本ページでは、pgbench を使って PolarDB PostgreSQL クラスターのプライマリノードのピークパフォーマンスをテストする方法について説明します。
pgbench とは、PostgreSQL の軽量ストレステストツールです。pgbench は PostgreSQL でベンチマークテストを実行するためのシンプルなプログラムです。 複数の並行データベースセッションにて、SQL 文の同じシーケンスを繰り返し実行します。
テスト環境
- すべてのテストは IP アドレスとポートを使ってローカルで完了する必要があります。
- ECS インスタンスタイプ:ecs.g5.16xlarge (64 コア、256 GiB)
- ネットワークタイプ:VPC
- オペレーティングシステム:64 ビット CentOS 7.6
注 CentOS 6 は PostgreSQL 11 をサポートしていません。
テスト指標
- 1 秒あたりの読み取り専用クエリ (QPS)
読み取り専用操作がデータベース上で実行されたときの、1 秒あたりの SELECT 文の実行数
- 読み取り/書き込み QPS
読み取り/書き込み操作がデータベース上で実行されたときの、1 秒あたりのINSERT、SELECT、UPDATE 文の実行数
前提条件
- PostgreSQL 11 をインストール
次のコマンドを実行して、PostgreSQL 11を ECS インスタンスにインストールします。
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm yum install -y postgresql11* su - postgres vi .bash_profile export PS1="$USER@`/bin/hostname -s`-> " export LANG=en_US.utf8 export PGHOME=/usr/pgsql-11 export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH export DATE=`date +"%Y%m%d%H%M"` export PATH=$PGHOME/bin:$PATH:. export MANPATH=$PGHOME/share/man:$MANPATH alias rm='rm -i' alias ll='ls -lh' unalias vi
- PolarDB PostgreSQL クラスターのパラメーターを変更
一部のパラメーターはコンソールでは変更できないため、チケットを送信して、クラスターの YAML 設定ファイルを変更する必要があります。 設定項目は次のとおりです。
default_statistics_target: "100" max_wal_size: "64GB" #half mem size effective_cache_size: "96GB" #3/4 mem size max_parallel_workers_per_gather: "16" #half cpu core number maintenance_work_mem: "2GB" #1/32 mem, don't exceed 8GB checkpoint_completion_target: "0.9" max_parallel_workers: "32" #cpu core number,don't exceed 64 max_prepared_transactions: "2100" archive_mode: "off" work_mem: "64MB" #mem 1/2000,don't exceed 128MB wal_buffers: "16MB" min_wal_size: "64GB" #1/4 mem size, min size 3GB (3 wal files, 2 as preallocated) shared_buffers: "192GB" #75% mem size 8GB max_connections: "12900" polar_bulk_extend_size: "4MB" polar_xlog_record_buffers: "25GB" #10~15% mem size,min size 1GB hot_standby_feedback: "on" full_page_writes: "off" synchronous_commit: "on" polar_enable_async_pwrite: "off" polar_parallel_bgwriter_delay: "10ms" polar_max_non_super_conns: '12800' polar_parallel_new_bgwriter_threshold_lag: "6GB" polar_use_statistical_relpages: "on" polar_vfs.enable_file_size_cache: "on"
注 前述のコードスニペットは、32 コア 256 GB polar.pg.x8.4xlarge クラスターの設定ファイルの変更を行う例として使用されています。 PolarDB PostgreSQL クラスターとApsaraDB RDS for PostgreSQL クラスターのメモリサイズを同じに設定し、パフォーマンスを比較します。設定を変更した後、PolarDB PostgreSQL クラスターを再起動して、設定を有効にします。
テスト手順
- 次のコマンドを実行して、ターゲットデータベースのサイズに基づいてテストデータを初期化します。
- 50 億件のデータレコードの初期化:
pgbench -i -s 50000
- 10 億件のデータレコードの初期化:
pgbench -i -s 10000
- 5 億件のデータレコードの初期化:
pgbench -i -s 5000
- 1 億件のデータレコードの初期化:
pgbench -i -s 1000
- 50 億件のデータレコードの初期化:
- 次のコマンドを実行して、環境変数を設定します。
export PGHOST=<Private endpoint of the primary node of the PolarDB PostgreSQL cluster> export PGPORT=<Private port of the primary node of the PolarDB PostgreSQL cluster> export PGDATABASE=postgres export PGUSER=<Username to log on to the PolarDB PostgreSQL database> export PGPASSWORD=<User password to log on to the PolarDB PostgreSQL database>
- テストスクリプトを作成し、読み取り専用操作と読み取り/書き込み操作を実行します。
- 次のコードを含むスクリプト ro.sql を作成し、読み取り専用操作を実行します。
\set aid random_gaussian(1, :range, 10.0) SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
- 次のコードを含むスクリプト rw.sql を作成し、読み取り/書き込み操作を実行します。
\set aid random_gaussian(1, :range, 10.0) \set bid random(1, 1 * :scale) \set tid random(1, 10 * :scale) \set delta random(-5000, 5000) BEGIN; UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid; SELECT abalance FROM pgbench_accounts WHERE aid = :aid; UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid; UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid; INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP); END;
- 次のコードを含むスクリプト ro.sql を作成し、読み取り専用操作を実行します。
- 次のコマンドを実行してテストを行います。
- 読み取り専用操作を実行します。
polar.o.x8.4xlarge, the total number of data records is 1 billion, the number of hot data records is 100 million. pgbench -M prepared -v -r -P 1 -f ./ro.sql -c 128 -j 128 -T 120 -D scale=10000 -D range=100000000 polar.o.x8.4xlarge, the total number of data records is 1 billion, the number of hot data records is 500 million. pgbench -M prepared -n -r -P 1 -f ./ro.sql -c 128 -j 128 -T 120 -D scale=10000 -D range=500000000 polar.o.x8.4xlarge, the total number of data records is 1 billion, the number of hot data records is 1 billion. pgbench -M prepared -n -r -P 1 -f ./ro.sql -c 128 -j 128 -T 120 -D scale=10000 -D range=1000000000 polar.o.x8.2xlarge, the total number of data records is 1 billion, the number of hot data records is 100 million. pgbench -M prepared -v -r -P 1 -f ./ro.sql -c 64 -j 64 -T 120 -D scale=10000 -D range=100000000 polar.o.x8.2xlarge, the total number of data records is 1 billion, the number of hot data records is 500 million. pgbench -M prepared -n -r -P 1 -f ./ro.sql -c 64 -j 64 -T 120 -D scale=10000 -D range=500000000 polar.o.x8.2xlarge, the total number of data records is 1 billion, the number of hot data records is 1 billion. pgbench -M prepared -n -r -P 1 -f ./ro.sql -c 64 -j 64 -T 120 -D scale=10000 -D range=1000000000 polar.o.x4.xlarge, the total number of data records is 1 billion, the number of hot data records is 100 million. pgbench -M prepared -v -r -P 1 -f ./ro.sql -c 32 -j 32 -T 120 -D scale=10000 -D range=100000000 polar.o.x4.xlarge, the total number of data records is 1 billion, the number of hot data records is 500 million. pgbench -M prepared -n -r -P 1 -f ./ro.sql -c 32 -j 32 -T 120 -D scale=10000 -D range=500000000 polar.o.x4.xlarge, the total number of data records is 1 billion, the number of hot data records is 1 billion. pgbench -M prepared -n -r -P 1 -f ./ro.sql -c 32 -j 32 -T 120 -D scale=10000 -D range=1000000000 polar.o.x4.large, the total number of data records is 500 million, the number of hot data records is 100 million. pgbench -M prepared -v -r -P 1 -f ./ro.sql -c 16 -j 16 -T 120 -D scale=5000 -D range=100000000 polar.o.x4.large, the total number of data records is 500 million, the number of hot data records is 500 million. pgbench -M prepared -n -r -P 1 -f ./ro.sql -c 16 -j 16 -T 120 -D scale=5000 -D range=500000000 polar.o.x4.medium, the total number of data records is 100 million, the number of hot data records is 50 million. pgbench -M prepared -v -r -P 1 -f ./ro.sql -c 8 -j 8 -T 120 -D scale=1000 -D range=50000000 polar.o.x4.medium, the total number of data records is 100 million, the number of hot data records is 100 million. pgbench -M prepared -n -r -P 1 -f ./ro.sql -c 8 -j 8 -T 120 -D scale=1000 -D range=100000000
- 読み取り、書き込み操作を実行します。
polar.o.x8.4xlarge, the total number of data records is 1 billion, the number of hot data records is 100 million. pgbench -M prepared -v -r -P 1 -f ./rw.sql -c 128 -j 128 -T 120 -D scale=10000 -D range=100000000 polar.o.x8.4xlarge, the total number of data records is 1 billion, the number of hot data records is 500 million. pgbench -M prepared -n -r -P 1 -f ./rw.sql -c 128 -j 128 -T 120 -D scale=10000 -D range=500000000 polar.o.x8.4xlarge, the total number of data records is 1 billion, the number of hot data records is 1 billion. pgbench -M prepared -n -r -P 1 -f ./rw.sql -c 128 -j 128 -T 120 -D scale=10000 -D range=1000000000 polar.o.x8.2xlarge, the total number of data records is 1 billion, the number of hot data records is 100 million. pgbench -M prepared -v -r -P 1 -f ./rw.sql -c 64 -j 64 -T 120 -D scale=10000 -D range=100000000 polar.o.x8.2xlarge, the total number of data records is 1 billion, the number of hot data records is 500 million. pgbench -M prepared -n -r -P 1 -f ./rw.sql -c 64 -j 64 -T 120 -D scale=10000 -D range=500000000 polar.o.x8.2xlarge, the total number of data records is 1 billion, the number of hot data records is 1 billion. pgbench -M prepared -n -r -P 1 -f ./rw.sql -c 64 -j 64 -T 120 -D scale=10000 -D range=1000000000 polar.o.x4.xlarge, the total number of data records is 1 billion, the number of hot data records is 100 million. pgbench -M prepared -v -r -P 1 -f ./rw.sql -c 32 -j 32 -T 120 -D scale=10000 -D range=100000000 polar.o.x4.xlarge, the total number of data records is 1 billion, the number of hot data records is 500 million. pgbench -M prepared -n -r -P 1 -f ./rw.sql -c 32 -j 32 -T 120 -D scale=10000 -D range=500000000 polar.o.x4.xlarge, the total number of data records is 1 billion, the number of hot data records is 1 billion. pgbench -M prepared -n -r -P 1 -f ./rw.sql -c 32 -j 32 -T 120 -D scale=10000 -D range=1000000000 polar.o.x4.large, the total number of data records is 500 million, the number of hot data records is 100 million. pgbench -M prepared -v -r -P 1 -f ./rw.sql -c 16 -j 16 -T 120 -D scale=5000 -D range=100000000 polar.o.x4.large, the total number of data records is 500 million, the number of hot data records is 500 million. pgbench -M prepared -n -r -P 1 -f ./rw.sql -c 16 -j 16 -T 120 -D scale=5000 -D range=500000000 polar.o.x4.medium, the total number of data records is 100 million, the number of hot data records is 50 million. pgbench -M prepared -v -r -P 1 -f ./rw.sql -c 8 -j 8 -T 120 -D scale=1000 -D range=50000000 polar.o.x4.medium, the total number of data records is 100 million, the number of hot data records is 100 million. pgbench -M prepared -n -r -P 1 -f ./rw.sql -c 8 -j 8 -T 120 -D scale=1000 -D range=100000000
注- scale に 100,000 をかけた値は、テストデータレコードの数です。
- Range は、ホットデータレコードの数です。
- -c は、テストの接続数です。 この数は、このタイプのクラスターがサポートする最大接続数ではありません。 詳細については、「仕様と料金」をご参照ください。
- 読み取り専用操作を実行します。
それぞれのタイプのテスト結果
タイプ | テストデータレコード数 | ホット (アクティブ) データレコード数 | 読み取り専用 QPS | 読み取り/書き込み QPS |
---|---|---|---|---|
polar.pg.x8.4xlarge 32 コア、256 GB |
10 億 | 1 億 | 522160 | 294915 |
polar.pg.x8.4xlarge 32 コア、256 GB |
10 億 | 5 億 | 514143 | 282645 |
polar.pg.x8.4xlarge 32 コア、256 GB |
10 億 | 10 億 | 493321 | 268473 |
polar.pg.x8.2xlarge 16 コア、128 GB |
10 億 | 1 億 | 256998 | 156330 |
polar.pg.x8.2xlarge 16 コア、128 GB |
10 億 | 5 億 | 253937 | 133125 |
polar.pg.x8.2xlarge 16 コア、128 GB |
10 億 | 10 億 | 243326 | 115915 |
polar.pg.x8.xlarge 8 コア、64 GB |
10 億 | 1 億 | 159323 | 71820 |
polar.pg.x8.xlarge 8 コア、64 GB |
10 億 | 5 億 | 155498 | 58140 |
polar.pg.x8.xlarge 8 コア、64 GB |
10 億 | 10 億 | 152735 | 58555 |
polar.pg.x4.xlarge 8 コア、32 GB |
10 億 | 1 億 | 129323 | 64235 |
polar.pg.x4.xlarge 8 コア、32 GB |
10 億 | 5 億 | 115498 | 53682 |
polar.pg.x4.xlarge 8 コア、32 GB |
10 億 | 10 億 | 102735 | 51555 |
polar.pg.x4.large 4 コア、16 GB |
5 億 | 1 億 | 75729 | 48648 |
polar.pg.x4.large 4 コア、16 GB |
5 億 | 5 億 | 63818 | 43343 |
polar.pg.x4.medium 2 コア、 8 GB |
1 億 | 5000 万 | 34386 | 21383 |
pg.x8.medium.2 2 コア、16 GB、250 GB |
1 億 | 1 億 | 33752 | 15974 |
ApsaraDB RDS for PostgreSQL との比較
- テストでは非標準の PolarDB PostgreSQL 仕様を使用します。 両方のクラスターの比較を簡素化するため、PolarDB PostgreSQL クラスターのメモリは専用のApsaraDB RDS for PostgreSQL クラスターのものと同じになっています。
- 次の表では、ApsaraDB RDS for PostgreSQL のインスタンスタイプを示しています。
タイプ |
デフォルトのストレージスペースに保存できるデータレコードの推定数 (動的なサイズ変更) |
テストデータレコード数 | ホット (アクティブ) データレコード数 | 読み取り専用 QPS | 読み取り/書き込み QPS |
---|---|---|---|---|---|
pg.x4.4xlarge.2 32 コア、128 GB、2 TB |
100 億 | 10 億 | 1 億 | 462190 | 254915 |
pg.x4.4xlarge.2 32 コア、128 GB、2 TB |
100 億 | 10 億 | 5 億 | 463176 | 228440 |
pg.x4.4xlarge.2 32 コア、128 GB、2 TB |
100 億 | 10 億 | 10 億 | 473321 | 200250 |
pg.x8.2xlarge.2 16 コア、128 GB、2 TB |
100 億 | 10 億 | 1 億 | 256998 | 156330 |
pg.x8.2xlarge.2 16 コア、128 GB、2 TB |
100 億 | 10 億 | 5 億 | 253937 | 133125 |
pg.x8.2xlarge.2 16 コア、128 GB、2 TB |
100 億 | 10 億 | 10 億 | 243326 | 115915 |
pg.x8.xlarge.2 8 コア、64 GB、1 TB |
50 億 | 10 億 | 1 億 | 155014 | 71820 |
pg.x8.xlarge.2 8 コア、64 GB、1 TB |
50 億 | 10 億 | 5 億 | 159878 | 58140 |
pg.x8.xlarge.2 8 コア、64 GB、1 TB |
50 億 | 10 億 | 10 億 | 152917 | 58555 |
pg.x8.large.2 4 コア、32 GB、500 GB |
25 億 | 5 億 | 1 億 | 79429 | 45110 |
pg.x8.large.2 4 コア、32 GB、500 GB |
25 億 | 5 億 | 5 億 | 76268 | 36375 |
pg.x8.medium.2 2 コア、16 GB、250 GB |
12.5 億 | 1 億 | 5000 万 | 49733 | 24520 |
pg.x8.medium.2 2 コア、16 GB、250 GB |
12.5 億 | 1 億 | 1 億 | 44093 | 19880 |
- タイプは、PolarDB PostgreSQL インスタンスのタイプです。 チケットを送信し、PolarDB PostgreSQL インスタンスのメモリサイズを ApsaraDB RDS for PostgreSQL インスタンスのものへ変更します。
- デフォルトストレージスペースに保存できるデータレコードの推定数は、インスタンスタイプのデフォルトストレージスペースに保存できるデータレコードの数です。
- テストデータレコード数は、テストに使用されたデータレコードの数です。
- ホット (アクティブ) データレコード数は、テスト中、SQL 文で照会され、更新されたデータレコードの数です。
- 読み取り専用 QPS は、1 秒あたりのリクエスト数を示す読み取り専用テストの結果です。
- 読み取り/書き込み QPS は、1 秒あたりのリクエスト数を示す読み取り/書き込みテストの結果です。