背景介绍
PostgreSQL 在横向和纵向的扩展能力在开源数据库中一直处于非常领先的地位。针对OLTP类写操作占比很高的场景,想要探究下单pg在普通x86机器下对单个表的插入性能。
环境介绍
由于antdb v3.1版本用的pg内核版本为9.6,本次同样选取pg_9.6版本。
下载链接:https://github.com/postgres/postgres.git
x86配置:
CPU | Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz (22core) |
mem | 64GB |
磁盘 | STAT 4TB |
全部在本地测试,避免网络的影响,但是本地测试有一个问题就是测试客户端也会占用一定的资源,本次测试忽略此点。
安装与配置
os配置:
vi /etc/sysctl.conf
#add by zhugy3(信号量设置)
kernel.sem=501000 641280000 501000 12800
#最大单个共享内存段大小(建议为内存一半)
kernel.shmmax=67450355712
#减少time_wait
net.ipv4.tcp_timestamps = 1
#其余参数采用默认即可
vi /etc/security/limits.conf
zhugy soft nofile 1024000
zhugy hard nofile 1024000
zhugy soft nproc unlimited
zhugy hard nproc unlimited
zhugy soft core unlimited
zhugy hard core unlimited
zhugy soft memlock unlimited
zhugy hard memlock unlimited
数据库配置:
vim $PGDATA/postgresql.conf
listen_addresses = '*'
port = 6606
max_connections = 3000
shared_buffers = 5GB
max_prepared_transactions=1000
vim $PGDATA/pg_hba.conf
#host replication zhugy ::1/128 trust
host all all 0.0.0.0/0 trust
测试步骤
现在开源可用的pg基准测试工具有很多,如TPCC,sysbench及pg自带的pgbench等等。综合工具的功能,易用性,本次测试场景等方面,本次选定操作简单但功能较为强大的pgbench作为测试工具。
测试场景说明:
一张test表,22个字段,一条记录大概200字节。一条insert作为一个事务,autocommit,测试在不同并发下数据写入能力。
create table test(id serial8, c1 int8 default 0, c2 int8 default 0, c3 int8 default 0, c4 int8 default 0, c5 int8 default 0, c6 int8 default 0, c7 int8 default 0, c8 int8 default 0, c9 int8 default 0, c10 int8 default 0, c11 int8 default 0, c12 int8 default 0, c13 int8 default 0, c14 int8 default 0, c15 int8 default 0, c16 int8 default 0, c17 int8 default 0, c18 int8 default 0, c19 int8 default 0, c20 int8 default 0, crt_time timestamptz);
pgbench 测试脚本如下:
vi test.sql
insert into test(crt_time) values(now());
vi exec.sh
#!/bin/bash
pgbench -d postgres -U zhugy -p 6606 -M prepared -n -r -f ./test.sql -c 16 -j 16 -T 120 >>insert.log
sleep 10
pgbench -d postgres -U zhugy -p 6606 -M prepared -n -r -f ./test.sql -c 32 -j 32 -T 120 >>insert.log
sleep 10
pgbench -d postgres -U zhugy -p 6606 -M prepared -n -r -f ./test.sql -c 64 -j 64 -T 120 >>insert.log
sleep 10
pgbench -d postgres -U zhugy -p 6606 -M prepared -n -r -f ./test.sql -c 128 -j 128 -T 120 >>insert.log
sleep 10
pgbench -d postgres -U zhugy -p 6606 -M prepared -n -r -f ./test.sql -c 256 -j 256 -T 120 >>insert.log
sleep 10
pgbench -d postgres -U zhugy -p 6606 -M prepared -n -r -f ./test.sql -c 512 -j 512 -T 120 >>insert.log
sleep 10
pgbench -d postgres -U zhugy -p 6606 -M prepared -n -r -f ./test.sql -c 1000 -j 1000 -T 120 >>insert.log
测试脚本执行过程中,开启nmon监控,最后搜集分析结果数据。
测试结果
并发数 | TPS(insert) |
16 | 1333.567698 |
32 | 2552.525998 |
64 | 4919.909822 |
128 | 6373.980879 |
256 | 6069.215036 |
512 | 5926.957966 |
1000 | 5120.652663 |
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiAzNvwVZ2x2bzNXak9CX90TQNNkRrFlQKBTSvwFbslmZvwFMwQzLcVmepNHdu9mZvwFVywUNMZTY18CX052bm9CX9UFVNd3ZU90dFRVT3V1MMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2LcRHelR3LcJzLctmch1mclRXY39jMykTOwQTN2EDOwYDM4EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
nmon资源情况如下:
disk使用情况:
分析测试结果,发现测试过程中,CPU利用率最高才20%,性能瓶颈还是在磁盘IO能力。并发在128达到峰值,随着并发提高总体写的TPS开始降低。
用fio工具跑了下本台x86的随机写iops:1207
fio-2.1.10
Starting 10 threads
LOG: using stale statistics instead of current ones because stats collector is not responding
Jobs: 10 (f=10): [wwwwwwwwww] [100.0% done] [0KB/21568KB/0KB /s] [0/1348/0 iops] [eta 00m:00s]
mytest: (groupid=0, jobs=10): err= 0: pid=5470: Fri Jun 8 17:26:48 2018
write: io=1136.6MB, bw=19323KB/s, iops=1207, runt= 60228msec
再看看别人家的测试环境,果然硬件是硬伤。
fio-2.2.5
Starting 10 threads
Jobs: 10 (f=10): [w(10)] [100.0% done] [0KB/331.6MB/0KB /s] [0/42.5K/0 iops] [eta 00m:00s]
mytest: (groupid=0, jobs=10): err= 0: pid=148520: Fri Jun 8 17:33:29 2018
write: io=10240MB, bw=333464KB/s, iops=41682, runt= 31445msec
AntDB:
开源url:https://github.com/ADBSQL/AntDB
QQ交流群:496464280