PostgreSQL のシーケンスのキャッシュサイズによる tps を比較してみた。pgbench で同時多重(500)でシーケンスにアクセスし、キャッシュサイズが 1 だと 9,601、20 だと 12,714 とキャッシュサイズが大きいほうがスループットは高い。とりあえず流してみた程度で厳密な検証ではない。
# | キャッシュサイズ | tps |
1 | 1 | 9,601 |
2 | 20 | 12,714 |
- RDS Performance Insights
- RDS CloudWatch メトリクス
- EC2 CloudWatch メトリクス(pgbench を実行)
計測手順
- キャッシュサイズ=1
$ pgbench -r -c 500 -j 500 -n -t 1000 -f pgsqlseq1_1.sql -U awsuser -h aurora-postgres124.cluster-cnaamhj3erpx.ap-northeast-1.rds.amazonaws.com -d postgres -p 5432 > pgsqlseq1_1.log 2>&1 (中略) transaction type: pgsqlseq1_1.sql scaling factor: 1 query mode: simple number of clients: 500 number of threads: 500 number of transactions per client: 1000 number of transactions actually processed: 500000/500000 latency average = 81.927 ms tps = 6103.021764 (including connections establishing) tps = 9601.273317 (excluding connections establishing) statement latencies in milliseconds: 23.610 select nextval('pgsqlseq1_1');
- キャッシュサイズ=20
$ pgbench -r -c 500 -j 500 -n -t 1000 -f pgsqlseq1_20.sql -U awsuser -h aurora-postgres124.cluster-cnaamhj3erpx.ap-northeast-1.rds.amazonaws.com -d postgres -p 5432 > pgsqlseq1_20.log 2>&1 (中略) transaction type: pgsqlseq1_20.sql scaling factor: 1 query mode: simple number of clients: 500 number of threads: 500 number of transactions per client: 1000 number of transactions actually processed: 500000/500000 latency average = 64.212 ms tps = 7786.661545 (including connections establishing) tps = 12714.076957 (excluding connections establishing) statement latencies in milliseconds: 15.243 select nextval('pgsqlseq1_20');
準備手順
- シーケンスを作成する
create sequence pgsqlseq1_1 start with 1 increment by 1 cache 1; create sequence pgsqlseq1_20 start with 1 increment by 1 cache 20;
# pgsqlseq1_1.sql select nextval('pgsqlseq1_1'); # pgsqlseq1_20.sql select nextval('pgsqlseq1_20');
環境
- PostgreSQL
- Aurora PostgreSQL 12.4
- r5.4xlarge
- EC2