1. 程式人生 > >MySQL壓測工具--TPCC安裝,測試

MySQL壓測工具--TPCC安裝,測試

enc 解讀 file 事務 AC space 過大 一次 基準

今天我們來講一下MySQL的壓力測試工具,目前我接觸到的主要有兩種壓力測試工具:TPCC,Sysbench,前者只適合MySQL數據庫OLTP壓力測試,而Sysbench功能就比較廣泛,可以測試OS的CPU,Memory,IO,以及多種關系型數據庫,如MySQL,PostgreSQL;

這篇博客主要講解Tpcc 安裝,測試。


簡介

TPC-C是專門針對聯機交易處理系統(OLTP系統)的規範,一般情況下我們也把這類系統稱為業務處理系統;

tpcc-mysql是percona基於TPC-C衍生出來的產品,專用於MySQL基準測試。


安裝

下載安裝epel:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm


安裝bzr客戶端:

yum install -y bzr


下載tpcc-mysql-master.zip軟件:

https://github.com/Percona-Lab/tpcc-mysql

unzip tpcc-mysql-master.zip

cd tpcc-mysql-master/src/

make


如果 make 編譯沒有報錯,就會在 /tmp/tpcc-mysql 下生成 tpcc 二進制命令行工具 tpcc_load 、 tpcc_start;


Tpcc工具結構介紹

create_table.sql:創建所需的數據庫表,共9個表

add_fkey_idx.sql:創建索引和外鍵

drop_cons.sql:刪除約束


這9個表的關系:

customer district history item new_orders order_line orders stock warehouse


技術分享圖片



tpcc-mysql的業務邏輯及其相關的幾個表作用如下:

New-Order:新訂單,一次完整的訂單事務,幾乎涉及到全部表

Payment:支付,主要對應 orders、history 表

Order-Status:訂單狀態,主要對應 orders、order_line 表

Delivery:發貨,主要對應 order_line 表

Stock-Level:庫存,主要對應 stock 表

其他相關表:

客戶:主要對應 customer 表

地區:主要對應 district 表

商品:主要對應 item 表

倉庫:主要對應warehouse 表


測試步驟

(1)建庫建表

mysqladmin -uroot -p147258 create tpccdb;

mysql -uroot -p147258 tpccdb < /tmp/tpcc-mysql-master/create_table.sql

mysql -uroot -p147258 tpccdb < /tmp/tpcc-mysql-master/add_fkey_idx.sql --這一步也可以在加載數據之後做;


(2)填充數據

如:向tpccdb壓測100個倉庫數量:

./tpcc_load -hlocalhost -dtpccdb -uroot -p147258 -w100

【NOTE】選項 warehouse為測試庫下的倉庫數量,真實測試場景中,倉庫數一般不建議少於100個,視服務器硬件配置而定,如果是配備了SSD或者PCie SSD這種高IOPS設備的話,建議最少不低於1000個。


補充tpcc_load的參數:

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

-h 指定主機名

-P 指定mysql端口

-d 指定庫名

-u 指定用戶

-p 指定密碼

-w 指定倉庫數

-l 指定* [part]: 1=ITEMS 2=WAREHOUSE 3=CUSTOMER 4=ORDERS

-m 指定最小warehouse

-n 指定最大warehouse


(3)開始測試

如:指定倉庫1000,並發數32,預熱120s,測試持續1h;

tpcc_start -hlocalhost -d tpccdb -u root -p "147258" -w 1000 -c 32 -r 120 -l 3600 -f tpcc_mysql_20140921.log >>tpcc_caseX_20140921.log 2>&1

【NOTE】真實測試場景中,建議預熱時間不小於5分鐘,持續壓測時長不小於30分鐘,否則測試數據可能不具參考意義。


補充tpcc_start的用法:

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 指定並發連接數,默認是1;

-r 指定開始測試前進行warmup的時間,單位s;

-l 指定測試持續時間,單位s;

-i 指定生成報告間隔時長

-f 指定生成的報告文件名


TPCC結果解讀

output註釋:

10, trx: 12920, 95%: 9.483, 99%: 18.738, max_rt: 213.169, 12919|98.778, 1292|101.096, 1293|443.955, 1293|670.842

20, trx: 12666, 95%: 7.074, 99%: 15.578, max_rt: 53.733, 12668|50.420, 1267|35.846, 1266|58.292, 1267|37.421

30, trx: 13269, 95%: 6.806, 99%: 13.126, max_rt: 41.425, 13267|27.968, 1327|32.242, 1327|40.529, 1327|29.580

40, trx: 12721, 95%: 7.265, 99%: 15.223, max_rt: 60.368, 12721|42.837, 1271|34.567, 1272|64.284, 1272|22.947

50, trx: 12573, 95%: 7.185, 99%: 14.624, max_rt: 48.607, 12573|45.345, 1258|41.104, 1258|54.022, 1257|26.626


--10 - the seconds from the start of the benchmark

(每隔10s統計 )


--trx: 12920 - New Order transactions executed during the gived interval (in this case, for the previous 10 sec). Basically this is the --throughput per interval. The more the better

(在10s內新訂單事物數,該值越大說明性能越好)


--95%: 9.483: - The 95% Response time of New Order transactions per given interval. In this case it is 9.483 sec

每個給定區間的新訂單事務的95%響應時間


--99%: 18.738: - The 99% Response time of New Order transactions per given interval. In this case it is 18.738 sec

每個給定區間的新訂單事務的99%響應時間


--max_rt: 213.169: - The Max Response time of New Order transactions per given interval. In this case it is 213.169 sec

(新訂單事物最大響應的時間 )


--the rest: 12919|98.778, 1292|101.096, 1293|443.955, 1293|670.842 is throughput and max response time for the other kind of transactions and can be ignored

(其他事物數和最大響應時間)



開始壓測指定倉庫10個,並發32個,預熱10s,持續120s,每隔10s生成報告,並生成日誌文件tpccdb20170315.log:
(這裏的測試是自己的虛擬機,硬件配置不太好,所以測試參數沒有設置過大,只是為了能有個結果供我們學習分析,不具有參考意義)

[root@Darren1 tpcc-mysql-master]# ./tpcc_start -S /tmp/mysql.sock -hlocalhost -dtpccdb -uroot -p147258 -w10 -c32 -r10 -l120 -ftpccdb20170315.log
***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option S (socket) with value '/tmp/mysql.sock'
option h with value 'localhost'
option d with value 'tpccdb'
option u with value 'root'
option p with value '147258'
option w with value '10'
option c with value '32'
option r with value '10'
option l with value '120'
option f with value 'tpccdb20170315.log'
<Parameters>
     [server]: localhost
     [port]: 3306
     [DBname]: tpccdb
       [user]: root
       [pass]: 147258
  [warehouse]: 10
 [connection]: 32
     [rampup]: 10 (sec.)     --預熱時長
    [measure]: 120 (sec.)     --測試時長
RAMP-UP TIME.(10 sec.)             --預熱結束
MEASURING START.              --測試開始
  10, trx: 13, 95%: 15137.766, 99%: 18323.255, max_rt: 18325.580, 14|13748.201, 0|1574.186, 0|0.000, 0|0.000
  20, trx: 13, 95%: 21680.204, 99%: 22399.251, max_rt: 22399.842, 10|23612.802, 2|6979.888, 0|0.000, 0|0.000
  30, trx: 14, 95%: 21550.797, 99%: 24865.887, max_rt: 24863.416, 8|19415.285, 0|0.000, 1|34375.755, 0|0.000
  40, trx: 6, 95%: 30071.479, 99%: 30071.479, max_rt: 30070.638, 13|21700.073, 2|1556.698, 0|0.000, 0|0.000
  50, trx: 16, 95%: 16555.115, 99%: 18088.917, max_rt: 18089.462, 15|10727.610, 1|985.788, 2|44921.254, 0|0.000
  60, trx: 6, 95%: 20426.460, 99%: 20426.460, max_rt: 20427.254, 7|16342.486, 0|0.000, 0|0.000, 0|0.000
  70, trx: 7, 95%: 20840.263, 99%: 20840.263, max_rt: 20842.583, 6|17685.274, 0|0.000, 2|71371.553, 1|73601.007
  80, trx: 12, 95%: 19331.825, 99%: 21961.066, max_rt: 21963.506, 12|16032.869, 2|6187.316, 0|0.000, 0|0.000
  90, trx: 10, 95%: 14917.352, 99%: 14917.352, max_rt: 14915.321, 8|11906.947, 1|3237.487, 1|56860.851, 1|73551.862
 100, trx: 8, 95%: 19061.751, 99%: 19061.751, max_rt: 19061.873, 9|14089.579, 1|433.691, 2|54415.280, 3|106539.602
 110, trx: 16, 95%: 16076.521, 99%: 16270.171, max_rt: 16268.213, 3|11618.824, 1|92.480, 1|8790.656, 0|0.000
 120, trx: 10, 95%: 13437.587, 99%: 13437.587, max_rt: 13437.183, 22|31044.348, 1|5419.699, 2|53726.988, 0|0.000
STOPPING THREADS................................                  --結束壓測
<Raw Results>                                            --第一次統計結果
  [0] sc:0 lt:131  rt:0  fl:0 avg_rt: 13862.8 (5)        --new-order,新訂單業務成功次數(success),延遲次數(late),重試次數(retry),失敗次數(failure),平均重試次數
  [1] sc:0 lt:127  rt:0  fl:0 avg_rt: 8024.2 (5)         --payment,支付業務統計
  [2] sc:0 lt:11  rt:0  fl:0 avg_rt: 3254.7 (5)         --order-status,訂單狀態業務統計
  [3] sc:0 lt:11  rt:0  fl:0 avg_rt: 56329.9 (80)        --delivery 發貨業務統計
  [4] sc:0 lt:5  rt:0  fl:0 avg_rt: 208602.8 (20)        --stock-level庫存業務統計
 in 120 sec.
<Raw Results2(sum ver.)>                                             --第二次測試結果
  [0] sc:0  lt:131  rt:0  fl:0
  [1] sc:0  lt:127  rt:0  fl:0
  [2] sc:0  lt:11  rt:0  fl:0
  [3] sc:0  lt:11  rt:0  fl:0
  [4] sc:0  lt:5  rt:0  fl:0
<Constraint Check> (all must be [OK])       --所有的都必須OK才行
 [transaction percentage]
        Payment: 44.56% (>=43.0%) [OK]   --支付成功次數,結果大於43%,為OK,結果小於43%,為NG;
   Order-Status: 3.86% (>= 4.0%) [NG] *    --訂單狀態
       Delivery: 3.86% (>= 4.0%) [NG] *  --發貨狀態
    Stock-Level: 1.75% (>= 4.0%) [NG] *   --庫存狀態
 [response time (at least 90% passed)]      --響應耗時指標必須超過90%通過才行
      New-Order: 0.00%  [NG] *       --表示not good
        Payment: 0.00%  [NG] *
   Order-Status: 0.00%  [NG] *
       Delivery: 0.00%  [NG] *
    Stock-Level: 0.00%  [NG] *
<TpmC>
                 65.500 TpmC    --TpmC結果值(每分鐘事務數,該值是第一次統計結果中的新訂單事務數除以總耗時分鐘數,例如本例中是:131/2=65.5),TpmC/60=tps



FAQ

安裝時候的報錯

[root@Darren1 tpcc-mysql-master]# ./tpcc_load help

./tpcc_load: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

解決方法:

[root@Darren1 tpcc-mysql-master]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20



參考鏈接:

http://imysql.com/2014/10/10/tpcc-mysql-full-user-manual.shtml

http://imysql.com/2015/07/28/mysql-benchmark-reference.shtml



MySQL壓測工具--TPCC安裝,測試