学习笔记:MySQL基准测试之tpcc-mysql

     如果第三方的sysbench(http://blog.csdn.net/sweeper_freedoman/article/details/73611154)是MySQL基准测试的专业版,那tpcc-mysql(https://code.launchpad.net/~percona-dev/perconatools/tpcc-mysql)就是旗舰版了。它由全球知名数据库服务商Percona公司的程序员开发,通过一套用3NF(第三范式)实现的仓储公司数据模型来模拟真实的业务压力,这套数据模型包含仓储公司库存管理、销售、产品分发、付款以及订单查询等现实场景下的一系列操作,一共包含9张表。结果采用学术界和工业界普遍使用的TPC-C评价OLTP应用的性能。

     安装tpcc-mysql到github(https://github.com/Percona-Lab/tpcc-mysql)上clone一份源码下来编译就行了。

root@ubuntu:~# git clone https://github.com/Percona-Lab/tpcc-mysql.git
root@ubuntu:~# cd tpcc-mysql/ ; ls
root@ubuntu:~/tpcc-mysql# cd src ; make
cc -w -O3 -g -I. `mysql_config --include`  -c load.c
/bin/sh: 1: mysql_config: not found
load.c:19:19: fatal error: mysql.h: 没有那个文件或目录
compilation terminated.
Makefile:22: recipe for target 'load.o' failed
make: *** [load.o] Error 1
root@ubuntu:~/tpcc-mysql/src# make clean
rm -f *.o

     啊噢,出现报错,我的本地Ubuntu Linux缺少“mysql_config”。

root@ubuntu:~/tpcc-mysql/src# mysql_config
程序“mysql_config”尚未安装。 您可以使用以下命令安装:
apt install libmysqlclient-dev
root@ubuntu:~/tpcc-mysql/src# apt install libmysqlclient-dev
root@ubuntu:~/tpcc-mysql/src# make
root@ubuntu:~/tpcc-mysql/src# cd .. ; ls | grep ^tpcc
tpcc_load
tpcc_start

     mysql_config包含在“ libmysqlclient-dev ”里,apt安装一下(yum系统为“ mysql-devel ”),然后编译成功。可以看到tpcc-mysql主程序目录下面多了两个以tpcc开头的核心文件。

     tpcc-mysql基准测试分为三个阶段,创建库表、加载数据和执行测试。

①创建库表。

     这一阶段是测试工作的准备阶段。包含创建一个基准测试用schema(如果已经创建好跳过即可),导入仓储公司数据模型表结构(必须)以及导入数据模型索引约束(可以等到第②阶段加载数据完成后再执行这一步)。

root@ubuntu:~/tpcc-mysql# mysqladmin -uroot -p520 create benchmarker
root@ubuntu:~/tpcc-mysql# mysql -uroot -p520 benchmarker < create_table.sql
root@ubuntu:~/tpcc-mysql# mysql -uroot -p520 benchmarker < add_fkey_idx.sql

②加载数据。

     即执行tpcc_load,创建加载一份测试数据。执行“ ./tpcc_load --help ”可以查看用法:|hostname| |port| |dbname| |user| |password| |WAREHOUSES|。本次测试实例创建11个仓库(-w)。

root@ubuntu:~/tpcc-mysql# ./tpcc_load  -h127.0.0.1 -P3306 -dbenchmarker -uroot -p520 -w11
*************************************
*** TPCC-mysql Data Loader        ***
*************************************
option h with value '127.0.0.1'
option p with value '3306'
option d with value 'benchmarker'
option u with value 'root'
option p with value '520'
option w with value '11'
<Parameters>
     [server]: 127.0.0.1
     [port]: 3306
     [DBname]: benchmarker
       [user]: root
       [pass]: 520
  [warehouse]: 11
TPCC Data Load Started...

***** 这里代表一大段啪啪啪眼花缭乱的打印输出 *****

...DATA LOADING COMPLETED SUCCESSFULLY.

     这一过程视机器性能和创建仓库量,可能要花一点时间往测试库表里写数据,执行过程会打印出来。

③执行测试。

     即执行tpcc_start,进行仓储公司业务场景测试。执行“ ./tpcc_start --help ”可以查看用法:|hostname| |port| |dbname| |user| |WAREHOUSES| |CONNECTIONS| |WARMUP TIME| |BENCHMARK TIME|。

  • warehouses(-w)仓库数量
  • connections(-c)连接线程数
  • warmup_time(-r)热身时间(秒:不计入测试)
  • running_time(-l)测试时间
  • report_interval(-i)测试报告打印时间间隔

root@ubuntu:~/tpcc-mysql# ./tpcc_start  -h127.0.0.1 -P3306 -dbenchmarker -uroot -p520 -w11 -c2 -r22 -l180
***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option h with value '127.0.0.1'
option p with value '3306'
option d with value 'benchmarker'
option u with value 'root'
option p with value '520'
option w with value '11'
option c with value '2'
option r with value '22'
option l with value '180'
<Parameters>
     [server]: 127.0.0.1
     [port]: 3306
     [DBname]: benchmarker
       [user]: root
       [pass]: 520
  [warehouse]: 11
 [connection]: 2
     [rampup]: 22 (sec.)
    [measure]: 180 (sec.)

RAMP-UP TIME.(22 sec.)

MEASURING START.

  10, trx: 6, 95%: 2665.596, 99%: 3636.936, max_rt: 3636.496, 5|789.268, 0|140.956, 1|1560.098, 1|10399.828
  20, trx: 9, 95%: 3520.185, 99%: 3520.185, max_rt: 3520.139, 9|689.531, 1|156.137, 1|965.955, 1|10290.280
  30, trx: 9, 95%: 1919.477, 99%: 1919.477, max_rt: 1919.449, 10|633.419, 1|868.591, 1|2240.299, 0|0.000

  ***** 这里代表一大段啪啪啪眼花缭乱的打印输出 *****
  
STOPPING THREADS..

<Raw Results>
  [0] sc:0 lt:173  rt:0  fl:0 avg_rt: 968.7 (5)
  [1] sc:1 lt:172  rt:0  fl:0 avg_rt: 268.5 (5)
  [2] sc:0 lt:17  rt:0  fl:0 avg_rt: 183.5 (5)
  [3] sc:0 lt:18  rt:0  fl:0 avg_rt: 1739.0 (80)
  [4] sc:0 lt:17  rt:0  fl:0 avg_rt: 9209.2 (20)
 in 180 sec.

<Raw Results2(sum ver.)>
  [0] sc:0  lt:173  rt:0  fl:0 
  [1] sc:1  lt:172  rt:0  fl:0 
  [2] sc:0  lt:17  rt:0  fl:0 
  [3] sc:0  lt:18  rt:0  fl:0 
  [4] sc:0  lt:17  rt:0  fl:0 

<Constraint Check> (all must be [OK])
 [transaction percentage]
        Payment: 43.47% (>=43.0%) [OK]
   Order-Status: 4.27% (>= 4.0%) [OK]
       Delivery: 4.52% (>= 4.0%) [OK]
    Stock-Level: 4.27% (>= 4.0%) [OK]
 [response time (at least 90% passed)]
      New-Order: 0.00%  [NG] *
        Payment: 0.58%  [NG] *
   Order-Status: 0.00%  [NG] *
       Delivery: 0.00%  [NG] *
    Stock-Level: 0.00%  [NG] *

<TpmC>
                 57.667 TpmC

     测试的一部分重要信息是格式化打印出来的,通过“ report_interval ”(-i)选项设置,默认10s,用于说明该时间段内仓储公司的订单处理。如本次测试前10s的输出

10, trx: 6, 95%: 2665.596, 99%: 3636.936, max_rt: 3636.496, 5|789.268, 0|140.956, 1|1560.098, 1|10399.828

  • 10。基准测试执行时间计时(秒)。
  • trx。当前给定区间内事务(New-Order)处理能力,值越大越好。“ 6, 95%: 2665.596, 99%: 3636.936 ”分别为事务量、95%以及99%事务响应时间(秒)。
  • max_rt。当前给定区间内事务(New-Order)响应时间的极大值(秒),3636.496。
  • the rest。其他事务(Payment、Order-Status、Delivery和Stock-Level)的处理能力和响应时间极大值,可以忽略。

     测试的最后一行给出TpmC值。Tpm是transaction per minute的缩写,C代表TPC(Transaction Processing Performance Council,事务处理性能协会)的C基准测试。该值的计算来自于上面的“ trx ”结果,默认情况下,首先求出New Order Per 10 Second的均值,然后乘以6,最后得到TpmC值。该值越大越好,表示更优良的事务处理能力。本次测试的TpmC值为57.667,来自于我笔记本电脑的一台小虚拟机。

     这几天着重学习了一下MySQL基准测试的知识和工具,这些内容暂时就以对tpcc-mysql工具的学习收尾。最后,返璞归真,总结一下性能测试中常用的指标。理解这些指标的涵义也许比实施基准测试更重要。MySQL数据库主要包括两大瓶颈:吞吐量和磁盘I/O。吞吐量主要体现在QPS、TPS、Request以及Request Time;磁盘I/O主要体现在IOPS。

  • QPS。Query Perl Second(每秒查询量),查询次数 / 时间(秒)。
  • TPS。Transaction Per Second(每秒事务量),事务次数 / 时间(秒)。
  • IOPS。Input / Output Operations Per Second(每秒读写操作量),读写次数 / 时间(秒)。


参考:

《MySQL技术内幕 InnoDB存储引擎》(https://book.douban.com/subject/24708143/
《高性能MySQL》(https://book.douban.com/subject/23008813/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值