PostgreSQL 8.1 Benchmark

 本日、FreeBSD5.4にてCVSupを行って/usr/ports/databases/以下を見てみるとpostgresql81-serverが出来ていたので早速インストールしてみた。


tmkbsd# cd /usr/ports/databases/postgresql81-server
tmkbsd# make install clean

しかし、postgresql-clientが8.0だよ〜っと言われて止まってしまうので、アンインストールしてから再度やってみた。今度は問題なくインストールは完了。続けてinitdbを行ったがエラーで止まってしまう。/usr/local/pgsql/dataがディフォルトのデータディレクトリなのだが、ディレクトリが空じゃないと怒られました。PostgreSQL 8.0をインストールしていたからで、/usr/local/pgsql/dataをディレクトリごと消してもう一度。


tmkbsd# /usr/local/etc/rc.d/010.pgsql.sh initdb

creating template1 database in /usr/local/pgsql/data/base/1 ... FATAL: could not create semaphores: No space left on device
DETAIL: Failed system call was semget(1, 17, 03600).
HINT: This error does *not* mean that you have run out of disk space.
It occurs when either the system limit for the maximum number of semaphore sets (SEMMNI), or the system wide maximum number of semaphores (SEMMNS), would be exceeded. You need to raise the respective kernel parameter. Alternatively, reduce PostgreSQL's consumption of semaphores by reducing its max_connections parameter (currently 10).
The PostgreSQL documentation contains more information about configuring your system for PostgreSQL.
child process exited with exit code 1
initdb: removing contents of data directory "/usr/local/pgsql/data"

 kernelパラメータのSEMMNIとSEMMNSの値が低いようである。


tmkbsd# ipcs -S
seminfo:
semmap: 30 (# of entries in semaphore map)
semmni: 10 (# of semaphore identifiers)
semmns: 60 (# of semaphores in system)
semmnu: 30 (# of undo structures in system)
semmsl: 60 (max # of semaphores per id)
semopm: 100 (max # of operations per semop call)
semume: 10 (max # of undo entries per process)
semusz: 92 (size in bytes of undo structure)
semvmx: 32767 (semaphore maximum value)

同時接続180で多すぎだと思いながらも推奨値?の

To allow many simultaneous connections to your PostgreSQL server, you
should raise the SystemV shared memory limits in your kernel. Here are
example values for allowing up to 180 clients (configurations in
postgresql.conf also needed, of course):
options SYSVSHM
options SYSVSEM
options SYSVMSG
options SHMMAXPGS=65536
options SEMMNI=40
options SEMMNS=240
options SEMUME=40
options SEMMNU=120
に変更してみた。


/boot/loader.confに
kern.ipc.semmni=40
kern.ipc.semmns=240
kern.ipc.semume=40
kern.ipc.semmnu=120
と書いてリブート。


tmkbsd# ipcs -S
seminfo:
semmap: 30 (# of entries in semaphore map)
semmni: 40 (# of semaphore identifiers)
semmns: 240 (# of semaphores in system)
semmnu: 120 (# of undo structures in system)
semmsl: 60 (max # of semaphores per id)
semopm: 100 (max # of operations per semop call)
semume: 40 (max # of undo entries per process)
semusz: 92 (size in bytes of undo structure)
semvmx: 32767 (semaphore maximum value)
semaem: 16384 (adjust on exit max value)

そして再度 /usr/local/etc/rc.d/010.pgsql.sh initdbでOKでした。

ベンチマークPostgreSQLのcontribに入っているpgbenchを使う。いろいろ探してみたらPortspostgresql-contribを見つけインストール。


tmkbsd# su - pgsql
$ createdb test
CREATE DATABASE
$ pgbench -i test
creating tables...
10000 tuples done.
20000 tuples done.
30000 tuples done.
40000 tuples done.
50000 tuples done.
60000 tuples done.
70000 tuples done.
80000 tuples done.
90000 tuples done.
100000 tuples done.
set primary key...
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "branches_pkey" for table "branches"
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "tellers_pkey" for table "tellers"
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "accounts_pkey" for table "accounts"
vacuum...done.
$ pgbench -c 1 test
starting vacuum...end.
transaction type: TPC-B (sort of)
scaling factor: 1
number of clients: 1
number of transactions per client: 10
number of transactions actually processed: 10/10
tps = 104.458279 (including connections establishing)
tps = 115.436118 (excluding connections establishing)

以下はPostgreSQL 8.1をインストールする前にPostgreSQL 8.0で取った値との比較ですが、PostgreSQL8.0ではkernelパラメータを弄っていないので単純には比較できません。又、postgresql.confはlisten_address以外は変更していません。

Client数 PostgreSQL8.0 PostgreSQL8.1 単純性能比(%)
1 85.076 129.078 151.7
2 106.851 140.601 131.2
4 103.656 137.923 133.1
8 82.356 115.450 140.2
16 69.476 81.895 117.8
32 53.090 54.277 102.2


32接続くらいになると、性能アップはないようですが、それ以下ですと1.3倍〜1.5倍くらいのアップがあります。ChangeLogを読んでみるとSMPだともっと差がでるのかもしれません。SQL文を弄ったりインデックスを張ったりでチューニングするより事情が許すのであれば、さっさと8.1へ移行する方が良いということみたいです。



さて、FreeBSD 5.4とFreeBSD 6.0での対決はどうでしょうか?


http://pcweb.mycom.co.jp/articles/2005/11/07/freebsd/002.htmlにあるようにFreeBSD 6.0からはCVSupに代わりportsnapでPortsツリーを最新にした方が良いとのことなので早速


bsdtmk6# portsnap fetch
と、やってみたのですが、/usr/ports/databases/postgresql81-serverはないと怒られます。FTPftp.freebsd.orgのportsを覗いてみるとちゃんとあります。試しにCVSupを入れてPortsツリーを最新にするとやっと/usr/ports/databases/postgresql81-serverが出てきました。


 インストールして、initdbしてみるとkernelパラメータを弄らなくても出来てしまいました。ちゃんと比較するためにkernelパラメータを弄ってリブート。その後同じ手順でpgbenchで値をとってみました。

Client数 FreeBSD5.4 FreeBSD6.0 単純性能比(%)
1 129.078 66.959 51.9
2 140.601 75.084 53.4
4 137.923 72.021 52.2
8 115.450 64.642 56.0
16 81.895 51.334 62.7
32 54.277 37.290 68.7

あれ〜、FreeBSD 6.0の方が半分くらいの性能になっています。間違えたのかと何度もやり直してみましたが性能比は変わりません。なんで〜。これくらいのデータ量ではディスクIOがほとんど発生していないためにファイルシステムの恩恵には与れていないのかもしれませんが、理由はよくわかりません。誰か教えてください。一応topコマンドで他のでかいプロセスが動いているのかと思ってみましたが、そうではありませんでした。

環境:
同じWindows XP SP2のVMware 5.0上でそれぞれDisk Space 6.0GB、MEM 256MBを使った仮想マシンFreeBSD 5.4とFreeBSD 6.0をインストール。


 当面はFreeBSD 5.4でPostgreSQL 8.1を使うことにします。