您好,登錄后才能下訂單哦!
sysbench是一款壓力測試工具,可以測試系統的硬件性能,也可以用來對數據庫進行基準測試。
安裝方式:https://github.com/akopytov/sysbench/blob/master/README.md#general-command-line-options
此處安裝的是sysbench 1.0.6版本,和網上大部分的0.4,0.5版本的命令不太一樣。
sysbench支持三種測試方案:
1、使用自帶的測試模塊,如對cpu,I/O,memory等的測試。
2、使用自帶的lua腳本進行測試,如果使用快速安裝的方式,默認的腳本路徑為:/usr/share/sysbench
3、使用自定義的lua腳本。
獲取幫助信息:
如果對相關模塊或者腳本的參數不明確的,可以使用 sysbench testname help來查看,testname含模塊名稱和腳本名稱。
sysbench經典測試命令:
prepare
: 創建測試數據或者相關的測試文件,為測試做準備工作。如數據庫的測試數據準備等。
run
: 開始執行測試。
cleanup
: 移除測試數據
help
: 幫助命令
測試CPU性能
sysbench cpu --cpu-max-prime=10000 run #顯示測試結果 General statistics: total time: 10.0003s total number of events: 8692 Latency (ms): min: 1.12 avg: 1.15 max: 2.98 95th percentile: 1.25 sum: 9996.64 Threads fairness: events (avg/stddev): 8692.0000/0.00 execution time (avg/stddev): 9.9966/0.00
I/O測試
準備測試數據:
sysbench fileio --file-total-size=40G prepare
運行順序寫入測試:
sysbench fileio --file-total-size=40G --file-test-mode=seqwr run #測試結果 File operations: reads/s: 0.00 writes/s: 3916.87 fsyncs/s: 5001.01 Throughput: read, MiB/s: 0.00 written, MiB/s: 61.20 General statistics: total time: 10.0055s total number of events: 89250 Latency (ms): min: 0.01 avg: 0.11 max: 28.02 95th percentile: 0.12 sum: 9937.24 Threads fairness: events (avg/stddev): 89250.0000/0.00 execution time (avg/stddev): 9.9372/0.00
運行順序重寫測試:
sysbench fileio --file-total-size=40G --file-test-mode=seqrewr run #測試結果: File operations: reads/s: 0.00 writes/s: 4018.65 fsyncs/s: 5131.38 Throughput: read, MiB/s: 0.00 written, MiB/s: 62.79 General statistics: total time: 10.0003s total number of events: 91531 Latency (ms): min: 0.00 avg: 0.11 max: 31.45 95th percentile: 0.10 sum: 9933.80 Threads fairness: events (avg/stddev): 91531.0000/0.00 execution time (avg/stddev): 9.9338/0.00
混合隨機讀/寫:(如果執行出錯,需要重新prepare數據)
sysbench fileio --file-total-size=40G --file-test-mode=rndrw --max-time=100 --max-requests=0 run #測試結果: File operations: reads/s: 338.98 writes/s: 225.99 fsyncs/s: 722.23 Throughput: read, MiB/s: 5.30 written, MiB/s: 3.53 General statistics: total time: 100.0007s total number of events: 128727 Latency (ms): min: 0.00 avg: 0.78 max: 43.01 95th percentile: 2.97 sum: 99785.92 Threads fairness: events (avg/stddev): 128727.0000/0.00 execution time (avg/stddev): 99.7859/0.00
清除測試數據:
sysbench fileio --file-total-size=40G cleanup
OLTP基準測試
OLTP基準測試模擬了一個簡單的事務處理系統的工作負載。若要對數據庫性能進行測試就要使用OLTP相關的腳本。
在/usr/share/sysbench/目錄下有相關的lua腳本:
bulk_insert.lua oltp_common.lua oltp_delete.lua oltp_insert.lua oltp_point_select.lua oltp_read_only.lua oltp_read_write.lua oltp_update_index.lua oltp_update_non_index.lua oltp_write_only.lua select_random_points.lua select_random_ranges.lua
對于未知的測試參數,可以通過 sysbench scripts-name help 來查看。
創建測試數據:
sysbench oltp_common --table-size=1000000 --db-driver=mysql \ --mysql-db=test --mysql-user=root --mysql-password=123456 prepare Creating table 'sbtest1'... Inserting 1000000 records into 'sbtest1' Creating a secondary index on 'sbtest1'...
執行run命令進行測試:(只讀)
sysbench oltp_read_only --table-size=1000000 --db-driver=mysql \ --mysql-db=test --mysql-user=root --mysql-password=123456 --time=60 --max-requests=0 --threads=8 run #測試結果 Running the test with following options: Number of threads: 8 Initializing random number generator from current time Initializing worker threads... Threads started! SQL statistics: queries performed: read: 1679174 write: 0 other: 239882 total: 1919056 transactions: 119941 (1998.81 per sec.) queries: 1919056 (31980.95 per sec.) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) General statistics: total time: 60.0047s total number of events: 119941 Latency (ms): min: 0.32 avg: 4.00 max: 56.17 95th percentile: 8.13 sum: 479830.78 Threads fairness: events (avg/stddev): 14992.6250/116.75 execution time (avg/stddev): 59.9788/0.00
除了使用read_only測試,我們還可以測試數據庫的寫性能:
sysbench oltp_write_only --table-size=1000000 --db-driver=mysql \ --mysql-db=test --mysql-user=root --mysql-password=123456 --time=60 --max-requests=0 --threads=8 run #測試結果 SQL statistics: queries performed: read: 0 write: 83764 other: 41882 total: 125646 transactions: 20941 (348.93 per sec.) queries: 125646 (2093.56 per sec.) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) General statistics: total time: 60.0120s total number of events: 20941 Latency (ms): min: 4.92 avg: 22.92 max: 5518.27 95th percentile: 69.29 sum: 479968.99 Threads fairness: events (avg/stddev): 2617.6250/17.87 execution time (avg/stddev): 59.9961/0.00
上面的結果中包含了很多的信息,其中重點需要我們關注的信息是:
1、總的事務數 (total number of events)
2、每秒事務數
3、時間統計信息(最小,平均,最大響應時間,以及95%百分比響應時間)
4、線程公平性統計信息,表示負載的公平性。(thread-fairness)
清理測試數據:
sysbench oltp_read_only --table-size=1000000 --db-driver=mysql \ --mysql-db=test --mysql-user=root --mysql-password=123456 cleanup
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。