Tpcc-mysql是percona基于tpcc衍生出来专用于mysql基准测试的产品,在业界有较高知名度,下面就介绍此工具的使用,及数据结果使用gnuplot绘图。
1,安装 tpcc-mysql:
yum install bzr
bzr branch lp:~percona-dev/perconatools/tpcc-mysql
注:如果yum 找不到bzr 先安装仓库:
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
源码拷贝下来后,就需要适当的修改Makefile 否则可能会编译出错而失败,下面红色部分根据实际情况修改
[root@localhost src]# cat Makefile
#
# "make all" to build necessary executables.
#
LIBS= `mysql_config --libs_r` -lrt
INC= -I. `mysql_config --include` -I /opt/app/mysql5/include/mysql/
#DEFS= -DDEBUG
CFLAGS= -w -O2 -g
TRANSACTIONS= neword.o payment.o ordstat.o delivery.o slev.o
OBJS= main.o spt_proc.o driver.o support.o sequence.o rthist.o $(TRANSACTIONS)
.SUFFIXES:
.SUFFIXES: .o .c
.c.o:
$(CC) $(CFLAGS) $(INC) $(DEFS) -c $*.c
all: ../tpcc_load ../tpcc_start
../tpcc_load : load.o support.o
$(CC) load.o support.o $(LIBS) -L /opt/app/mysql5/lib/mysql/ -o ../tpcc_load
../tpcc_start : $(OBJS)
$(CC) $(OBJS) $(LIBS) -L /opt/app/mysql5/lib/mysql/ -o ../tpcc_start
clean :
rm -f *.o
[root@localhost src]#
安装完毕在根目录下有:
[root@localhost tpcc-mysql]# ls
add_fkey_idx.sql
create_table.sql
load.sh
schema2
src
tpcc_start
count.sql
drop_cons.sql
README
scripts
tpcc_load
[root@localhost tpcc-mysql]#
建议多读 README,测试过程写的比较详细
2,测试前准备
1> 首先根据readme 生成测试库
mysql> create database tpcc1000;
mysql> use tpcc1000
mysql> \. /opt/create_table.sql
mysql> \. /opt/add_fkey_idx.sql
2> 生成测试数据
[root@localhost src]#./tpcc_load 192.168.1.2 tpcc1000 nigel "12345" 20
生成测试数据(这步可能需要很长时间,根据机器性能不同而不同)。
3> 测试开始:
下列测试分别对 innodb_buffer_pool_size = 8M,512M,2G 进行测试,事务及实际关系结果下如图1所示:
./tpcc_start -h172.16.0.230 -dtpcc1000 -unigel -p12345 -w20 -c16 -r10 -l1200 > /opt/8m-tpcc-data.log
./tpcc_start -h172.16.0.230 -dtpcc1000 -unigel -p12345 -w20 -c16 -r10 -l1200 > /opt/512m-tpcc-data.log
./tpcc_start -h172.16.0.230 -dtpcc1000 -unigel -p12345 -w20 -c16 -r10 -l1200 > /opt/2g-tpcc-data.log
: -d 测试库
:-u 用户名
:-p 密码
:-w 使用多少个数据仓库
:-c 测试的并发数
:-r 预热几秒
:-l 运行测试多长时间
log内容截取如下:
cat 2g-tpcc-data.txt
***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option h with value '172.16.0.230'
option d with value 'tpcc1000'
option u with value 'nigel'
option p with value '12345'
option w with value '20'
option c with value '16'
option r with value '10'
option l with value '1200'
<Parameters>
[server]: 192.168.1.2
[port]: 3306
[DBname]: tpcc1000
[user]: nigel
[pass]: 12345
[warehouse]: 20
[connection]: 16
[rampup]: 10 (sec.)
[measure]: 1200 (sec.)
RAMP-UP TIME.(10 sec.)
MEASURING START.
10, 19(0):2.842|2.860, 13(0):0.492|0.536, 2(0):0.214|0.245, 1(0):0.000|2.713, 0(0):0.000|0.000
20, 18(0):2.742|2.826, 16(0):0.467|0.482, 1(0):0.000|0.215, 2(0):2.759|2.969, 2(0):7.584|7.773
30, 19(0):2.646|2.717, 24(0):0.461|0.505, 2(0):0.201|0.224, 2(0):2.527|2.620, 2(0):7.603|7.767
40, 39(0):1.939|2.287, 32(0):0.512|0.579, 3(0):0.198|0.205, 2(0):2.301|2.985, 5(0):6.314|6.601
50, 33(0):2.207|2.255, 38(0):0.408|0.484, 4(0):0.203|0.211, 3(0):2.595|2.680, 3(0):5.515|5.698
60, 44(0):2.050|2.151, 47(0):0.405|0.408, 5(0):0.193|0.221, 5(0):2.530|2.586, 5(0):5.918|6.438
70, 59(0):2.192|2.212, 54(0):0.395|0.412, 5(0):0.207|0.225, 7(0):2.390|2.447, 5(0):5.680|6.023
80, 60(0):1.927|1.987, 58(0):0.421|0.461, 7(0):0.203|0.207, 4(0):2.197|2.264, 6(0):5.693|6.001
90, 64(0):2.104|2.234, 66(0):0.444|0.487, 6(0):0.190|0.210, 6(0):2.422|2.426, 7(0):5.359|6.044
100, 69(0):2.016|2.152, 68(0):0.415|0.425, 6(0):0.199|0.201, 9(0):2.324|2.355, 7(0):5.568|5.768
110, 74(0):2.147|2.148, 76(0):0.463|0.482, 8(0):0.218|0.246, 7(0):2.252|2.312, 9(0):5.610|5.769
120, 88(0):2.162|2.215, 89(0):0.441|0.513, 9(0):0.204|0.216, 9(0):2.208|2.455, 6(0):5.792|6.034
130, 100(0):1.961|1.981, 101(0):0.433|0.449, 10(0):0.209|0.210, 9(0):2.345|2.355,(0):5.856|5.880
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
STOPPING THREADS................
<Raw Results>
[0] sc:10874 lt:0 rt:0 fl:0
[1] sc:10869 lt:0 rt:0 fl:0
[2] sc:1089 lt:0 rt:0 fl:0
[3] sc:1086 lt:0 rt:0 fl:0
[4] sc:1091 lt:0 rt:0 fl:0
in 1200 sec.
<Raw Results2(sum ver.)>
[0] sc:10894 lt:0 rt:0 fl:0
[1] sc:10883 lt:0 rt:0 fl:0
[2] sc:1089 lt:0 rt:0 fl:0
[3] sc:1086 lt:0 rt:0 fl:0
[4] sc:1091 lt:0 rt:0 fl:0
<Constraint Check> (all must be [OK])
[transaction percentage]
Payment: 43.46% (>=43.0%) [OK]
Order-Status: 4.35% (>= 4.0%) [OK]
Delivery: 4.34% (>= 4.0%) [OK]
Stock-Level: 4.36% (>= 4.0%) [OK]
[response time (at least 90% passed)]
New-Order: 100.00% [OK]
Payment: 100.00% [OK]
Order-Status: 100.00% [OK]
Delivery: 100.00% [OK]
Stock-Level: 100.00% [OK]
<TpmC>
543.700 TpmC
[root@localhost opt]#
#
#=================================
#
4> 生成测试数据文件:
./tpcc_analyze.sh /opt/8m-tpcc-data.log > tpcc-8-data.txt
./tpcc_analyze.sh /opt/512m-tpcc-data.log > tpcc-512-data.txt
./tpcc_analyze.sh /opt/2g-tpcc-data.log > tpcc-2g-data.txt
3,使用gnuplot 绘图
1> 合并数据文件,以便于画图:
paste tpcc-8-data.txt tpcc-512-data.txt tpcc-2g-data.txt > tpcc-graph-data.txt
2> 使用脚本画图;
./tpcc-graph.sh tpcc-graph-data.txt 201.jpg
4,附脚本:
[root@localhost shell]# cat tpcc_analyze.sh
#!/bin/bash
TIMESLOT=1
if [ -n "$2" ]
then
TIMESLOT=$2
echo "Defined $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 ?\n",$1,aggr) ; cntr=0; aggr=0 } } '
[root@localhost shell]# cat tpcc-graph.sh
#!/bin/bash
gnuplot << EOP
set style line 1 lt 1 lw 3
set style line 2 lt 5 lw 3
set style line 3 lt 9 lw 3
set terminal jpeg size 640,480
set grid x y
set xlabel "Time(sec)"
set ylabel "Transactions"
set output '$2'
plot "$1" title "PS 5.1.56 buffer pool 8M" ls 1 with lines , \
"$1" us 3:4 title "PS 5.1.56 buffer pool 512M" ls 2 with lines ,\
"$1" us 5:6 title "PS 5.1.56 buffer pool 2G" ls 3 with lines axes x1y1
EOP
[root@localhost shell]#
完。