前面知道sysbench基准測試的主要步驟為:prepare(准備數據集)→ run(運行測試)→ cleanup(清除數據集)
這一節介紹oltp.lua測試。
oltp基准測試模擬了一個簡單的事物處理系統的工作負載。
①、准備數據集(使用test數據庫,用戶名root,密碼123456,表數目8,每張表記錄10萬,測試oltp.lua):
[root@localhost db]# sysbench --test=oltp.lua --mysql-db=test --mysql-user=root --mysql-password=123456 --oltp-tables-count=8 --oltp-table-size=100000 prepare
對選項作如下說明:
--test=oltp.lua //測試用的lua腳本,可以使用絕對路徑。該腳本位於sysbench源碼包的“sysbench-1.0/sysbench/tests/db/”文件夾下面。當然,你也可以自己寫lua腳本。
--mysql-db=test //測試數據庫
--mysql-user=root //用戶名
--myssql-password=123456 //密碼
--oltp-tables-count=8 //數據表
--oltp-table-size=100000 //每張表記錄為10萬
執行結果是:在test數據庫中創建8張表,表名分別為“sbtest1...8”,每張表中有記錄10萬條。
②、執行oltp基礎測試(線程數10,最大執行時間60s,只讀off,打印信息間隔10s):
[root@localhost db]# sysbench --test=oltp.lua --mysql-db=test --mysql-user=root --mysql-password=123456 \
--oltp-tables-count=8 --oltp-table-size=100000 --num-threads=10 --max-time=60 --report-interval=10 --oltp-read-only=off run
對選項作如下說明:
--num-threads=10 //線程數為10
--max-time=60 //測試時間為60s
--report-interval=10 //報告打印周期為10s
--oltp-read-only=off //非只讀操作測試
運行結果如下:
sysbench 1.0: multi-threaded system evaluation benchmark
Running the test with following options: //測試屬性,可以通過選項設定
Number of threads: 10
Report intermediate results every 10 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
//每10秒鍾報告一次測試結果,tps、每秒讀、每秒寫、99%以上的響應時長統計
[ 10s] threads: 10, tps: 81.24, reads: 1149.41, writes: 325.75, response time: 280.29ms (95%), errors: 0.00, reconnects: 0.00
[ 20s] threads: 10, tps: 72.20, reads: 1012.70, writes: 292.00, response time: 318.42ms (95%), errors: 0.00, reconnects: 0.00
[ 30s] threads: 10, tps: 79.40, reads: 1111.60, writes: 317.60, response time: 284.35ms (95%), errors: 0.00, reconnects: 0.00
[ 40s] threads: 10, tps: 74.00, reads: 1034.59, writes: 295.60, response time: 350.64ms (95%), errors: 0.00, reconnects: 0.00
[ 50s] threads: 10, tps: 80.90, reads: 1127.81, writes: 320.90, response time: 309.40ms (95%), errors: 0.10, reconnects: 0.00
[ 60s] threads: 10, tps: 79.90, reads: 1126.20, writes: 322.80, response time: 309.03ms (95%), errors: 0.00, reconnects: 0.00
OLTP test statistics:
queries performed: //性能統計
read: 65632 //讀總數,select語句
write: 18749 //寫總數,insert、delete、update語句
other: 9375 //其它語句,如commit等
total: 93756 //總的執行語句數
transactions: 4687 (78.06 per sec.) //總的事物數(每秒處理事物數)
read/write requests: 84381 (1405.28 per sec.) //讀寫請求次數(每秒的讀寫次數)
other operations: 9375 (156.13 per sec.) //其它操作的每秒執行數
ignored errors: 1 (0.02 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.0456s //總時間
total number of events: 4687 //事物總數
total time taken by event execution: 600.0783s //所有事務耗時相加(不考慮並行因素)
response time: //應答時間
min: 31.96ms //最小
avg: 128.03ms //平均
max: 690.49ms //最大
approx. 95 percentile: 317.65ms //95%語句執行時間
Threads fairness: //線程公平性
events (avg/stddev): 468.7000/5.04
execution time (avg/stddev): 60.0078/0.01
最重要的參數指標:
總的事物數,每秒事務數,時間統計信息(最大、最小、平均、95%以上語句響應時間)
③、刪除測試數據集
[root@localhost db]# sysbench --test=oltp.lua --mysql-db=test --mysql-user=root --mysql-password=123456 --oltp-tables-count=8 --oltp-table-size=100000 cleanup
后續:
這里的測試使用的是sysbench自帶的oltp.lua腳本。也可以寫自己的lua腳本來做相關測試。呃,可是lua不會...