TPC-C是专门针对联机交易处理系统(OLTP系统)的规范,通常状况下咱们也把这类系统称为业务处理系统。tpcc-mysql是percona基于TPC-C(下面简写成TPCC)衍生出来的产品,专用于MySQL基准测试。mysql
安装
经过下载源码编译安装(推荐)
MySQL中文网便捷下载地址:
http://imysql.com/wp-content/uploads/2014/09/tpcc-mysql-src.tgz
[root@server01 pkg]# gunzip tpcc-mysql-src.tgz
[root@server01 pkg]# tar -xf tpcc-mysql-src.tar
[root@server01 pkg]# cd tpcc-mysql
[root@server01 tpcc-mysql]# ls
add_fkey_idx.sql count.sql create_table.sql drop_cons.sql load.sh README schema2 scripts src
[root@server01 tpcc-mysql]# cd src/
[root@server01 src]# ls
delivery.c load.c Makefile ordstat.c payment.c rthist.h sequence.h spt_proc.c support.c trans_if.h
driver.c main.c neword.c parse_port.h rthist.c sequence.c slev.c spt_proc.h tpc.h
[root@server01 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
若是 make 没有报错,就会在 ../tpcc-mysql 下生成 tpcc 二进制命令行工具 tpcc_load 、 tpcc_start
[root@server01 src]# cd ..
[root@server01 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_load 提供初始化数据的功能
tpcc_start 进行压力测试sql
tpcc-mysql的业务逻辑及其相关的几个表做用以下:
New-Order:新订单,一次完整的订单事务,几乎涉及到所有表
Payment:支付,主要对应 orders、history 表
Order-Status:订单状态,主要对应 orders、order_line 表
Delivery:发货,主要对应 order_line 表
Stock-Level:库存,主要对应 stock 表
其余相关表:
客户:主要对应 customer 表
地区:主要对应 district 表
商品:主要对应 item 表
仓库:主要对应 warehouse 表 数据库
TPCC测试前准备
#建立测试数据库
[root@server01 tpcc-mysql]# mysqladmin -uroot create tpcc1000
#建立测试数据表
[root@server01 tpcc-mysql]# mysql -uroot -f tpcc1000 < create_table.sql
#建立外键和索引
[root@server01 tpcc-mysql]# mysql -uroot -f tpcc1000 < add_fkey_idx.sql
初始化完毕后,就能够开始加载测试数据了socket
开始测试
[root@server01 tpcc-mysql]# ./tpcc_load localhost tpcc1000 root "Aa123456789" 15
*************************************
*** ###easy### TPC-C Data Loader ***
*************************************
<Parameters>
[server]: localhost
[port]: 3306
[DBname]: tpcc1000
[user]: root
[pass]: Aa123456789
[warehouse]: 15工具
2002, HY000, Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
该错误是由于默认找的mysql.sock文件路径不一样,能够建立一个软链接
[root@server01 tpcc-mysql]# ln -s /data/mysqldata3306/sock/mysql.sock /var/lib/mysql/mysql.sock
加载过程比较缓慢,须要耐心等待
[root@server01 tpcc-mysql]# ./tpcc_load localhost tpcc1000 root "Aa123456789" 15
*************************************
*** ###easy### TPC-C Data Loader ***
*************************************
<Parameters>
[server]: localhost
[port]: 3306
[DBname]: tpcc1000
[user]: root
[pass]: Aa123456789
[warehouse]: 15
TPCC Data Load Started...
Loading Item
.................................................. 5000
......
.......... 3000
Orders Done.测试
...DATA LOADING COMPLETED SUCCESSFULLY.
加载完成后可进行测试
[root@server01 tpcc-mysql]# ./tpcc_start -hlocalhost -P3306 -d tpcc1000 -u root -p"Aa123456789" -w 15 -c 10 -r 120 -l 120
***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option h with value 'localhost'
option P with value '3306'
option d with value 'tpcc1000'
option u with value 'root'
option p with value 'Aa123456789'
option w with value '15'
option c with value '10'
option r with value '120'
option l with value '120'
<Parameters>
[server]: localhost
[port]: 3306
[DBname]: tpcc1000
[user]: root
[pass]: Aa123456789
[warehouse]: 15
[connection]: 10
[rampup]: 120 (sec.)
[measure]: 120 (sec.)this
RAMP-UP TIME.(120 sec.)命令行
MEASURING START.server
10, 15(10):13.769|15.806, 19(0):2.986|5.338, 1(0):1.646|1.951, 1(0):13.931|18.609, 0(0):19.999|45.221
20, 12(10):10.660|10.737, 11(0):2.842|2.873, 2(0):0.577|1.896, 2(0):10.088|12.811, 2(2):19.999|40.274
30, 18(12):10.888|13.278, 16(0):1.416|2.252, 1(0):0.000|0.999, 1(0):0.000|8.792, 1(1):0.000|37.348
40, 13(6):8.680|13.399, 12(0):2.362|4.198, 1(0):0.000|0.593, 1(0):0.000|14.000, 2(2):19.999|45.828
50, 19(11):10.943|11.400, 16(0):2.667|3.177, 3(0):0.488|0.790, 2(0):10.548|11.274, 0(0):0.000|0.000
60, 11(7):8.947|11.514, 15(0):2.810|3.232, 1(0):0.000|0.569, 2(0):11.321|11.724, 3(3):19.999|40.327
70, 16(13):10.152|11.452, 15(0):2.586|2.738, 2(0):0.489|0.746, 1(0):0.000|10.245, 1(1):0.000|40.009
80, 14(9):10.407|11.322, 15(0):2.127|2.458, 1(0):0.000|0.479, 2(0):9.574|11.261, 2(2):19.999|41.798
90, 19(12):9.147|9.379, 21(0):3.113|4.260, 1(0):0.000|0.826, 1(0):0.000|13.315, 2(2):19.999|38.874
100, 13(13):11.407|17.713, 13(0):1.502|1.815, 1(0):0.000|1.018, 2(0):13.091|13.434, 0(0):0.000|0.000
110, 15(12):9.611|11.027, 15(0):2.136|2.491, 2(0):0.311|0.660, 2(0):12.476|12.597, 2(2):19.999|43.571
120, 13(12):9.200|13.701, 14(0):2.347|2.436, 2(0):0.431|0.854, 1(0):0.000|9.053, 2(2):19.999|37.823
-- 以逗号分隔,共6列
-- 第一列,第N次10秒
-- 第二列,新订单成功执行压测的次数(推迟执行压测的次数):90%事务的响应时间|本轮测试最大响应时间,新订单事务数也被认为是总有效事务数的指标
-- 第三列,支付业务成功执行次数(推迟执行次数):90%事务的响应时间|本轮测试最大响应时间
-- 第四列,订单状态业务的结果,后面几个的意义同上
-- 第五列,物流发货业务的结果,后面几个的意义同上
-- 第六列,库存仓储业务的结果,后面几个的意义同上
STOPPING THREADS..........索引
<Raw Results> -- 第一次统计结果
[0] sc:51 lt:127 rt:0 fl:0 -- New-Order,新订单业务成功(success,简写sc)次数,延迟(late,简写lt)次数,重试(retry,简写rt)次数,失败(failure,简写fl)次数
[1] sc:182 lt:0 rt:0 fl:0 -- Payment,支付业务统计,其余同上
[2] sc:18 lt:0 rt:0 fl:0 -- Order-Status,订单状态业务统计,其余同上
[3] sc:18 lt:0 rt:0 fl:0 -- Delivery,发货业务统计,其余同上
[4] sc:0 lt:17 rt:0 fl:0 -- Stock-Level,库存业务统计,其余同上
in 120 sec.
<Raw Results2(sum ver.)> -- 第二次统计结果
[0] sc:51 lt:127 rt:0 fl:0
[1] sc:182 lt:0 rt:0 fl:0
[2] sc:18 lt:0 rt:0 fl:0
[3] sc:18 lt:0 rt:0 fl:0
[4] sc:0 lt:17 rt:0 fl:0
<Constraint Check> (all must be [OK])
[transaction percentage]
Payment: 44.07% (>=43.0%) [OK] -- 支付成功次数(上述统计结果中 sc + lt)必须大于43.0%,不然结果为NG,而不是OK
Order-Status: 4.36% (>= 4.0%) [OK] -- 订单状态,其余同上
Delivery: 4.36% (>= 4.0%) [OK] -- 发货,其余同上
Stock-Level: 4.12% (>= 4.0%) [OK] -- 库存,其余同上
[response time (at least 90% passed)] -- 响应耗时指标必须超过90%经过才行
New-Order: 28.65% [NG] * -- 下面几个响应耗时指标所有 100% 经过
Payment: 100.00% [OK]
Order-Status: 100.00% [OK]
Delivery: 100.00% [OK]
Stock-Level: 0.00% [NG] *
<TpmC> 89.000 TpmC -- TpmC结果值(每分钟事务数,该值是第一次统计结果中的新订单事务数除以总耗时分钟数)