DBA必備!30分鐘學會tpcc-mysql基準測試

2019-11-17     波波說運維

概述

TPC-C是專門針對聯機交易處理系統(OLTP系統)的規範,一般情況下我們也把這類系統稱為業務處理系統。
tpcc-mysql是percona基於TPC-C(下面簡寫成TPCC)衍生出來的產品,專用於MySQL基準測試。其源碼放在launchpad上,用bazaar管理。


一、 安裝tpcc-mysql

1、下載源碼包

官方:https://code.launchpad.net/~percona-dev/perconatools/tpcc-mysql

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

 wget https://codeload.github.com/Percona-Lab/tpcc-mysql/zip/master

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

New-Order:新訂單,一次完整的訂單事務,幾乎涉及到全部表
Payment:支付,主要對應 orders、history 表
Order-Status:訂單狀態,主要對應 orders、order_line 表
Delivery:發貨,主要對應 order_line 表
Stock-Level:庫存,主要對應 stock 表

其他相關表:
客戶:主要對應 customer 表
地區:主要對應 district 表
商品:主要對應 item 表
倉庫:主要對應 warehouse 表

2、編譯安裝
編譯非常簡單,只需要一個 make 即可。

unzip tpcc-mysql-master.zip -d /usr/local/
cd /usr/local/tpcc-mysql-master/src
make

如果 make 沒有報錯,就會在/usr/local/tpcc-mysql-master下生成 tpcc 二進位命令行工具 tpcc_load 、 tpcc_start

3、配置環境變量

echo "export PATH=$PATH:/usr/local/tpcc-mysql-master" >> /etc/profile
source /etc/profile

二、TPCC測試前準備

1、創建測試資料庫

set global validate_password_policy=0;
create database tpcc;
grant all privileges on tpcc.* to tpcc@'%' identified by 'tpcc@1234';
flush privileges;

2、初始化測試庫環境

#創建表
mysql -uroot -p -h 172.26.151.78 -D tpcc < /usr/local/tpcc-mysql-master/create_table.sql
#創建FK和索引
mysql -uroot -p -h 172.26.151.78 -D tpcc < /usr/local/tpcc-mysql-master/add_fkey_idx.sql

3、加載測試數據

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個。

執行下面的命令,開始灌入測試數據:

 tpcc_load -h 172.26.151.78 -P 3306 -d tpcc -u tpcc -p tpcc@1234 -w 5

在這裡,需要注意的是 tpcc 默認會讀取 /var/lib/mysql/mysql.sock 這個socket 文件。

ps:tpcc並行加載腳本項目連結 tpcc_load_parallel.sh,加載效率至少提升10倍以上。


三、TPCC壓測
tpcc_start 工具用於tpcc壓測,其用法如下:

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

幾個選項稍微解釋下

-w 指定倉庫數量
-c 指定並發連接數
-r 指定開始測試前進行warmup的時間,進行預熱後,測試效果更好
-l 指定測試持續時間
-i 指定生成報告間隔時長
-f 指定生成的報告文件名


實例:

tpcc_start -h 172.26.151.78 -P 3306 -d tpcc -u tpcc -p tpcc@1234 \\
-w 5 -c 16 -r 120 -l 60 -f tpcc_mysql.log >> tpcc_run_result.log 2>&1

說明:模擬5個倉庫規模,並發 16個線程進行測試,熱身時間為 120秒, 壓測時間為 60秒。

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


四、TPCC測試結果解讀

測試結果輸出如下:

***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option h with value '172.26.151.78' --主機
option P with value '3306' --埠
option d with value 'tpcc' --資料庫
option u with value 'tpcc' --用戶
option p with value 'tpcc@1234' --密碼
option w with value '5' --倉庫
option c with value '16' --並發數
option r with value '120' --數據預熱時長
option l with value '60' --壓測時長
option f with value 'tpcc_mysql.log' --輸出報告日誌文件

[server]: 172.26.151.78
[port]: 3306
[DBname]: tpcc
[user]: tpcc
[pass]: tpcc@1234
[warehouse]: 5
[connection]: 16
[rampup]: 120 (sec.)
[measure]: 60 (sec.)

RAMP-UP TIME.(120 sec.)

--預熱結束,開始進行壓測
MEASURING START.
--每10秒鐘輸出一次壓測數據
10, trx: 2743, 95%: 47.649, 99%: 60.724, max_rt: 111.180, 2744|114.260, 275|12.523, 274|110.302, 276|183.083
20, trx: 2736, 95%: 46.494, 99%: 59.893, max_rt: 84.122, 2735|91.317, 273|10.343, 273|108.566, 272|202.762
30, trx: 2806, 95%: 46.051, 99%: 57.195, max_rt: 73.239, 2804|75.634, 281|7.229, 281|88.217, 280|146.604
40, trx: 2662, 95%: 45.748, 99%: 55.111, max_rt: 77.804, 2660|111.316, 266|6.176, 266|99.176, 267|152.443
50, trx: 2729, 95%: 47.678, 99%: 61.602, max_rt: 101.055, 2736|72.949, 273|9.053, 274|101.752, 273|149.860
60, trx: 2803, 95%: 44.546, 99%: 57.694, max_rt: 75.418, 2796|92.569, 280|6.037, 279|106.101, 280|142.249

-- 第一列,第N次10秒
-- trx: 2803 - 給定間隔的New Order 的 transaction 數量
-- 95%: 44.546 - 給定間隔95%的New Order transactions的reponse time
-- max_rt: 75.418 - 最大New Order transactions的reponse time
-- 剩餘的都是別的transactions的trx和最大response time

--壓測結束
STOPPING THREADS................


[0] sc:0 lt:16480 rt:0 fl:0 avg_rt: 85.4 (5) -- New-Order,新訂單業務成功(success,簡寫sc)次數,延遲(late,簡寫lt)次數,重試(retry,簡寫rt)次數,失敗(failure,簡寫fl)次數
[1] sc:457 lt:16018 rt:0 fl:0 avg_rt: 38.9 (5) -- Payment,支付業務統計
[2] sc:1619 lt:29 rt:0 fl:0 avg_rt: 7.6 (5) -- Order-Status,訂單狀態業務統計
[3] sc:1546 lt:101 rt:0 fl:0 avg_rt: 194.9 (80) -- Delivery,發貨業務統計
[4] sc:0 lt:1648 rt:0 fl:0 avg_rt: 301.9 (20) -- Stock-Level,庫存業務統計
in 60 sec.
# sc:成功數量 lt:延遲數量 fl:失敗數量 avg_rt:平均response time

[0] sc:0 lt:16480 rt:0 fl:0
[1] sc:457 lt:16019 rt:0 fl:0
[2] sc:1619 lt:29 rt:0 fl:0
[3] sc:1546 lt:101 rt:0 fl:0
[4] sc:0 lt:1648 rt:0 fl:0

(all must be [OK])
-- 下面所有業務邏輯結果都必須為 OK 才行
[transaction percentage]
Payment: 43.47% (>=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: 0.00% [NG] * -- 下面幾個響應耗時指標部分沒通過
Payment: 2.77% [NG] *
Order-Status: 98.24% [OK]
Delivery: 93.87% [OK]
Stock-Level: 0.00% [NG] *
# 和標準比較 [OK] 合格 [NG] 不合格


16480.000 TpmC
#每分鐘事務數(該值是第一次統計結果中的新訂單事務數除以總耗時分鐘數)

覺得有用的朋友多幫忙轉發哦!後面會分享更多devops和DBA方面的內容,感興趣的朋友可以關注下~

文章來源: https://twgreatdaily.com/zh-tw/crkcdm4BMH2_cNUg_FVo.html