您的位置:首页 > 数据库 > SQL

如何用tpcc-mysql工具进行oltp压力测试

2016-05-07 00:36 645 查看
一.下载源码包

1.下载:http://imysql.com/wp-content/uploads/2014/09/tpcc-mysql-src.tgz

2.解压和解包

[apps@mvxl0784 software]$ gunzip tpcc-mysql-src.tgz

[apps@mvxl0784 software]$ tar -xf tpcc-mysql-src.tar

tpcc-mysql的业务逻辑及其相关的几个表作用如下:

New-Order:新订单,一次完整的订单事务,几乎涉及到全部表

Payment:支付,主要对应 orders、history 表

Order-Status:订单状态,主要对应 orders、order_line 表

Delivery:发货,主要对应 order_line 表

Stock-Level:库存,主要对应 stock 表

其他相关表:

客户:主要对应 customer 表

地区:主要对应 district 表

商品:主要对应 item 表

仓库:主要对应 warehouse 表

二.编译

[apps@mvxl0784 software]$ cd tpcc-mysql

[apps@mvxl0784 tpcc-mysql]$ ls

add_fkey_idx.sql count.sql create_table.sql drop_cons.sql load.sh README schema2 scripts src

[apps@mvxl0784 tpcc-mysql]$ pwd

/apps/software/tpcc-mysql

[apps@mvxl0784 tpcc-mysql]$ cd src

[apps@mvxl0784 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

[apps@mvxl0784 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

三、TPCC测试前准备

初始化测试库环境

cd /apps/software/tpcc-mysql

/apps/svr/mariadb10/bin/mysql -u root -p --socket=/tmp/mysql3306.sock -e "create database tpcc100"

/apps/svr/mariadb10/bin/mysql -u root -p --socket=/tmp/mysql3306.sock -f tpcc100 < create_table.sql

初始化完毕后,就可以开始加载测试数据了

tpcc_load用法如下:

tpcc_load [server] [DB] [user] [pass] [warehouse]

或者

tpcc_load [server] [DB] [user] [pass] [warehouse] [part] [min_wh] [max_wh]

选项 warehouse 意为指定测试库下的仓库数量。

真实测试场景中,仓库数一般不建议少于100个,视服务器硬件配置而定,如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,建议最少不低于1000个。

执行下面的命令,开始灌入测试数据:

cd /apps/software/tpcc-mysql

./tpcc_load localhost tpcc100 root "safe2016" 100

在这里,需要注意的是 tpcc 默认会读取 /var/lib/mysql/mysql.sock 这个socket 文件。

因此,如果你的 socket 文件不在相应路径的话,可以做个软连接,或者通过TCP/IP的方式连接测试服务器,例如:

./tpcc_load 10.16.24.109:3306 tpcc100 root "safe2016" 100

我们这里采用建立link文件的方式:

[root@mvxl0784 lib]# cd /var/lib

[root@mvxl0784 lib]# mkdir mysql

[root@mvxl0784 lib]# cd /var/lib/mysql

[root@mvxl0784 mysql]# ln -s /tmp/mysql3306.sock mysql.sock

正式load数据:

cd /apps/software/tpcc-mysql

./tpcc_load localhost tpcc100 root "safe2016" 100

最后完成时显示如下:

Loading Orders for D=10, W= 100

.......... 1000

.......... 2000

.......... 3000

Orders Done.

...DATA LOADING COMPLETED SUCCESSFULLY.

四、进行TPCC测试

cd /apps/software/tpcc-mysql

./tpcc_start -h localhost -d tpcc100 -u root -p "safe2016" -w 100 -c 16 -r 120 -l 1800 -f tpcc_mysql_20160506.log >> tpcc_caseX_20160506.log 2>&1

即:模拟 100个仓库规模,并发 16个线程进行测试,热身时间为 120秒, 压测时间为 半小时。

真实测试场景中,建议预热时间不小于5分钟,持续压测时长不小于30分钟,否则测试数据可能不具参考意义。

*** ###easy### TPC-C Load Generator ***

***************************************

option h with value 'localhost'

option d with value 'tpcc100'

option u with value 'root'

option p with value 'safe2016'

option w with value '100'

option c with value '16'

option r with value '120'

option l with value '1800'

option f with value 'tpcc_mysql_20160506.log'

<Parameters>

[server]: localhost

[port]: 3306

[DBname]: tpcc100

[user]: root

[pass]: safe2016

[warehouse]: 100

[connection]: 16

[rampup]: 120 (sec.)

[measure]: 1800 (sec.)

RAMP-UP TIME.(120 sec.)

-- 预热结束,开始进行压测

MEASURING START.

-- 每10秒钟输出一次压测数据

10, 7272(0):1.316|6.084, 7269(0):0.297|4.315, 728(0):0.172|0.531, 728(0):1.512|3.179, 725(0):4.564|8.784

20, 7320(0):1.250|1.881, 7319(0):0.274|1.481, 732(0):0.157|0.306, 731(0):1.379|1.488, 733(0):3.884|5.327

30, 6502(0):1.271|1.967, 6501(0):0.273|0.681, 650(0):0.148|0.199, 652(0):1.424|2.062, 651(0):4.023|5.452

40, 7334(1):1.238|5.957, 7331(0):0.263|1.155, 733(0):0.143|0.204, 733(0):1.342|1.519, 733(0):3.790|5.539

50, 6450(0):1.280|2.436, 6457(0):0.276|0.679, 645(0):0.151|0.172, 645(0):1.444|1.544, 645(0):4.266|5.206

...........................................................................................................

1780, 6802(0):1.240|2.026, 6800(0):0.257|0.628, 680(0):0.156|0.222, 680(0):1.357|1.507, 678(0):3.838|5.044

1790, 7486(0):1.191|1.647, 7484(0):0.254|0.503, 749(0):0.138|0.204, 748(0):1.337|1.487, 750(0):3.638|4.761

1800, 6835(0):1.200|2.292, 6836(0):0.255|0.492, 683(0):0.142|0.165, 684(0):1.341|1.522, 682(0):3.673|4.887

-- 以逗号分隔,共6列

-- 第一列,第N次10秒

-- 第二列,新订单成功执行压测的次数(推迟执行压测的次数):90%事务的响应时间|本轮测试最大响应时间,新订单事务数也被认为是总有效事务数的指标

-- 第三列,支付业务成功执行次数(推迟执行次数):90%事务的响应时间|本轮测试最大响应时间

-- 第四列,订单状态业务的结果,后面几个的意义同上

-- 第五列,物流发货业务的结果,后面几个的意义同上

-- 第六列,库存仓储业务的结果,后面几个的意义同上

-- 压测结束

STOPPING THREADS................

-- 第一次结果统计

<Raw Results>

[0] sc:1235370 lt:15 rt:0 fl:0 -- New-Order,新订单业务成功(success,简写sc)次数,延迟(late,简写lt)次数,重试(retry,简写rt)次数,失败(failure,简写fl)次数

[1] sc:1235338 lt:4 rt:0 fl:0

[2] sc:123539 lt:0 rt:0 fl:0

[3] sc:123538 lt:0 rt:0 fl:0

[4] sc:123536 lt:0 rt:0 fl:0

in 1800 sec.

-- 第二次统计结果,其他同上

<Raw Results2(sum ver.)>

[0] sc:1235373 lt:15 rt:0 fl:0

[1] sc:1235381 lt:4 rt:0 fl:0

[2] sc:123539 lt:0 rt:0 fl:0

[3] sc:123539 lt:0 rt:0 fl:0

[4] sc:123537 lt:0 rt:0 fl:0

<Constraint Check> (all must be [OK]) -- 下面所有业务逻辑结果都必须为 OK 才行

[transaction percentage]

Payment: 43.48% (>=43.0%) [OK] -- 支付成功次数(上述统计结果中 sc + lt)必须大于43.0%,否则结果为NG,而不是OK

Order-Status: 4.35% (>= 4.0%) [OK]

Delivery: 4.35% (>= 4.0%) [OK]

Stock-Level: 4.35% (>= 4.0%) [OK]

[response time (at least 90% passed)] -- 响应耗时指标必须超过90%通过才行

New-Order: 100.00% [OK] -- 下面几个响应耗时指标全部 100% 通过

Payment: 100.00% [OK]

Order-Status: 100.00% [OK]

Delivery: 100.00% [OK]

Stock-Level: 100.00% [OK]

<TpmC>

41179.500 TpmC -- TpmC结果值(每分钟事务数,该值是第一次统计结果中的新订单事务数除以总耗时分钟数,例如本例中是:1235370/30 = 41179)

测试下轮开始前,需要如下处理:

1、如何避免压测时受到缓存的影响

a、填充测试数据比物理内存还要大,至少超过 innodb_buffer_pool_size 值,不能将数据全部装载到内存中,除非你的本意就想测试全内存状态下的MySQL性能。

b、每轮测试完成后,都重启mysqld实例,并且用下面的方法删除系统cache,释放swap(如果用到了swap的话),甚至可以重启整个OS。

sync -- 将脏数据刷新到磁盘

echo 3 > /proc/sys/vm/drop_caches -- 清除OS Cache

swapoff -a && swapon -a
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: