[pgsql-jp: 32423] Postgresのリアルタイムデータ更新について

秋谷直弘 akiya @ hirise.co.jp
2004年 3月 6日 (土) 11:08:55 JST


現在Javaにて、
1秒に数十件のデータを取得し、
リアルタイムにpostgresqlに書込む処理を行っております。
(Windowsで取得し、Linuxに書込み)
ところが、同時接続数が多くなるのでDBサーバ(Linux)でSQLのプロセスが溜まってし
まい、
挙句の果てにはリアルタイムに更新を行ってくれません。
(postgresql.confのmax_connectionsは勿論増やしてあります)

環境は以下の通りです。
Windows XP Pro
 JDK  :JDK1.3.1_05		※1
 JDBC :rh-postgresql3.jar 	※2

RedHat Enterprise Linux AS v.3
 JDK  :IBMJava2-SDK-1.4.1-9	※3
 JRE  :IBMJava2-JRE-1.4.1-8	※3
 PostgreSQL :rh-postgresql-7.3.4-9※2

※1:使用するAPIの都合上、このバージョンしか使えません
※2:AS(Linux)で正式にサポートされているPostgresです
※3:AS(Linux)で正式にサポートされているJ2SDKです


どなたか1秒に数十件のデータをリアルタイムでDBに書き込みに行く
良い方法をご存知の方がいらっしゃいましたらご教授願います。

簡単ではありますが、
以下に処理の大まかな流れを記載しておきます。
↓↓↓↓↓
データ取得
↓
new Thread() {
	public void run() {
	※(1)DB接続
	※(2)DB更新
	}
}
↓
※(1)
//	JDBCドライバロード
	Class.forName(driver);
//	コネクション実行
	connection=DriverManager.getConnection(url,user,pass);
↓
※(2)
	SELECTで一旦既存データの有無を確認し、
	無ければ INSERT、あれば UPDATEを行い、
	毎回Connection、Statement、ResultSetを閉じています。
↑↑↑↑↑

また、PGM頭でConnectionはさせっぱなしにしておいて
データの取得に応じてStatementの実行も行ってみたのですが、
どうも上手くいきません。
コネクションプールも検討したのですが、そもそもSQLの実行プロセスが溜まってい
るので
プロセスしたコネクションを使用しても意味の無いような気がして試していませ
ん・・・
勘違いでしょうか?

一応以下にDBサーバ上での[ps aux | grep post]
の実行結果も記載しておきます。
[root @ localhost root]# ps aux | grep post
postgres  4211  0.0  0.3 25564 2036 ?        R    Feb29   1:22
/usr/bin/postmast
er -p 5432
postgres  4212  0.0  0.5 26556 2996 ?        S    Feb29   0:13 postgres:
stats b
uffer process
postgres  4213  0.0  0.4 25832 2200 ?        S    Feb29   0:09 postgres:
stats c
ollector process
root      2849  0.0  0.1  5072  948 pts/1    S    Mar03   0:00 su postgres
postgres  2850  0.0  0.2  5256 1252 pts/1    S    Mar03   0:00 bash
postgres  2864  0.0  0.3  7304 1720 pts/1    S    Mar03   0:00 psql rate-db
postgres  2865  0.0  2.2 26424 11488 ?       S    Mar03   0:21 postgres:
postgre
s rate-db [local] idle
root      7459  0.0  0.1  5092  976 pts/8    S    14:49   0:00 su postgres
postgres  7460  0.0  0.2  5256 1272 pts/8    S    14:49   0:00 bash
postgres  7467  0.0  0.3  7308 1808 pts/8    S    14:49   0:00 psql rate-db
postgres  7468  0.1  2.2 26424 11676 ?       S    14:49   0:40 postgres:
postgre
s rate-db [local] idle
root     26261  0.0  0.1  5080  976 pts/10   S    18:54   0:00 su postgres
postgres 26262  0.0  0.2  5264 1284 pts/10   S    18:54   0:00 bash
postgres 26340  0.0  0.3  7316 1840 pts/10   S    18:55   0:00 psql
j8-rate-db
postgres 26341  0.0  1.4 27076 7316 ?        S    18:55   0:00 postgres:
postgre
s j8-rate-db [local] idle
postgres 32384 16.3  2.2 26440 11440 ?       R    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 UPDATE
postgres 32385  9.0  1.7 26296 8832 ?        S    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 UPDATE waiting
postgres 32387 10.5  2.2 26304 11344 ?       R    20:26   0:00 postgres:
postgre
s rate-db 127.0.0.1 SELECT
postgres 32388 46.0  2.0 26300 10728 ?       S    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 UPDATE
postgres 32389 36.0  2.1 26300 11212 ?       S    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 UPDATE
postgres 32390 11.0  1.5 26296 7812 ?        R    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 SELECT
postgres 32393  0.0  1.4 26300 7440 ?        R    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 UPDATE
postgres 32394  0.0  1.1 26296 5756 ?        R    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 SELECT
postgres 32395  0.0  0.8 26296 4120 ?        S    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 SELECT
postgres 32396  0.0  0.8 26296 4196 ?        R    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 SELECT
postgres 32397  0.0  0.7 26296 3772 ?        S    20:26   0:00 postgres:
postgre
s rate-db 192.168.1.14 idle
root     32399  0.0  0.1  4684  688 pts/0    S    20:26   0:00 grep post

とまあ、こんな感じにプロセスが溜まっていきます。
上記例はまだまだ少ないほうです・・・

以上、宜しくお願いいたします。




pgsql-jp メーリングリストの案内