测试了mysql5.6.13 开启与关闭log-bin 两种情况下的性能。
环境: Intel(R) Xeon(R) CPU E5620 12G内存 CentOS release 6.4 (Final) SAS硬盘 XFS文件系统
安装tpcc-mysql
yum install bzr cd ~ bzr branch lp:~percona-dev/perconatools/tpcc-mysql cd tpcc-mysql/src 修改 Makefile中mysql_config的路径。 make all
然后就在 ~/tpcc-mysql/ 目录中生成了 tpcc_load与 tpcc_start 两个可执行文件。
yum install gnuplot
注释掉/etc/my.cnf中的 log-bin
创建测试库:
cd ~/tpcc-mysql mysql -u root -p -e "CREATE DATABASE tpcc1000;" mysql -u root -p tpcc1000 < create_table.sql mysql -u root -p tpcc1000 < add_fkey_idx.sql
导入数据:
./tpcc_load 127.0.0.1 tpcc1000 root "123456" 20
20是指20个warehouse,经常看到他们用1000来测试。 不过导入数据的速度啊,20个已经很慢了。。
最终出现: …DATA LOADING COMPLETED SUCCESSFULLY.
开测:
./tpcc_start -h127.0.0.1 -dtpcc1000 -uroot -p123456 -w20 -c16 -r10 -l1200 > tpcc-output-nobinlog -w20 表示20个warehouse -c16 表示并发16个线程, 在mysql show processlist中可以看到有16条语句在并发执行。 -r10 预热10秒。 -l1200 测试持续1200秒。 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-output-nobinlog的内容:
10, 5266(0):2.695|3.028, 5269(0):0.500|0.696, 526(0):0.236|0.291, 526(0):3.061|3.177, 528(0):8.839|9.383 20, 5137(0):2.731|2.907, 5123(0):0.499|0.680, 514(0):0.236|0.265, 514(0):3.036|3.217, 512(0):8.481|9.151 30, 4947(0):2.764|2.938, 4957(0):0.502|0.552, 494(0):0.234|0.240, 496(0):3.084|3.849, 496(0):9.260|9.532 40, 5017(0):2.743|2.928, 5024(0):0.504|0.677, 503(0):0.236|0.365, 502(0):3.066|4.199, 504(0):8.864|9.406 ... ... ... ... <TpmC> 22805.301 TpmC
10,5266 表示0-10秒,完成了5266个transactions 20,5137 表示10-20秒,完成了5137个transactions 30,4947 表示20-30秒,完成了4947个transactions 最终的绘图,也是基于这些数据。
最后的TPMC: transactions per minute 表示平均每分钟完成 22805个transactions
然后修改/etc/my.cnf 打开log-bin 重复上面的测试过程, 生成 tpcc-output-binlog 这次的TpMC是 18524.949 TpmC
如果仅仅是比较TpMC,那么也没有必要用图表了。。
tpcc-output-analyze.sh 内容如下:
#!/bin/bash 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 } } '
这个脚本就是对 tpcc-output-nobinlog 的第一列与第二列进行运算。
[root@yw-0-0 tpcc-mysql]# ./tpcc-output-analyze.sh tpcc-output-binlog 3 >tpcc-data-binlog [root@yw-0-0 tpcc-mysql]# [root@yw-0-0 tpcc-mysql]# ./tpcc-output-analyze.sh tpcc-output-nobinlog 3 >tpcc-data-nobinlog [root@yw-0-0 tpcc-mysql]# [root@yw-0-0 tpcc-mysql]# [root@yw-0-0 tpcc-mysql]# head tpcc-data-nobinlog 30 5116 60 4981 90 5234 120 1003 150 1007 180 4499 210 5106 240 5477 270 2943 300 1831
30 5116 表示0~30秒,平均每10秒完成 5116个transactions 60 4981 表示30~60秒,平均每10秒完成 4981个transactions
然后把二个计算结果拼到一个文件中方便绘图:
[root@yw-0-0 tpcc-mysql]# paste tpcc-data-binlog tpcc-data-nobinlog >tpcc-graphic-data.txt [root@yw-0-0 tpcc-mysql]# head tpcc-graphic-data.txt 30 4782 30 5116 60 4472 60 4981 90 4930 90 5234 120 259 120 1003 150 320 150 1007 180 2460 180 4499 210 4523 210 5106 240 5095 240 5477 270 4011 270 2943 300 271 300 1831
前两列为 binlog的数据,后两列为nobinlog的数据。
绘图的脚本 tpcc-graph-build.sh 如下:
#! /bin/bash ### goto user homedir and remove previous file rm -f '$2' gnuplot << EOP ### set data source file datafile = '$1' ### set graph type and size set terminal jpeg size 640,480 ### set titles set grid x y set xlabel "Time (sec)" set ylabel "Transactions" ### set output filename set output '$2' ### build graph # plot datafile with lines plot datafile title "5.6.13, binlog" with lines, \ datafile using 3:4 title "5.6.13, nobinlog" with lines axes x1y1 EOP
开始绘图:
[root@yw-0-0 tpcc-mysql]# [root@yw-0-0 tpcc-mysql]# ./tpcc-graph-build.sh tpcc-graphic-data.txt tpcc-graph.jpg
比较不解的是,为啥数据抖动这么大呢?
查看更多关于tpcc-mysql 与 gnuplot的详细内容...