Más contenido relacionado
La actualidad más candente (20)
Similar a PostgreSQL Query Cache - "pqc" (20)
PostgreSQL Query Cache - "pqc"
- 1. PostgreSQL Query Cache
“pqc”
2011/2/25
アップタイム・テクノロジーズ
Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
- 2. pqc概要
• PostgreSQLへの問い合わせをキャッシングすることで、SQL問い合わ
せのパフォーマンスを「劇的に(10~100倍)」改善する。
– PostgreSQLへの問い合わせを中継する。
– 異なるポート上で接続を待ち受けている(デフォルトでは9999)
– SELECTクエリの結果をキャッシュする(クエリキャッシュ)。
– キャッシュのライフサイクル管理を行う。
PostgreSQL
クライアント
PostgreSQLサーバ
pqcd
Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
PostgreSQL
バックエンド
キャッシュメモリ
- 3. 外部仕様
• シンプルクエリ実行とPreparedStatementをサポートする
– プロトコルはバージョン3のみサポート
• アクティブキャッシュモード
– 基本的にすべてのSELECTクエリの結果をキャッシュする。
– 指定した特定のSELECTクエリの結果はキャッシュしない。
• パッシブキャッシュモード
– 基本的にクエリの結果をキャッシュしない。
– 指定した特定のSELECTクエリの結果のみをキャッシュする。
– 指定した実行時間を越えたクエリの結果をキャッシュする(未実装)
• キャッシュインバリデーション(無効化)
– キャッシュ有効期限の指定によるクエリキャッシュ無効化
– 特定のクエリを指定することによるクエリキャッシュ無効化
– すべてのクエリキャッシュの無効化(未実装)
Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
- 4. 導入手順
Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
• 必要なライブラリ
– libevent 1.4.14b (memcachedが使用)
– memcached 1.4.5
– libmemcached 0.43
• インストール
– automake
– ./configure --prefix=$PREFIX
– make
– sudo make install
– cd $PREFIX/etc
– cp pqcd_hba.conf.sample pqcd_hba.conf
• 起動
– $PREFIX/bin/pqcd (daemon mode)
– $PREFIX/bin/pqcd –n –d (debug mode)
• 終了
– $PREFIX/bin/pqcd stop (daemon mode)
– <CTRL+C> (debug mode)
- 5. 導入手順(RPMから)
Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
• 必要なRPM
– uqc-libevent-1.4.14b-1.i386.rpm
– uqc-memcached-1.4.5-1.i386.rpm
– uqc-libmemcached-0.43-1.i386.rpm
– uqc-querycache-20110223-1.i386.rpm
• 設定ファイル
– /opt/uptime/querycache/etc/pqcd.conf
– /opt/uptime/querycache/etc/pqcd_hba.conf
• 起動
– /opt/uptime/querycache/bin/pqcd
• 終了
– /opt/uptime/querycache/bin/pqcd stop
- 6. 設定オプション
• 必要に応じてpqcd.conf の設定を行います($PREFIX/etc にあります)
Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
• memcached_bin
– Memcachedの実行ファイルのパス名(デフォルトは
“/opt/uptime/querycache/bin/memcached” )
• query_cache_mode
– クエリキャッシュモード。“active” または“passive” を指定(デフォルトは“active” )
• query_cache_expiration
– キャッシュの有効期限を秒数で指定(デフォルトは30)
- 7. キャッシュ制御ヒント文
• SELECT文の先頭にコメントとして付加する。
– /* cache:refresh */SELECT * FROM …
– <slash> <asterrisk> <space> <hint> <space> <asterisk> <slash>
• cache:on (アクティブモードのデフォルト)
– キャッシュを参照する。無ければクエリを実行してキャッシュに乗せる。
• cache:off (パッシブモードのデフォルト)
– キャッシュを参照しない。かつ、キャッシュに乗せない。
Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
• cache:refresh
– キャッシュを参照しない。クエリを実行してキャッシュに乗せる。
• cache:expire
– キャッシュを無効化する。クエリは実行しない。(未実装)
• cache:expireall
– すべてのクエリのキャッシュを無効化する。クエリは実行しない。(未実装)
- 13. 【お問い合わせ先】
アップタイム・テクノロジーズ合同会社
E-mail: contact@uptime.jp
Web: http://www.uptime.jp/
TEL: 050-3585-7837
FAX: 03-5770-7883
Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Notas del editor
- [snaga@devwa02 src]$ /opt/pgsql/901/bin/psql -p 9999 -h localhost -U uptime testdb psql (9.0.1, server 8.3.6) WARNING: psql version 9.0, server version 8.3. Some psql features might not work. Type &quot;help&quot; for help. testdb=# \\timing Timing is on. testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 617.948 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 3.236 ms testdb=# /* cache:off */SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 455.847 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 2.916 ms testdb=# DELETE FROM pgbench_accounts; DELETE 1000000 Time: 11798.786 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 2.485 ms testdb=# /* cache:off */SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 2039.547 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 1.870 ms testdb=# /* cache:refresh */SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 128.099 ms testdb=# SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 2.491 ms testdb=#
- [snaga@devwa02 src]$ /opt/pgsql/901/bin/psql -p 9999 -h localhost -U uptime testdb psql (9.0.1, server 8.3.6) WARNING: psql version 9.0, server version 8.3. Some psql features might not work. Type &quot;help&quot; for help. testdb=# \\timing Timing is on. testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 617.948 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 3.236 ms testdb=# /* cache:off */SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 455.847 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 2.916 ms testdb=# DELETE FROM pgbench_accounts; DELETE 1000000 Time: 11798.786 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 2.485 ms testdb=# /* cache:off */SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 2039.547 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 1.870 ms testdb=# /* cache:refresh */SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 128.099 ms testdb=# SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 2.491 ms testdb=#
- [snaga@devwa02 src]$ /opt/pgsql/901/bin/psql -p 9999 -h localhost -U uptime testdb psql (9.0.1, server 8.3.6) WARNING: psql version 9.0, server version 8.3. Some psql features might not work. Type &quot;help&quot; for help. testdb=# \\timing Timing is on. testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 617.948 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 3.236 ms testdb=# /* cache:off */SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 455.847 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 2.916 ms testdb=# DELETE FROM pgbench_accounts; DELETE 1000000 Time: 11798.786 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 2.485 ms testdb=# /* cache:off */SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 2039.547 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 1.870 ms testdb=# /* cache:refresh */SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 128.099 ms testdb=# SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 2.491 ms testdb=#
- [snaga@devwa02 src]$ /opt/pgsql/901/bin/psql -p 9999 -h localhost -U uptime testdb psql (9.0.1, server 8.3.6) WARNING: psql version 9.0, server version 8.3. Some psql features might not work. Type &quot;help&quot; for help. testdb=# \\timing Timing is on. testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 617.948 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 3.236 ms testdb=# /* cache:off */SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 455.847 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 2.916 ms testdb=# DELETE FROM pgbench_accounts; DELETE 1000000 Time: 11798.786 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 2.485 ms testdb=# /* cache:off */SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 2039.547 ms testdb=# SELECT count(*) FROM pgbench_accounts; count --------- 1000000 (1 row) Time: 1.870 ms testdb=# /* cache:refresh */SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 128.099 ms testdb=# SELECT count(*) FROM pgbench_accounts; count ------- 0 (1 row) Time: 2.491 ms testdb=#