Tpcc-MySQL
下载安装tpcc-mysql
1 | cd /usr/local |
安装之前需要保证将mysql_config添加到$PATH 环境变量中
1 | cd src ; make ( you should have mysql_config available in $PATH) |
初始化数据
1 | [mysql@master ~]$ mysqladmin -umysql -p -S /data/mysqldata/3306/mysql.sock create tpcc10 |
装载数据1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29/usr/local/tpcc-mysql/tpcc_load -hlocalhost -d tpcc10 -u mysql -p mysql -w 10
各列含义为: |hostname:port| |dbname| |user| |password| |WAREHOUSES
选项 warehouse 意为指定测试库下的仓库数量, 在生产环境中建议设置至少100以上
这里设置10个仓库
*************************************
*** TPCC-mysql Data Loader ***
*************************************
option h with value 'localhost'
option d with value 'tpcc10'
option u with value 'mysql'
option p with value 'mysql'
option w with value '10'
<Parameters>
[server]: localhost
[port]: 3306
[DBname]: tpcc10
[user]: mysql
[pass]: mysql
[warehouse]: 10
TPCC Data Load Started...
Loading Item
.................................................. 5000
.................................................. 10000
.................................................. 15000
.................................................. 20000
.................................................. 25000
.................................................. 30000
...
...DATA LOADING COMPLETED SUCCESSFULLY.
压力测试
1 | [mysql@master tpcc-mysql]$ /usr/local/tpcc-mysql/tpcc_start -h 172.16.120.130 -P 3306 -d tpcc10 -u mysql -p mysql -w 10 -c 10 -r 10 -l 360 -i 10 |
含义1
2
3
4
5
6
710, trx: 12920, 95%: 9.483, 99%: 18.738, max_rt: 213.169, 12919|98.778, 1292|101.096, 1293|443.955, 1293|670.842
10 - 从基准测试开始到现在的秒数
trx: 12920 - 在给定的间隔内(在这种情况下,在过去的10秒)内执行的新订单交易. 基本上这是每个间隔的吞吐量. 越多越好
95%:9.483: - 每次给定间隔的新订单交易的95%响应时间. 在这种情况下是9.483秒
99%:18.738: - 每次给定间隔的新订单交易的99%响应时间. 在这种情况下是18.738秒
max_rt:213.169: - 每个给定间隔的新订单交易的最大响应时间. 在这种情况下是213.169秒
其余的:12919 | 98.778,1292 | 101.096,1293 | 443.955,1293 | 670.842是其他类型的事务的吞吐量和最大响应时间,可以忽略
gnuplot出图
/usr/local/tpcc-mysql/scripts 目录下有一个analyze.sh
修改了一下,如果用gnuplot出图,则为1
2
3
4
5
6
7
8 cat tpcc.txt | grep -v HY000 | grep -v payment | grep -v neword | awk -v timeslot=1 ' BEGIN { FS="[,():]"; s=0; cntr=0 } /MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) {
cntr++; } if ( cntr==timeslot ) { printf ("%d %d\n",$1,$3) ; cntr=0;}}' >> tpcc-graphic-data.txt
10 99
20 118
30 154
40 207
50 225
只输出时间和trx列
gnuplot.cnf1
2
3
4
5
6
7
8
9
10set terminal gif small size 800,600 #指定输出成gif图片,且图片大小为550×25
set output "tpcc.gif" #指定输出gif图片的文件名
set title "MySQL Performance" #图片标题
set style data lines #显示网格
set xlabel "Time/s" #X轴标题
set ylabel "Transactions" #Y轴标题
set grid #显示网格
plot \
"tpcc-graphic-data.txt" using 1:2 title "Total throughput" with lines #从tpcc-graphic-data.txt文件中读取第一列和第二列作为X轴和Y轴数据,
示例名"Total throughput"
出图
cat gnuplot.cnf | gnuplot
highcharts出图
修改analyze.sh1
2
3
4
5
6
7
8
9 cat tpcc.txt | grep -v HY000 | grep -v payment | grep -v neword | awk -v timeslot=1 ' BEGIN { FS="[,():]"; s=0; cntr=0 } /MEASURING START/ { s=1} /STOPPING THREADS/ {s=0} /0/ { if (s==1) {
cntr++; } if ( cntr==timeslot ) { printf ("'{\'time\':'%d',\'trx\':'%d}\n",$1,$3) ; cntr=0;}}'
{'time':10,'trx':99}
{'time':20,'trx':118}
{'time':30,'trx':154}
{'time':40,'trx':207}
{'time':50,'trx':225}
{'time':60,'trx':276}
出图1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21import charts
def getData(file):
with open(file,'r') as data:
dicList=[]
for line in data:
dic=eval(line.strip())
dicList.append(dic)
timeList,trxList=[],[]
for i in dicList:
timeList.append(i['time'])
trxList.append(i['trx'])
dataList=list(zip(timeList,trxList))
return dataList
options = {
'title':{'text':'TPCC-MySQL'},
'yAxis':{'title':{'text':'trx'}}
}
charts.plot(getData('C:\\Users\\Fan\\tpcc.txt'),name='10 warehouse 10 connect',options=options,show='inline',)
不过要注意的是 这里是 trx是10秒的累计,每十秒一个trx
关于tpcc_load
tpcc_load用上面的方法是很慢的,实际上tpcc-mysql/下有一个脚本load_multi_schema.sh. 修改一下后1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55tpcc_load -h127.0.0.1 -d tpcc10 -u root -p "" -w 1000
各列含义为: |hostname:port| |dbname| |user| |password| |WAREHOUSES
选项 warehouse 意为指定测试库下的仓库数量, 在生产环境中建议设置至少100以上
$1 将要创建的数据库名
$2 仓库数量
$3 schema数量,这里为1
$4 数据库ip
这里mysql用户名密码socket写死了
[root@master2 tpcc-mysql]# more load_multi_schema.sh
#export LD_LIBRARY_PATH=/data/opt/bin/mysql-5.7.11-linux-glibc2.5-x86_64/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib/
DBNAME=$1
WH=$2
NSCHEMA=$3
HOST=$4
STEP=5 #step应该小于WH
schema=0
while [ $schema -lt $NSCHEMA ] #主循环
do
DBFULLNAME=${DBNAME}_${schema}
echo "Creating schema $DBFULLNAME"
mysqladmin -umysql -pmysql -S /data/mysqldata/3306/mysql.sock -f drop $DBFULLNAME
mysqladmin -umysql -pmysql -S /data/mysqldata/3306/mysql.sock create $DBFULLNAME
mysql -umysql -pmysql -S /data/mysqldata/3306/mysql.sock $DBFULLNAME < create_table.sql
mysql -umysql -pmysql -S /data/mysqldata/3306/mysql.sock $DBFULLNAME < add_fkey_idx.sql
mkdir -p out
#以上是创建数据库,跑初始化脚本
./tpcc_load -h$HOST -d $DBFULLNAME -u mysql -p mysql -w $WH -l 1 -m 1 -n $WH >> out/1_$DBFULLNAME.out &
#Usage: tpcc_load -h server_host -P port -d database_name -u mysql_user -p mysql_password -w warehouses -l part -m min_wh -n max_wh
#* [part]: 1=ITEMS 2=WAREHOUSE 3=CUSTOMER 4=ORDERS
#-m 1 就是建ITEMS
x=1
#在循环里建剩下的-m 1 -n 步长, 一次循环建多少个
while [ $x -le $WH ] #主循环里的嵌套循环
do
echo $x $(( $x + $STEP - 1 ))
./tpcc_load -h$HOST -d $DBFULLNAME -u mysql -p mysql -w $WH -l 2 -m $x -n $(( $x + $STEP - 1 )) >> out/2_$DBFULLNAME.$x.out &
./tpcc_load -h$HOST -d $DBFULLNAME -u mysql -p mysql -w $WH -l 3 -m $x -n $(( $x + $STEP - 1 )) >> out/3_$DBFULLNAME.$x.out &
./tpcc_load -h$HOST -d $DBFULLNAME -u mysql -p mysql -w $WH -l 4 -m $x -n $(( $x + $STEP - 1 )) >> out/4_$DBFULLNAME.$x.out &
x=$(( $x + $STEP ))
done
for job in `jobs -p`
do
echo $job
wait $job
done
schema=$(( $schema + 1 ))
done
现在load是并行的1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19[mysql@master2 tpcc-mysql]$ ./load_multi_schema.sh tpcc 10 1 192.168.98.128
Creating schema tpcc_0
Warning: Using a password on the command line interface can be insecure.
Database "tpcc_0" dropped
Warning: Using a password on the command line interface can be insecure.
Warning: Using a password on the command line interface can be insecure.
Warning: Using a password on the command line interface can be insecure.
1 5
6 10
28496
28497
28498
28499
28500
28501
28502
[mysql@master2 tpcc-mysql]$
out目录有日志