TPCC 是由 TPC(Transaction Processing Performance Council) 非盈利组织推出的一套基准测试程序,主要用于OLTP类应用的测试; 一些厂家出了一些新的硬件,要有卖点,鼓吹自己性能优秀,那么就需要用数据说话,拿出一些数值做对比,TPCC就是对比标准之一;
TPCC-MYSQL是什么? TPCC-MYSQL是Percona按照TPCC开发的,基于Mysql的压测工具,该工具模拟电商环境;TPCC-Mysql会模拟搭建一套生产环境,用于下单,支付,查订单,发货,查库存;模拟各个环节,然后获取数据,评估当前的环境的吞吐量
下载:
https://download.csdn.net/download/lusizeng/5505281
tpcc-mysql-src.tgz
解压 : tar -zxvf tpcc-mysql-src.tgz
设置环境变量: PATH=$PATH:/export/servers/mysql/bin
进入tpcc-mysql/src目录下 make编译,成功后会在tpcc-mysql下生成 tpcc_load 和tpcc_start
[root@localhost src]# make
cc -w -O2 -g -I. `mysql_config --include` -c load.c
cc -w -O2 -g -I. `mysql_config --include` -c support.c
cc load.o support.o `mysql_config --libs_r` -lrt -o ../tpcc_load
cc -w -O2 -g -I. `mysql_config --include` -c main.c
cc -w -O2 -g -I. `mysql_config --include` -c spt_proc.c
cc -w -O2 -g -I. `mysql_config --include` -c driver.c
cc -w -O2 -g -I. `mysql_config --include` -c sequence.c
cc -w -O2 -g -I. `mysql_config --include` -c rthist.c
cc -w -O2 -g -I. `mysql_config --include` -c neword.c
cc -w -O2 -g -I. `mysql_config --include` -c payment.c
cc -w -O2 -g -I. `mysql_config --include` -c ordstat.c
cc -w -O2 -g -I. `mysql_config --include` -c delivery.c
cc -w -O2 -g -I. `mysql_config --include` -c slev.c
cc main.o spt_proc.o driver.o support.o sequence.o rthist.o neword.o payment.o ordstat.o delivery.o slev.o `mysql_config --libs_r` -lrt -o ../tpcc_start
[root@localhost tpcc-mysql]# ls
add_fkey_idx.sql count.sql create_table.sql drop_cons.sql load.sh README schema2 scripts src tpcc_load tpcc_start
先建个测试库tpcc, 然后使用自带的脚本建表,加索引:
[root@localhost tpcc-mysql]# mysqladmin -h 192.168.10.10 -P 3358 -utony -ptony --database tpcc < create_table.sql
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [ERROR] unknown option '--database'
[root@localhost tpcc-mysql]# mysql -h 192.168.10.10 -P 3358 -utony -ptony tpcc < create_table.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost tpcc-mysql]#
[root@localhost tpcc-mysql]# mysql -h 192.168.10.10 -P 3358 -utony -ptony tpcc < add_fkey_idx.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost tpcc-mysql]# mysql -h 192.168.10.10 -P 3358 -utony -ptony tpcc -e "show tables;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------------+
| Tables_in_tpcc |
+----------------+
| customer |
| district |
| history |
| item |
| new_orders |
| order_line |
| orders |
| stock |
| warehouse |
+----------------+
[root@localhost tpcc-mysql]#
建模:./tpcc_load 192.168.10.13:3358 apple tony tony 10
报错,缺少库文件libmysqlclient.so.20,先查找该文件,然后连接到系统库/usr/local/lib下,然后路径给到/etc/ld.so.conf;最后更新即可
[root@localhost tpcc-mysql]# ./tpcc_load 192.168.10.13:3358 apple tony tony 10
./tpcc_load: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
[root@localhost tpcc-mysql]# find / -name libmysqlclient.so.20
/export/servers/mysql/lib/libmysqlclient.so.20
/tmp/mysql-5.7.19-linux-glibc2.12-x86_64bak/lib/libmysqlclient.so.20
[root@localhost tpcc-mysql]# ln -s /export/servers/mysql/lib/libmysqlclient.so.20 /usr/local/lib
[root@localhost tpcc-mysql]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
[root@localhost tpcc-mysql]# echo "/usr/local/lib" >> /etc/ld.so.conf
[root@localhost tpcc-mysql]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
[root@localhost tpcc-mysql]# /sbin/ldconfig -v
加载数据: ./tpcc_load 192.168.10.10:3358 tpcc tony tony 10 | tee output.log 要多等会儿,比较花费时间;
参数含义:连接192.168.10.10地址3358端口tpcc库账号tony,密码tony建10个仓库
customer表,对应客户,新建了30W条数据
district 表,对应地区,100个地区
history表,对应历史订单,
item: 对应商品,有10W个商品条目
new_orders: 新订单,9W
order_line: 订单状态300W
orders: 下单30W
stock:查看库存状态100W
warehouse: 仓库,即电商仓库数量10个;电商测试,建议根据实际情况修改仓库数量,一般不少于100个;
Usage: tpcc_start -h server_host -P port -d database_name -u mysql_user -p mysql_password -w warehouses -c connections -r warmup_time -l running_time -i report_interval -f report_file -t trx_file
./tpcc_start -h localhost -P 3358 -d tpcc -u tony -p tony -w 10 -c 30 -r 120 -l 120 -i 10 >> mysql_tpcc_20180801.log
查看当前QPS:
每秒获取QPS方法:
/export/servers/mysql/bin/mysqladmin -h 192.168.10.15 extended-status -utony -ptony -i 1 | grep "Question"
[root@localhost ~]# /export/servers/mysql/bin/mysqladmin -h 192.168.10.15 extended-status -utony -ptony -r -i1 | grep "Question"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
| Questions | 6676917 |
| Questions | 7402 |
| Questions | 7172 |
| Questions | 7601 |
| Questions | 6152 |
| Questions | 7320 |
QPS为 7000
结果解读
***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option P with value '3358' #运行tpcc_start时,带的参数
option d with value 'tpcc'
option u with value 'tony'
option p with value 'tony'
option w with value '10'
option c with value '30'
option r with value '120'
option l with value '120'
option i with value '10'
#实际使用的参数
[server]:
[port]: 3358 #端口
[DBname]: tpcc #库名
[user]: tony #mysql用户名
[pass]: tony #mysql密码
[warehouse]: 10 #仓库数量
[connection]: 30 #并发连接数
[rampup]: 120 (sec.) #预热时间,将数据写入到buffer_pool中
[measure]: 120 (sec.) #压测时长
RAMP-UP TIME.(120 sec.) #预热结束
MEASURING START.
10, 854(0):3.027|16.648, 859(0):0.965|9.486, 85(0):0.815|4.159, 85(0):4.097|13.359, 88(0):7.312|17.208
20, 844(1):1.718|5.140, 841(0):0.537|2.111, 85(0):0.468|0.562, 86(0):2.108|4.613, 82(0):4.764|5.047
30, 871(0):1.883|3.178, 870(0):0.509|3.244, 86(0):0.513|0.555, 84(0):2.200|2.215, 88(0):4.333|5.197
40, 844(0):2.197|4.243, 843(1):0.723|7.183, 86(1):0.687|5.731, 86(0):3.100|4.250, 83(0):5.481|6.318
50, 810(0):1.890|4.087, 799(0):0.702|2.816, 80(0):0.355|0.365, 82(0):2.441|2.759, 83(0):4.778|5.189
60, 802(0):2.139|3.964, 814(0):0.723|1.912, 81(0):0.697|0.815, 79(0):3.570|3.681, 79(0):4.690|5.785
70, 816(0):2.124|3.338, 811(0):0.604|1.152, 80(0):0.325|0.329, 81(0):2.248|3.083, 83(0):4.406|4.468
80, 831(0):1.937|3.364, 839(0):0.929|2.183, 85(0):0.535|0.607, 84(0):2.339|3.018, 82(0):4.506|4.552
90, 840(1):1.938|8.171, 838(0):0.643|1.403, 83(0):0.462|0.530, 83(0):2.178|2.370, 85(0):4.613|5.311
100, 755(0):2.247|3.770, 748(1):0.816|14.088, 76(0):0.449|1.147, 76(0):3.005|4.870, 74(0):5.476|6.505
110, 728(3):2.723|9.704, 735(0):0.911|2.240, 73(0):0.523|0.643, 73(0):3.778|5.682, 73(0):7.149|8.039
120, 762(3):3.312|18.949, 763(0):0.705|1.886, 75(0):0.342|0.346, 76(0):3.293|3.872, 78(0):6.436|6.860
STOPPING THREADS..............................
以第一行为例:
10, 854(0):3.027|16.648, 859(0):0.965|9.486, 85(0):0.815|4.159, 85(0):4.097|13.359, 88(0):7.312|17.208
10, 第一个10秒; 因为我运行的时候-l 120s,所以输出了12行,每行10s
创建订单:共计854次,失败(0)次,其中90%的订单创建花费3.027s,最长一个订单创建花费16.648s
订单支付:共计支付859个订单,失败0, 90%的支付花费0.965s,最长花费9.486s,
查询订单: 共查询85次,查询失败0次,90%的查询订单0.815s,最长查询4.159s
发货: 共发货85次,失败0次,90%的订单发货花费4.097s,最长发货时间: 13.359s
查询库存: 共查询88次,失败0次,90%的查询库存花费7.312s,最长查询库存17.208s
--第一次统计结果
[0] sc:9749 lt:8 rt:0 fl:0
--新建订单 success成功9749,later操作延时0,retry重试0, failure操作失败0
[1] sc:9758 lt:2 rt:0 fl:0
--支付,成功9758,延时,2,重试0,失败0,
[2] sc:974 lt:1 rt:0 fl:0
--查询订单,同上
[3] sc:975 lt:0 rt:0 fl:0
--发货
[4] sc:978 lt:0 rt:0 fl:0
--查询库存,同上
in 120 sec.
--第二次统计结果
[0] sc:9749 lt:8 rt:0 fl:0
[1] sc:9758 lt:2 rt:0 fl:0
[2] sc:974 lt:1 rt:0 fl:0
[3] sc:975 lt:0 rt:0 fl:0
[4] sc:978 lt:0 rt:0 fl:0
(all must be [OK]) --测试结果,下面所有结果都必须是OK
[transaction percentage] --事物比例
Payment: 43.48% (>=43.0%) [OK] --支付,43.48%,(参考考标准>=43.0%) OK
Order-Status: 4.34% (>= 4.0%) [OK] --订单状态
Delivery: 4.34% (>= 4.0%) [OK] --发货
Stock-Level: 4.36% (>= 4.0%) [OK] --查库存
[response time (at least 90% passed)] --响应时间,必须超过90%才算通过
New-Order: 99.92% [OK] --创建订单
Payment: 99.98% [OK] --支付
Order-Status: 99.90% [OK] --查询状态
Delivery: 100.00% [OK] --发货
Stock-Level: 100.00% [OK] --查库存
4878.500 TpmC
--Tpmc,transactions per minute ,每分钟处理订单个数的能力,需要注意的是,这个参数不仅仅是其他什么不跑,尽在那里处理新订单了,而是同时也会在进行订单查询,查库存等操作;
tpmC值在国内外被广 泛用于衡量计算机系统的事务处理能力,已经是公众认可的标准
计算方法是,12次新订单总数除以分钟数;即:(854+844+871+844+810+802+816+831+840+755+728+762)/2=4878 生产系统要跑一个相对较长的时间得到一个准确的值
[root@localhost tpcc-mysql]# cat tpcc-output-analyze.sh
# vim tpcc-output-analyze.sh
#!/bin/sh
TIMESLOT=1
if [ -n "$2" ]
then
TIMESLOT=$2
fi
cat $1 | grep -v HY000 | grep -v payment | grep -v neword | awk -v timeslot=$TIMESLOT 'BEGIN { FS="[,():]"; s=0; cntr=0; aggr=0 } /MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) { cntr++; aggr+=$2; } if ( cntr==timeslot ) { printf ("%d %3d\n",$1,(aggr/timeslot)) ; cntr=0; aggr=0 } }'
[root@localhost tpcc-mysql]#
[root@localhost tpcc-mysql]# sh tpcc-output-analyze.sh mysql_tpcc_20180801.log > tpcc-graphic-data.txt
[root@localhost tpcc-mysql]# cat tpcc-graphic-data.txt
10 854
20 844
30 871
40 844
50 810
60 802
70 816
80 831
90 840
100 755
110 728
120 762
[root@localhost tpcc-mysql]#
安装绘图工具:
yum install gnuplot
设置环境变量
export GDFONTPATH=/usr/share/fonts/dejavu
export GNUPLOT_DEFAULT_GDFONT=DejaVuSansMono
source ~/.bashrc
设置绘图配置文件,开始绘图:
[root@localhost tpcc-mysql]# cat log.conf
set terminal gif small size 480,360 #指定输出成gif图片,且图片大小为550×25
set output "tcpp.gif" #指定输出gif图片的文件名
set title "MySQL Performance" #图片标题
set style data lines #显示网格
set xlabel "Time/s" #X轴标题
set ylabel "Data" #Y轴标题
set grid #显示网格
plot \
"tpcc-graphic-data.txt" using 1:2 title "Total throughput" with lines
[root@localhost tpcc-mysql]# cat log.conf | gnuplot
[root@localhost tpcc-mysql]# ls
512m-tpcc-data.data count.sql drop_cons.sql log.conf README scripts tcpp.gif tpcc-graphic-data.txt tpcc-output-analyze.sh tpcc_start
add_fkey_idx.sql create_table.sql load.sh mysql_tpcc_20180801.log schema2 src tpcc_analyze.sh tpcc_load tpcc_report.res
[root@localhost tpcc-mysql]#
看到生成了tcpp.gif图片,把导出来打开;测试的时候可以跑几个小时,这样可以看得明显一些;
把仓库数改为5,时间延长一些3600s,得出的结果图: