本帖最后由 sunyunyi 于 2019-12-26 10:28 编辑
PostgreSQL 11 集群和单实例环境压测对比
作者简介:
----------------------------------------------------------------------
@ 孙显鹏,海天起点oracle技术专家,十年从业经验
@ 精通oracle内部原理,擅长调优和解决疑难问题
@ 致力于帮助客户解决生产中的问题,提高生产效率。
@ 爱好:书法,周易,中医。微信:sunyunyi_sun
@ 易曰:精义入神,以致用也!
@ 调优乃燮理阴阳何其难也!
----------------------------------------------------------------------
PG 集群架构说明:
55: coordinator
55,56: worker-node
pg 版本 pg11,集群版本5.7
测试前调整参数:
调整内存和连接参数后压力测试,启动coordinator 和 worker-node:
sudo -u postgres /usr/pgsql-11/bin/pg_ctl -D /pgdata/citus/coordinator -o "-p 9700" -l coordinator_logfile start
sudo -u postgres /usr/pgsql-11/bin/pg_ctl -D /pgdata/pg11 -l logfile stop
测试目的:
比较单机和集群环境下pg性能。
测试工具:
pgbench
测试步骤:
--初始化25000000数据
sudo -u postgres /usr/pgsql-11/bin/pgbench -p 9700 -i -F 100 -s 500
......
24900000 of 25000000 tuples (99%) done (elapsed 111.63 s, remaining 0.45 s)
25000000 of 25000000 tuples (100%) done (elapsed 111.89 s, remaining 0.00 s)
vacuuming...
creating primary keys...
done.
--单机压力测试:
thread:50 ,client:100 time:10min ,mode:select only
[root@piamarydb bench_data]# sudo -u postgres /usr/pgsql-11/bin/pgbench -p 9700 -v -j 50 -c 100 -T 600 -S
starting vacuum...end.
starting vacuum pgbench_accounts...end.
transaction type: <builtin: select only>
scaling factor: 250
query mode: simple
number of clients: 100
number of threads: 50
duration: 600 s
number of transactions actually processed: 1046992
latency average = 57.375 ms
tps = 1742.928192 (including connections establishing)
tps = 1743.442057 (excluding connections establishing)
10时26分19秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
10时26分30秒 0 403 99.75 87.19 48.86
10时26分31秒 0 403 99.75 87.19 48.86
10时26分32秒 1 403 99.75 87.19 48.86
10时26分33秒 3 403 99.75 87.19 48.86
10时26分34秒 0 403 99.69 87.38 49.13
10时26分35秒 0 403 99.69 87.38 49.13
10时26分36秒 2 403 99.69 87.38 49.13
10时26分37秒 0 373 99.69 87.38 49.13
10时26分38秒 1 252 99.69 87.38 49.13
10时26分39秒 0 252 91.71 85.93 48.86
10时26分40秒 0 252 91.71 85.93 48.86
10时26分41秒 1 252 91.71 85.93 48.86
10时26分42秒 0 252 91.71 85.93 48.86
10时26分43秒 0 252 91.71 85.93 48.86
10时26分44秒 0 252 84.36 84.51 48.60
10时26分45秒 0 252 84.36 84.51 48.60
10时26分46秒 1 252 84.36 84.51 48.60
10时26分47秒 0 252 84.36 84.51 48.60
10时26分48秒 0 252 84.36 84.51 48.60
10时26分49秒 0 252 77.61 83.10 48.34
10时26分50秒 0 252 77.61 83.10 48.34
10时26分51秒 0 252 77.61 83.10 48.3
[root@piamarydb bench_data]# sudo -u postgres /usr/pgsql-11/bin/pgbench -p 9700 -v -j 50 -c 100 -T 600
starting vacuum...end.
starting vacuum pgbench_accounts...end.
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 250
query mode: simple
number of clients: 100
number of threads: 50
duration: 600 s
number of transactions actually processed: 60365
latency average = 994.775 ms
tps = 100.525257 (including connections establishing)
tps = 100.550011 (excluding connections establishing)
10时37分12秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
10时37分13秒 0 403 16.19 21.30 30.39
10时37分14秒 0 403 16.19 21.30 30.39
10时37分15秒 0 403 15.21 21.02 30.25
10时37分16秒 0 403 15.21 21.02 30.25
10时37分17秒 15 404 15.21 21.02 30.25
10时37分18秒 0 404 15.21 21.02 30.25
10时37分19秒 1 404 15.21 21.02 30.25
10时37分20秒 0 403 21.12 22.14 30.56
10时37分21秒 1 403 21.12 22.14 30.56
10时37分22秒 1 403 21.12 22.14 30.56
10时37分23秒 1 403 21.12 22.14 30.56
10时37分24秒 0 403 21.12 22.14 30.56
10时37分25秒 1 403 20.39 21.97 30.46
10时37分26秒 1 403 20.39 21.97 30.46
10时37分27秒 10 403 20.39 21.97 30.46
10时37分28秒 0 403 20.39 21.97 30.46
10时37分29秒 0 403 20.39 21.97 30.46
10时37分30秒 1 403 20.44 21.96 30.41
10时37分31秒 1 403 20.44 21.96 30.4
shared 表:
sudo -u postgres psql -p 9700
postgres=# select count(*) from pgbench_accounts ;
count
----------
25000000
(1 行记录)
postgres=# SELECT pg_size_pretty(pg_relation_size('pgbench_accounts'));
3212 MB
(1 行记录)
select create_distributed_table('pgbench_accounts','aid');
select create_distributed_table('pgbench_branches','bid');
select create_distributed_table('pgbench_tellers','tid');
select create_distributed_table('pgbench_history','aid');
postgres=# SELECT
postgres-# shardid,
postgres-# node.nodename,
postgres-# node.nodeport
postgres-# FROM pg_dist_placement placement
postgres-# JOIN pg_dist_node node
postgres-# ON placement.groupid = node.groupid
postgres-# ;
shardid | nodename | nodeport
---------+---------------+----------
102330 | 192.168.56.55 | 5432
102331 | 192.168.56.66 | 5432
102332 | 192.168.56.55 | 5432
102333 | 192.168.56.66 | 5432
102334 | 192.168.56.55 | 5432
102335 | 192.168.56.66 | 5432
102336 | 192.168.56.55 | 5432
102337 | 192.168.56.66 | 5432
102338 | 192.168.56.55 | 5432
102339 | 192.168.56.66 | 5432
......
(128 行记录) == 4*32
集群压力测试:
sudo -u postgres /usr/pgsql-11/bin/pgbench -p 9700 -v -j 50 -c 100 -T 600 -S
[root@piamarydb pgdata]# sudo -u postgres /usr/pgsql-11/bin/pgbench -p 9700 -v -j 50 -c 100 -T 600 -S
starting vacuum...end.
starting vacuum pgbench_accounts...end.
transaction type: <builtin: select only>
scaling factor: 250
query mode: simple
number of clients: 100
number of threads: 50
duration: 600 s
number of transactions actually processed: 306072
latency average = 196.284 ms
tps = 509.464795 (including connections establishing)
tps = 509.625903 (excluding connections establishing)
55:
05时48分05秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
05时48分06秒 2 530 45.29 33.41 17.80
05时48分07秒 0 530 43.59 33.25 17.83
05时48分08秒 3 530 43.59 33.25 17.83
05时48分09秒 0 530 43.59 33.25 17.83
05时48分10秒 2 530 43.59 33.25 17.83
05时48分11秒 0 530 43.59 33.25 17.83
05时48分12秒 4 530 41.22 32.93 17.81
05时48分13秒 1 530 41.22 32.93 17.81
05时48分14秒 0 530 41.22 32.93 17.81
05时48分15秒 2 530 41.22 32.93 17.81
05时48分16秒 3 530 41.22 32.93 17.81
05时48分17秒 1 530 41.60 33.15 17.96
05时48分18秒 1 530 41.60 33.15 17.96
05时48分19秒 3 530 41.60 33.15 17.96
05时48分20秒 0 530 41.60 33.15 17.96
66:
12:32:27 PM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
12:32:28 PM 0 332 61.58 57.35 33.24
12:32:29 PM 1 332 61.58 57.35 33.24
12:32:30 PM 0 332 61.58 57.35 33.24
12:32:31 PM 0 332 61.58 57.35 33.24
12:32:32 PM 1 332 61.58 57.35 33.24
12:32:33 PM 1 332 60.57 57.21 33.32
12:32:34 PM 1 332 60.57 57.21 33.32
12:32:35 PM 1 332 60.57 57.21 33.32
12:32:36 PM 0 332 60.57 57.21 33.32
12:32:37 PM 0 332 60.57 57.21 33.32
12:32:38 PM 0 332 62.45 57.66 33.59
12:32:39 PM 3 332 62.45 57.66 33.59
12:32:40 PM 0 332 62.45 57.66 33.59
12:32:41 PM 1 332 62.45 57.66 33.59
starting vacuum pgbench_accounts... --时间较长
较单子压力测试tps少了2倍多,延迟增加了3倍多?
因为测试环境cpu就一个,一个shard对应一个connection对应一个cpu,
这样在集群模式下反而增加了CPU排队竞争,
加上网络原因和磁盘原因,集群环境下测试的效果反而没有单机效果好。
在较好的硬件平台做压力测试集群的效果将会是单机的2到3倍。
官方给出的结论:
we recommend choosing a cluster where the number of worker cores and RAM in total equals
that of the original instance. In such scenarios we have seen 2-3x performance improvements
because sharding improves resource utilization, allowing smaller indices etc.
下次有环境我们再作进一步测试。
读写测试:
[root@piamarydb pgdata]# sudo -u postgres /usr/pgsql-11/bin/pgbench -p 9700 -v -j 50 -c 100 -T 600
starting vacuum...end.
starting vacuum pgbench_accounts...end.
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 250
query mode: simple
number of clients: 100
number of threads: 50
duration: 600 s
number of transactions actually processed: 60509
latency average = 993.274 ms
tps = 100.677170 (including connections establishing)
tps = 100.722982 (excluding connections establishing)
sudo -u postgres psql -p 9700;
drop table pgbench_accounts;
drop table pgbench_branches;
drop table pgbench_tellers;
drop table pgbench_history;
压力测试场景较多,上面只是简单的测试场景,并没有阶梯增加并发做多次测试,有关更多的压力测试参数,参考帮助文档:
pgbench help:
sudo -u postgres /usr/pgsql-11/bin/pgbench --help
孙显鹏
|