TPCC業界通用的壓測工具,主要是壓資料庫性能。
首先安裝tpcc
官網位址:https://github.com/Percona-Lab/tpcc-mysql
[[email protected] src]# unzip tpcc-mysql-master.zip
[[email protected] src]# mv tpcc-mysql-master /usr/local/src/
[[email protected] local]# cd tpcc-mysql-master/
[[email protected] tpcc-mysql-master]# ls
add_fkey_idx.sql count.sql create_table.sql Dockerfile drop_cons.sql load_multi_schema.sh load.sh README.md schema2 scripts src
[[email protected] tpcc-mysql-master]# cd src/
[[email protected] src]# make #沒有make install
[[email protected] src]# cd ..
[[email protected] tpcc-mysql-master]# ls
add_fkey_idx.sql count.sql create_table.sql Dockerfile drop_cons.sql load_multi_schema.sh load.sh README.md schema2 scripts src tpcc_load tpcc_start
#編譯之後生成了tpcc_load和tpcc_start指令
在進行測試之前,需要導入tpcc的資料。
建立資料庫,然後導入tpcc的建表語句:
mysql> create database tpcc_test;
Query OK, 1 row affected (0.06 sec)
mysql> use tpcc_test;
Database changed
mysql> source /usr/local/tpcc-mysql-master/create_table.sql;
Query OK, 0 rows affected (0.00 sec)
......
mysql> show tables;
+---------------------+
| Tables_in_tpcc_test |
+---------------------+
| customer |
| district |
| history |
| item |
| new_orders |
| order_line |
| orders |
| stock |
| warehouse |
+---------------------+
9 rows in set (0.00 sec)
tpcc建立了九張表:
tpcc-mysql的業務邏輯及其相關的幾個表作用如下:
New-Order:新訂單,一次完整的訂單事務,幾乎涉及到全部表
Payment:支付,主要對應 orders、history 表
Order-Status:訂單狀态,主要對應 orders、order_line 表
Delivery:發貨,主要對應 order_line 表
Stock-Level:庫存,主要對應 stock 表
其他說明:
客戶:主要對應 customer 表
地區:主要對應 district 表
商品:主要對應 item 表
倉庫:主要對應 warehouse 表
首先加載資料:
./tpcc_load -h 10.0.102.214 -P 3306 -d tpcc_test -u root -p 123456 -w 10
#這個過程有點慢 ,1個warehouse對應10個地區,1地區對應3000的使用者
mysql> select count(*) from warehouse;
+----------+
| count(*) |
+----------+
| 10 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*) from district;
+----------+
| count(*) |
+----------+
| 100 |
+----------+
1 row in set (0.00 sec)
mysql> select count(*) from customer;
+----------+
| count(*) |
+----------+
| 300000 |
+----------+
1 row in set (0.11 sec)
資料插入成功之後,然後添加索引【注意一定要先插入資料再添加索引,若先建立索引,則資料插入的會更慢】
mysql> source /usr/local/tpcc-mysql-master/add_fkey_idx.sql;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (2.63 sec)
Records: 0 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.98 sec)
Records: 0 Duplicates: 0 Warnings: 0
......
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.00 sec)
各個表的結構關系如圖(使用MySQL workbench自動生成的er圖)
資料插入,索引建立之後,開始測試資料。
[[email protected] tpcc-mysql-master]# ./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 指定生成的報告檔案名
真實測試場景中,建議預熱時間不小于5分鐘,持續壓測時長不小于30分鐘,否則測試資料可能不具參考意義。
[[email protected] tpcc-mysql-master]# ./tpcc_start -h 10.0.102.214 -P 3306 -d tpcc_test -u root -p 123456 -w 10 -c 128 -r 120 -l 200
***************************************
*** ###easy### TPC-C Load Generator ***
***************************************
option h with value '10.0.102.214'
option P with value '3306'
option d with value 'tpcc_test'
option u with value 'root'
option p with value '123456'
option w with value '10'
option c with value '128'
option r with value '120'
option l with value '200'
<Parameters>
[server]: 10.0.102.214
[port]: 3306
[DBname]: tpcc_test
[user]: root
[pass]: 123456
[warehouse]: 10
[connection]: 128
[rampup]: 120 (sec.)
[measure]: 200 (sec.)
RAMP-UP TIME.(120 sec.) #預熱結束
MEASURING START.
10, trx: 2175, 95%: 201.680, 99%: 381.106, max_rt: 1619.119, 2156|3724.232, 217|229.157, 216|3278.305, 221|1335.471
20, trx: 2299, 95%: 157.736, 99%: 235.577, max_rt: 1499.332, 2303|3527.383, 229|44.633, 232|2130.182, 224|343.886
30, trx: 2484, 95%: 166.968, 99%: 221.357, max_rt: 398.790, 2505|1928.303, 250|66.903, 248|586.503, 246|374.860
40, trx: 2429, 95%: 172.350, 99%: 256.941, max_rt: 392.431, 2416|2335.130, 242|75.140, 239|779.635, 246|403.248
50, trx: 2510, 95%: 184.524, 99%: 251.689, max_rt: 336.677, 2498|1205.047, 251|35.061, 255|678.351, 252|413.731
60, trx: 2170, 95%: 184.358, 99%: 828.455, max_rt: 1187.092, 2175|2113.244, 217|62.069, 218|1613.712, 219|337.856
70, trx: 2539, 95%: 175.632, 99%: 233.821, max_rt: 372.486, 2539|1720.610, 253|69.966, 252|624.549, 253|397.743
80, trx: 2388, 95%: 177.588, 99%: 275.997, max_rt: 717.325, 2393|1750.563, 240|50.437, 240|1046.998, 239|332.516
90, trx: 2391, 95%: 190.074, 99%: 244.413, max_rt: 404.727, 2394|1602.446, 238|68.237, 238|812.026, 241|393.183
100, trx: 2458, 95%: 190.017, 99%: 291.625, max_rt: 483.963, 2450|1657.739, 247|59.142, 244|771.332, 244|404.857
110, trx: 2507, 95%: 166.070, 99%: 222.753, max_rt: 321.543, 2506|1610.591, 251|80.395, 252|650.804, 253|394.323
120, trx: 2130, 95%: 187.812, 99%: 552.392, max_rt: 817.886, 2145|2443.558, 213|37.962, 213|1586.296, 206|406.044
130, trx: 2488, 95%: 170.299, 99%: 212.399, max_rt: 290.578, 2471|1787.442, 249|58.585, 254|601.749, 256|379.250
140, trx: 2575, 95%: 178.600, 99%: 236.850, max_rt: 383.657, 2587|1550.100, 257|75.059, 253|633.108, 250|471.181
150, trx: 2441, 95%: 185.133, 99%: 308.322, max_rt: 479.655, 2447|1691.942, 244|38.844, 246|802.569, 248|449.930
160, trx: 2521, 95%: 172.660, 99%: 216.249, max_rt: 302.257, 2519|1521.757, 253|62.614, 252|675.931, 249|435.944
170, trx: 2512, 95%: 164.290, 99%: 225.504, max_rt: 1306.804, 2505|1745.858, 251|57.538, 248|610.941, 258|530.579
180, trx: 2181, 95%: 180.914, 99%: 251.463, max_rt: 1415.735, 2183|2489.273, 217|30.965, 221|1915.949, 214|428.293
190, trx: 2398, 95%: 197.262, 99%: 399.086, max_rt: 556.640, 2409|1319.926, 241|57.555, 238|977.416, 240|491.435
200, trx: 2470, 95%: 177.428, 99%: 217.612, max_rt: 341.156, 2448|1357.371, 245|76.254, 248|655.950, 246|457.847
STOPPING THREADS................................................................................................................................
<Raw Results>
[0] sc:0 lt:48066 rt:0 fl:0 avg_rt: 148.6 (5)
[1] sc:1 lt:48049 rt:0 fl:0 avg_rt: 604.9 (5)
[2] sc:3986 lt:819 rt:0 fl:0 avg_rt: 6.6 (5)
[3] sc:0 lt:4807 rt:0 fl:0 avg_rt: 683.6 (80)
[4] sc:0 lt:4805 rt:0 fl:0 avg_rt: 272.2 (20)
in 200 sec.
<Raw Results2(sum ver.)>
[0] sc:0 lt:48066 rt:0 fl:0
[1] sc:1 lt:48054 rt:0 fl:0
[2] sc:3986 lt:819 rt:0 fl:0
[3] sc:0 lt:4807 rt:0 fl:0
[4] sc:0 lt:4805 rt:0 fl:0
<Constraint Check> (all must be [OK])
[transaction percentage]
Payment: 43.47% (>=43.0%) [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)]
New-Order: 0.00% [NG] *
Payment: 0.00% [NG] *
Order-Status: 82.96% [NG] *
Delivery: 0.00% [NG] *
Stock-Level: 0.00% [NG] *
<TpmC>
14419.800 TpmC
[[email protected] tpcc-mysql-master]#
轉載至https://www.cnblogs.com/wxzhe/p/10027474.html