在青云的云主机(不是RDS)上做了一个简单的PostgreSQL的pgbench测试。结果如下
1. 环境
VM:1 core 1G mem的低端
云主机配置
PostgresQL9.4.2
(shared_buffers = 128MB,其它都是默认值)
-
[root@xxxxxxx chenhj]# cat /proc/cpuinfo
-
processor : 0
-
vendor_id : GenuineIntel
-
cpu family : 6
-
model : 44
-
model name : Westmere E56xx/L56xx/X56xx (Nehalem-C)
-
stepping : 1
-
microcode : 1
-
cpu MHz : 2099.998
-
cache size : 4096 KB
-
physical id : 0
-
siblings : 1
-
core id : 0
-
cpu cores : 1
-
apicid : 0
-
initial apicid : 0
-
fpu : yes
-
fpu_exception : yes
-
cpuid level : 11
-
wp : yes
-
flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc up rep_good unfair_spinlock pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt aes hypervisor lahf_lm
-
bogomips : 4199.99
-
clflush size : 64
-
cache_alignment : 64
-
address sizes : 40 bits physical, 48 bits virtual
-
power management:
-
2. pgbench测试
初始化时把scale因子设成100,数据库的大小大概是1.5GB,超过VM内存大小,所以后面的测试会考验IO能力。
2.1 SELECT only测试
-
[chenhj@i-yh5e8qjy ~]$ pgbench postgres -n -S -T 20
-
transaction type: SELECT only
-
scaling factor: 100
-
query mode: simple
-
number of clients: 1
-
number of threads: 1
-
duration: 20 s
-
number of transactions actually processed: 31586
-
latency average: 0.633 ms
-
tps = 1579.263361 (including connections establishing)
-
tps = 1579.519711 (excluding connections establishing)
-
-
[chenhj@i-yh5e8qjy ~]$ pgbench postgres -n -S -c 40 -T 20
-
transaction type: SELECT only
-
scaling factor: 100
-
query mode: simple
-
number of clients: 40
-
number of threads: 1
-
duration: 20 s
-
number of transactions actually processed: 50851
-
latency average: 15.732 ms
-
tps = 2537.321342 (including connections establishing)
-
tps = 2552.737465 (excluding connections establishing)
第1遍测试时,可能tps很低,需要再测几次,取数据预热后的结果。
单并发时的top结果:
-
[chenhj@xxxxxx ~]$ top
-
top - 00:58:42 up 14 days, 10:17, 2 users, load average: 0.30, 0.10, 0.05
-
Tasks: 91 total, 1 running, 90 sleeping, 0 stopped, 0 zombie
-
Cpu(s): 5.7%us, 3.4%sy, 0.0%ni, 0.0%id, 90.6%wa, 0.0%hi, 0.3%si, 0.0%st
-
Mem: 1020224k total, 953392k used, 66832k free, 102380k buffers
-
Swap: 1048572k total, 6856k used, 1041716k free, 559156k cached
-
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
-
26080 chenhj 20 0 257m 45m 44m D 5.7 4.5 0:00.84 postgres
-
16 root 20 0 0 0 0 S 0.7 0.0 0:26.19 kblockd/0
-
30 root 20 0 0 0 0 S 0.7 0.0 0:07.86 kswapd0
-
26078 chenhj 20 0 13156 1024 864 S 0.7 0.1 0:00.09 pgbench
-
644 root 20 0 82012 496 432 S 0.3 0.0 17:16.78 gapd
-
774 dbus 20 0 21536 828 628 S 0.3 0.1 3:46.44 dbus-daemon
-
26086 root 20 0 99340 4296 3212 S 0.3 0.4 0:00.05 sshd
-
1 root 20 0 19360 884 708 S 0.0 0.1 0:24.92 init
-
...
40并发时的top结果:
-
[chenhj@xxxxxx ~]$ top
-
top - 01:06:13 up 14 days, 10:24, 3 users, load average: 11.31, 2.63, 0.88
-
Tasks: 136 total, 2 running, 134 sleeping, 0 stopped, 0 zombie
-
Cpu(s): 53.0%us, 23.7%sy, 0.0%ni, 0.0%id, 20.0%wa, 0.0%hi, 3.3%si, 0.0%st
-
Mem: 1020224k total, 951204k used, 69020k free, 80936k buffers
-
Swap: 1048572k total, 6796k used, 1041776k free, 695264k cached
-
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
-
26634 chenhj 20 0 14532 1488 864 R 6.9 0.1 0:01.09 pgbench
-
26648 chenhj 20 0 257m 29m 28m S 2.3 3.0 0:00.27 postgres
-
26636 chenhj 20 0 257m 31m 30m S 2.0 3.2 0:00.30 postgres
-
26637 chenhj 20 0 257m 31m 30m S 2.0 3.1 0:00.29 postgres
-
26638 chenhj 20 0 257m 31m 30m D 2.0 3.1 0:00.28 postgres
-
26639 chenhj 20 0 257m 31m 30m S 2.0 3.2 0:00.28 postgres
-
26640 chenhj 20 0 257m 30m 30m S 2.0 3.1 0:00.27 postgres
-
...
2.2 TPC-B测试
TPC-B测试的结果和SELECT only类似,单并发的瓶颈在IO+CPU,多并发的瓶颈在CPU。
-
[chenhj@xxxxxx ~]$ pgbench postgres -n -T 20
-
transaction type: TPC-B (sort of)
-
scaling factor: 100
-
query mode: simple
-
number of clients: 1
-
number of threads: 1
-
duration: 20 s
-
number of transactions actually processed: 4494
-
latency average: 4.450 ms
-
tps = 223.468810 (including connections establishing)
-
tps = 223.499750 (excluding connections establishing)
-
-
[chenhj@xxxxxx ~]$ pgbench postgres -n -c 40 -T 20
-
transaction type: TPC-B (sort of)
-
scaling factor: 100
-
query mode: simple
-
number of clients: 40
-
number of threads: 1
-
duration: 20 s
-
number of transactions actually processed: 8938
-
latency average: 89.505 ms
-
tps = 445.559512 (including connections establishing)
-
tps = 447.203517 (excluding connections establishing)
以下是测试期间的top结果
单并发时的top结果 :
-
top - 01:08:23 up 14 days, 10:26, 3 users, load average: 1.52, 1.77, 0.79
-
Tasks: 98 total, 1 running, 97 sleeping, 0 stopped, 0 zombie
-
Cpu(s): 21.8%us, 7.8%sy, 0.0%ni, 30.7%id, 39.2%wa, 0.0%hi, 0.3%si, 0.0%st
-
Mem: 1020224k total, 953208k used, 67016k free, 81232k buffers
-
Swap: 1048572k total, 6796k used, 1041776k free, 747164k cached
-
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
-
26866 chenhj 20 0 257m 56m 55m D 24.0 5.7 0:02.25 postgres
-
26864 chenhj 20 0 13156 1036 864 S 3.3 0.1 0:00.31 pgbench
-
...
40并发时的top结果:
-
top - 01:09:41 up 14 days, 10:28, 3 users, load average: 3.08, 1.95, 0.92
-
Tasks: 137 total, 1 running, 136 sleeping, 0 stopped, 0 zombie
-
Cpu(s): 55.2%us, 14.7%sy, 0.0%ni, 0.3%id, 28.4%wa, 0.0%hi, 1.3%si, 0.0%st
-
Mem: 1020224k total, 943184k used, 77040k free, 81356k buffers
-
Swap: 1048572k total, 7584k used, 1040988k free, 684020k cached
-
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
-
26968 chenhj 20 0 14536 1516 864 S 6.3 0.1 0:00.53 pgbench
-
26326 root 20 0 177m 9.9m 3784 S 2.0 1.0 0:07.30 iotop
-
26970 chenhj 20 0 257m 14m 13m S 2.0 1.4 0:00.16 postgres
-
26971 chenhj 20 0 257m 13m 12m S 1.7 1.4 0:00.14 postgres
-
26972 chenhj 20 0 257m 13m 12m S 1.7 1.4 0:00.13 postgres
-
26974 chenhj 20 0 257m 13m 12m S 1.7 1.4 0:00.13 postgres
-
26975 chenhj 20 0 257m 13m 12m S 1.7 1.4 0:00.13 postgres
-
...
3. 个人PC虚拟机上的对比测试
下面在我
个人PC的虚拟机上做个对比测试
3.1 环境
宿主机
CPU:AMD Athlon II X4 640 3.0GHz
MEM:6G
OS:Win7 64bit
虚拟机所在存储:Apacer A S510S 128GB
虚拟机
CPU:4 core
MEM: 2G
OS:CentOS release 6.5 (Final)
PostgreSQL:9.3.4(shared_buffers = 128MB,其它都是默认值)
3.2 pgbench测试
SELECT only测试
-
[chenhj@node1 ~]$ pgbench pgbench -n -S -T 20
-
transaction type: SELECT only
-
scaling factor: 100
-
query mode: simple
-
number of clients: 1
-
number of threads: 1
-
duration: 20 s
-
number of transactions actually processed: 10727
-
latency average: 1.864 ms
-
tps = 536.303234 (including connections establishing)
-
tps = 536.414343 (excluding connections establishing)
-
-
[chenhj@node1 ~]$ pgbench pgbench -n -S -c 40 -T 20
-
transaction type: SELECT only
-
scaling factor: 100
-
query mode: simple
-
number of clients: 40
-
number of threads: 1
-
duration: 20 s
-
number of transactions actually processed: 65291
-
latency average: 12.253 ms
-
tps = 3261.046820 (including connections establishing)
-
tps = 3303.491893 (excluding connections establishing)
在这里不管单并发还是40并发,性能瓶颈都在CPU,SSD对这点IOPS表示毫无压力,40并发的tps高于单并发的原因在于可以充分利用4个core。
以下是测试过程中的top的结果
单并发时的top结果:
-
[root@node1 ~]# top
-
top - 02:17:52 up 1 day, 15:50, 4 users, load average: 0.22, 0.06, 0.01
-
Tasks: 153 total, 2 running, 151 sleeping, 0 stopped, 0 zombie
-
Cpu(s): 3.2%us, 11.2%sy, 0.0%ni, 84.3%id, 1.3%wa, 0.0%hi, 0.0%si, 0.0%st
-
Mem: 1921956k total, 1847408k used, 74548k free, 4216k buffers
-
Swap: 2064376k total, 508k used, 2063868k free, 1701720k cached
-
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
-
19424 chenhj 20 0 257m 105m 104m R 57.1 5.6 0:06.69 postgres
-
19422 chenhj 20 0 13156 968 816 S 18.6 0.1 0:02.07 pgbench
-
37 root 20 0 0 0 0 S 2.3 0.0 0:02.41 kblockd/3
-
17607 chenhj 20 0 256m 5116 4672 S 0.7 0.3 0:01.91 postgres
-
59 root 20 0 0 0 0 S 0.3 0.0 0:26.95 kswapd0
-
1 root 20 0 19364 752 540 S 0.0 0.0 0:01.77 init
40并发时的top结果:
-
[root@node1 ~]# top
-
top - 02:19:01 up 1 day, 15:52, 4 users, load average: 0.17, 0.07, 0.02
-
Tasks: 192 total, 7 running, 185 sleeping, 0 stopped, 0 zombie
-
Cpu(s): 21.1%us, 59.8%sy, 0.0%ni, 2.7%id, 10.2%wa, 3.4%hi, 2.9%si, 0.0%st
-
Mem: 1921956k total, 1847184k used, 74772k free, 4296k buffers
-
Swap: 2064376k total, 508k used, 2063868k free, 1650616k cached
-
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
-
19434 chenhj 20 0 14532 1432 816 R 13.5 0.1 0:00.57 pgbench
-
19437 chenhj 20 0 257m 14m 13m S 12.2 0.8 0:00.45 postgres
-
19436 chenhj 20 0 257m 14m 13m D 9.9 0.8 0:00.38 postgres
-
19441 chenhj 20 0 257m 14m 13m S 9.9 0.8 0:00.37 postgres
-
19470 chenhj 20 0 257m 13m 12m S 9.9 0.7 0:00.37 postgres
-
19438 chenhj 20 0 257m 14m 13m R 9.6 0.8 0:00.37 postgres
-
19440 chenhj 20 0 257m 14m 13m S 9.6 0.8 0:00.38 postgres
-
19442 chenhj 20 0 257m 14m 13m S 9.6 0.8 0:00.38 postgres
-
19446 chenhj 20 0 257m 14m 13m R 9.6 0.8 0:00.36 postgres
TPC-B测试
TPC-B测试的结果有些不同,瓶颈都在CPU+IO。
-
[chenhj@node1 ~]$ pgbench pgbench -n -T 20
-
transaction type: TPC-B (sort of)
-
scaling factor: 100
-
query mode: simple
-
number of clients: 1
-
number of threads: 1
-
duration: 20 s
-
number of transactions actually processed: 3251
-
latency average: 6.152 ms
-
tps = 162.526702 (including connections establishing)
-
tps = 162.558331 (excluding connections establishing)
-
-
[chenhj@node1 ~]$ pgbench pgbench -n -c 40 -T 20
-
transaction type: TPC-B (sort of)
-
scaling factor: 100
-
query mode: simple
-
number of clients: 40
-
number of threads: 1
-
duration: 20 s
-
number of transactions actually processed: 9361
-
latency average: 85.461 ms
-
tps = 467.186639 (including connections establishing)
-
tps = 471.360815 (excluding connections establishing)
比如40并发时,top结果在下面2种之间切换,应该是checkpoint的作用,平均的CPU利用率没有过半。
-
[root@node1 ~]# top
-
top - 02:34:49 up 1 day, 16:07, 4 users, load average: 0.17, 0.57, 0.46
-
Tasks: 192 total, 15 running, 177 sleeping, 0 stopped, 0 zombie
-
Cpu(s): 32.1%us, 25.2%sy, 0.0%ni, 33.9%id, 7.6%wa, 0.6%hi, 0.5%si, 0.0%st
-
Mem: 1921956k total, 1853080k used, 68876k free, 1596k buffers
-
Swap: 2064376k total, 508k used, 2063868k free, 1659988k cached
-
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
-
19672 chenhj 20 0 14536 1464 816 R 18.0 0.1 0:00.54 pgbench
-
19675 chenhj 20 0 257m 10m 9496 R 6.7 0.6 0:00.20 postgres
-
19674 chenhj 20 0 257m 10m 9692 R 6.3 0.6 0:00.19 postgres
-
19677 chenhj 20 0 257m 10m 9824 S 6.3 0.6 0:00.19 postgres
-
19678 chenhj 20 0 257m 10m 9696 R 6.3 0.6 0:00.19 postgres
-
19679 chenhj 20 0 257m 10m 9512 S 6.3 0.6 0:00.19 postgres
-
...
-
-
[root@node1 ~]# top
-
top - 02:34:55 up 1 day, 16:07, 4 users, load average: 2.80, 1.11, 0.64
-
Tasks: 192 total, 1 running, 191 sleeping, 0 stopped, 0 zombie
-
Cpu(s): 2.5%us, 1.5%sy, 0.0%ni, 34.2%id, 61.7%wa, 0.1%hi, 0.1%si, 0.0%st
-
Mem: 1921956k total, 1845764k used, 76192k free, 1628k buffers
-
Swap: 2064376k total, 508k used, 2063868k free, 1651344k cached
-
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
-
19672 chenhj 20 0 14536 1464 816 S 1.3 0.1 0:01.10 pgbench
-
19701 chenhj 20 0 257m 13m 11m S 1.3 0.7 0:00.36 postgres
-
19713 chenhj 20 0 257m 13m 11m S 1.3 0.7 0:00.39 postgres
-
19676 chenhj 20 0 257m 13m 12m S 1.0 0.7 0:00.37 postgres
-
19674 chenhj 20 0 257m 13m 12m S 0.7 0.7 0:00.40 postgres
-
19675 chenhj 20 0 257m 13m 12m S 0.7 0.7 0:00.38 postgres
-
...
4. 结论
1)青云云主机的IO还是蛮给力了,iops应该在500以上(又额外测了scale因子为10的情况,2并发时的TPC-B的tps能达到869)。
2)本人PC虚机的CPU效能太低,4个核才顶人家云主机的一个核(这也是服务器CPU和家用CPU的差别)。
阅读(3326) | 评论(0) | 转发(0) |