TPCC-MySQL安装、使用及结果解读

tpcc-mysql用于MySQL基准测试,percona基于TPC-C(下面简写成TPCC)衍生出来的产品。下面对tpcc-mysql进行安装然后使用,最后结果解读,安装very easy,let 's do it。

一、下载epel源

[root yum.repos.d]$ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.eyCDYb: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
        file /etc/yum.repos.d/epel-testing.repo from install of epel-release-6-8.noarch conflicts with file from package epel-release-5-4.noarch
        file /etc/yum.repos.d/epel.repo from install of epel-release-6-8.noarch conflicts with file from package epel-release-5-4.noarch

二、再安装安装bzr客户端

[root yum.repos.d]$ yum install bzr -y

之后就可以用bzr客户端下载tpcc-mysql源码了。

[root ~]$ bzr branch lp:~percona-dev/perconatools/tpcc-mysql
You have not informed bzr of your Launchpad ID, and you must do this to
write to Launchpad or access private data.  See "bzr help launchpad-login".
Branched 48 revision(s).
[root ~]$ ls -d tpcc-mysql/ 
tpcc-mysql/
[root ~]$ cd tpcc-mysql/src/
[root src]$ make

只要make即可,如果make没报错,就会在 /tmp/tpcc-mysql 下生成 tpcc 二进制命令行工具 tpcc_load 、 tpcc_start,可以看到已经下载成功了(安装就那么easy)

[root tpcc-mysql]$ pwd
/root/tpcc-mysql
[root 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

 

第二种安装方法:

在大牛的网站MySQL中文网下载源码包:http://imysql.com/wp-content/uploads/2014/09/tpcc-mysql-src.tgz,下载到本地后,先执行 gunzip 解压缩文件,再执行 tar xf 解包,直接 tar zxf 可能会报告异常。

[root src]$ pwd
/usr/local/src
[root src]$ wget http://imysql.com/wp-content/uploads/2014/09/tpcc-mysql-src.tgz
[root src]$ gunzip tpcc-mysql-src.tgz
[root src]$ tar xf tpcc-mysql-src.tar
[root src]$ cd tpcc-mysql/src
[root src]$ make
[root tpcc-mysql]$ pwd
/usr/local/src/tpcc-mysql
[root 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-mysql的业务逻辑及其相关的几个表作用如下:

New-Order:新订单,一次完整的订单事务,几乎涉及到全部表
Payment:支付,主要对应 orders、history 表
Order-Status:订单状态,主要对应 orders、order_line 表
Delivery:发货,主要对应 order_line 表
Stock-Level:库存,主要对应 stock 表

其它表说明:

客户:主要对应 customer 表
地区:主要对应 district 表
商品:主要对应 item 表
仓库:主要对应 warehouse 表

 

三、TPCC测试前准备

初始化测试库环境,先创建一个测试库然后导入create_table.sql,顾名思义是创表的sql语句:

[root tpcc-mysql]$mysql -uroot -p123456 -S /data/mysql-5.5/mysql.sock -e "create database tpcctest"
[root tpcc-mysql]$ mysql -uroot -p123456 -S /data/mysql-5.5/mysql.sock tpcctest <./create_table.sql 
[root tpcc-mysql]$ mysql -uroot -p123456 -S /data/mysql-5.5/mysql.sock -e "show tables from  tpcctest"
+--------------------+
| Tables_in_tpcctest |
+--------------------+
| customer           |
| district           |
| history            |
| item               |
| new_orders         |
| order_line         |
| orders             |
| stock              |
| warehouse          |
+--------------------+

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

tpcc_load用法如下:

[root tpcc-mysql]$ ./tpcc_load --help
*************************************
*** ###easy### TPC-C Data Loader  ***
*************************************
 usage: tpcc_load [server] [DB] [user] [pass] [warehouse]
      OR
        tpcc_load [server] [DB] [user] [pass] [warehouse] [part] [min_wh] [max_wh]

在这里,需要注意的是 tpcc 默认会读取 /var/lib/mysql/mysql.sock 这个socket 文件。因此,如果你的 socket 文件不在相应路径的话,可以做个软连接,或者通过TCP/IP的方式连接测试服务器

真实测试场景中,仓库数一般不建议少于100个,视服务器硬件配置而定,如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,建议最少不低于1000个仓库越多,造数据的时间越长,需要耐心等待

 

执行下面的命令,开始灌入测试数据:(本人的是虚拟机,仓库数就弄了10,省得压死了,哈哈)

[root tpcc-mysql]$ ./tpcc_load 127.0.0.1:3308 tpcctest root 123456 10

造数据成功后,会提示:...DATA LOADING COMPLETED SUCCESSFULLY.

 

四、进行TPCC测试及结果解读
tpcc_start 工具用于tpcc压测,其用法如下:

[root tpcc-mysql]$ ./tpcc_start --help
***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
./tpcc_start: invalid option -- '-'
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

选项说明:

-w 指定仓库数量
-c 指定并发连接数
-r 指定开始测试前进行warmup的时间,进行预热后,测试效果更好
-l 指定测试持续时间
-i  指定生成报告间隔时长
-f 指定生成的报告文件名

使用例子:

[root tpcc-mysql]$ ./tpcc_start -h127.0.0.1 -P3308 -d tpcctest -u root -p 123456 -w 10 -c 10 -r 120 -l 120 

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

结果解读:

***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option h with value '127.0.0.1'
option P with value '3308'
option d with value 'tpcctest'
option u with value 'root'
option p with value '123456'
option w with value '10'
option c with value '10'
option r with value '120'
option l with value '120'
<Parameters>
     [server]: 127.0.0.1      -- 主机
     [port]: 3308             -- 端口
     [DBname]: tpcctest       -- 压测的数据库
       [user]: root           -- 账号
       [pass]: 123456         -- 密码
  [warehouse]: 10             -- 仓库数
 [connection]: 10             -- 并发线程数 
     [rampup]: 120 (sec.)     -- 数据预热时长 
    [measure]: 120 (sec.)     -- 压测时长

RAMP-UP TIME.(120 sec.)       --预热结束

MEASURING START.              --开始压测

  10, 27(0):3.829|7.321, 26(0):1.854|4.399, 3(0):1.503|1.670, 3(0):4.467|5.559, 3(0):14.525|20.229 --每10秒输出一次压测数据
  20, 31(0):3.153|3.247, 29(0):0.861|1.202, 3(0):0.400|0.475, 3(0):4.471|4.980, 0(0):0.000|0.000
  30, 28(0):3.559|3.943, 27(0):0.807|0.838, 2(0):0.285|0.379, 2(0):3.273|3.628, 3(0):13.534|13.577
  40, 26(0):3.643|4.040, 32(0):0.676|0.686, 4(0):0.337|0.393, 4(0):4.397|5.081, 6(0):13.890|16.757
  50, 32(1):4.377|5.695, 30(0):0.749|0.813, 2(0):0.254|0.309, 3(0):3.418|4.066, 2(0):11.356|12.581
  60, 32(0):3.561|3.602, 33(0):1.024|1.645, 4(0):0.318|0.413, 3(0):3.446|3.542, 5(0):11.772|12.417
  70, 41(0):3.228|3.415, 39(0):0.956|1.296, 4(0):0.394|0.396, 5(0):3.671|3.925, 1(0):0.000|13.920
  80, 35(1):4.096|6.454, 35(0):0.727|0.877, 3(0):0.344|0.410, 3(0):3.100|3.961, 4(0):11.251|11.489
  90, 27(0):2.787|3.505, 25(0):0.945|1.093, 2(0):0.394|0.423, 2(0):2.804|5.293, 3(0):11.637|12.463
 100, 31(2):5.050|5.467, 31(0):0.835|0.884, 4(0):0.334|0.363, 4(0):3.094|3.738, 2(0):11.853|11.885
 110, 32(0):3.101|3.968, 33(0):0.606|1.503, 3(0):0.255|0.347, 3(0):3.007|3.427, 5(0):11.685|12.653
 120, 34(0):3.359|3.713, 33(0):0.730|0.844, 3(0):0.319|0.504, 3(0):3.092|3.502, 2(0):8.187|10.347

-- 以逗号分隔,共6列
-- 第一列,第N次10秒
-- 第二列,新订单成功执行压测的次数(推迟执行压测的次数):90%事务的响应时间|本轮测试最大响应时间,新订单事务数也被认为是总有效事务数的指标
-- 第三列,支付业务成功执行次数(推迟执行次数):90%事务的响应时间|本轮测试最大响应时间
-- 第四列,订单状态业务的结果,后面几个的意义同上
-- 第五列,物流发货业务的结果,后面几个的意义同上
-- 第六列,库存仓储业务的结果,后面几个的意义同上

STOPPING THREADS..........          -- 结束压测
 
<Raw Results>                       -- 第一次统计结果
  [0] sc:372  lt:4  rt:0  fl:0      -- New-Order,新订单业务成功(success,简写sc)次数,延迟(late,简写lt)次数,重试(retry,简写rt)次数,失败(failure,简写fl)次数
  [1] sc:373  lt:0  rt:0  fl:0      -- Payment,支付业务统计,其他同上
  [2] sc:37  lt:0  rt:0  fl:0       -- Order-Status,订单状态业务统计,其他同上
  [3] sc:38  lt:0  rt:0  fl:0       -- Delivery,发货业务统计,其他同上
  [4] sc:36  lt:0  rt:0  fl:0       -- Stock-Level,库存业务统计,其他同上
 in 120 sec.

<Raw Results2(sum ver.)>            -- 第二次统计结果,其他同上
  [0] sc:372  lt:4  rt:0  fl:0 
  [1] sc:373  lt:0  rt:0  fl:0 
  [2] sc:37  lt:0  rt:0  fl:0 
  [3] sc:38  lt:0  rt:0  fl:0 
  [4] sc:36  lt:0  rt:0  fl:0 

<Constraint Check> (all must be [OK])     -- 下面所有业务逻辑结果都必须为 OK 才行
 [transaction percentage]
        Payment: 43.37% (>=43.0%) [OK]    -- 支付成功次数(上述统计结果中 sc + lt)必须大于43.0%,否则结果为NG,而不是OK
   Order-Status: 4.30% (>= 4.0%) [OK]     --订单状态,其他同上
       Delivery: 4.42% (>= 4.0%) [OK]     -- 发货,其他同上
    Stock-Level: 4.19% (>= 4.0%) [OK]     -- 库存,其他同上
 [response time (at least 90% passed)]    -- 响应耗时指标必须超过90%通过才行
      New-Order: 98.94%  [OK]             -- 下面几个响应耗时指标全部 100% 通过
        Payment: 100.00%  [OK]
   Order-Status: 100.00%  [OK]
       Delivery: 100.00%  [OK]
    Stock-Level: 100.00%  [OK]

<TpmC>
                 188.000 TpmC  -- TpmC结果值(每分钟事务数,该值是第一次统计结果中的新订单事务数除以总耗时分钟数,例如本例中是:372/2=186

 

想了解更多内容可以参考:http://imysql.com/2014/10/10/tpcc-mysql-full-user-manual.shtml

http://imysql.com/2012/08/04/tpcc-for-mysql-manual.html

 

作者:陆炫志

出处:xuanzhi的博客 http://www.cnblogs.com/xuanzhi201111

您的支持是对博主最大的鼓励,感谢您的认真阅读。本文版权归作者所有,欢迎转载,但请保留该声明。

 

视频下载:http://pan.baidu.com/s/1mgE84HE

 

posted @ 2014-12-06 16:44  GoogSQL  阅读(7270)  评论(1编辑  收藏  举报