轉載:http://www.unixfbi.com/522.html
一、sysbench 介紹
sysbench 是一個模塊化、支持多平台安裝運行,多線程的基准測試工具,sysbench,不僅用來測試數據庫的性能,也可以測試運行數據庫的服務器的性能。
sysbench,不僅用來測試數據庫的性能,也可以測試運行數據庫的服務器的性能。
oltp 測試主要是結合了 lua 腳本,不需要修改源碼,通過自定義 lua 腳本就可以實現不同業務類型的測試。
主要有以下幾種方式的測試:
cpu 基准測試
磁盤 I/O 基准測試
內存連續讀寫性能測試
測試互斥鎖性能
測試順序讀寫性能
數據庫性能 OLTP 基准測試
什么是 OLTP?
On-Line Transaction Processing 聯機事務處理過程(OLTP)
也稱為面向交易的處理過程,其基本特征是前台接收的用戶數據可以立即傳送到計算中心進行處理,並在很短的時間內給出處理結果,是對用戶操作快速響應的方式之一。
二、sysbench 安裝和部分參數介紹
1.安裝 sysbench
在 centos7 上
# curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash sudo yum -y install sysbench
2.sysbench 參數介紹
$ sysbench --help Usage: sysbench [options]... [testname] [command] Commands implemented by most tests: prepare run cleanup help sysbench 壓測需要 3 個步驟: prepare(准備數據) -> run(運行測試) -> cleanup(清理數據) General options: --threads=N #創建測試線程的數量,默認值為 1 --events=N #限制事件的總數量,0 表示不限制,默認值為 0 --time=N #限制總共執行多長時間,單位是秒,默認是 10 --forced-shutdown=STRING #超過--time 后,等待多長時間強制關閉,單位是秒,默認 off --thread-stack-size=SIZE #每個線程的堆大小,默認是 64k --rate=N #平均事務率,0 表示不限制 --report-interval=N #定期報告統計數據的時間間隔,單位秒,默認為 0,表示不顯示中間報告。 --report-checkpoints=[LIST,...] #轉儲完整的統計信息並在指定的時間點重置所有計數器。默認為關閉 --config-file=FILENAME #可以把命令參數寫到一個文件中,指定這個文件 --tx-rate=N #該參數棄用,改為 --rate [0] --max-requests=N #該參數棄用,改為--events [0] --max-time=N #該參數棄用,改為 --time [0] --num-threads=N #該參數棄用,改為 --threads [1] mysql options: --mysql-host=[LIST,...] # MySQL 服務器地址 ,默認 localhost --mysql-port=[LIST,...] # MySQL 服務器端口 ,默認 3306 --mysql-socket=[LIST,...] # MySQL socket 文件 --mysql-user=STRING MySQL user 默認 sbtest --mysql-password=STRING MySQL password 默認為空 --mysql-db=STRING MySQL database name 默認 sbtest --mysql-compression[=on|off] #是否使用壓縮,默認為 off Compiled-in tests: fileio - File I/O test cpu - CPU performance test memory - Memory functions speed test threads - Threads subsystem performance test mutex - Mutex performance test
三、sysbench 使用說明
sysbench 壓測 MySQL 有三個步驟:prepare --> run --> cleanup
我們都是使用 sysbench 自帶的 lua 腳本來壓測 MySQL
1.壓測 MySQL
使用 oltp_read_write.lua 腳本壓測 MySQL
准備階段:
mysql -uroot -pllill2018 -e "create database sbtest;" -S /tmp/mysql3308.sock sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=172.16.17.123 --mysql-port=3308 --mysql-user=root --mysql-password='llill2018' --mysql-socket=/tmp/mysql3308.sock --mysql-db=sbtest --db-driver=mysql --tables=20 --table-size=5000000 --threads=32 prepare
測試階段:
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=172.16.17.123 --mysql-port=3308 --mysql-user=root --mysql-password='llill2018' --mysql-socket=/tmp/mysql3308.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=10000 --threads=32 --report-interval=10 --time=120 run
輸出結果如下:
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 32 Report intermediate results every 10 second(s) Initializing random number generator from current time Initializing worker threads... Threads started! [ 10s ] thds: 32 tps: 266.21 qps: 5355.17 (r/w/o: 3753.19/1066.56/535.43) lat (ms,95%): 186.54 err/s: 0.00 reconn/s: 0.00 [ 20s ] thds: 32 tps: 279.40 qps: 5590.16 (r/w/o: 3914.18/1116.99/559.00) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 30s ] thds: 32 tps: 273.60 qps: 5470.54 (r/w/o: 3829.26/1094.09/547.19) lat (ms,95%): 144.97 err/s: 0.00 reconn/s: 0.00 [ 40s ] thds: 32 tps: 258.20 qps: 5169.85 (r/w/o: 3620.43/1033.01/516.40) lat (ms,95%): 248.83 err/s: 0.00 reconn/s: 0.00 [ 50s ] thds: 32 tps: 281.80 qps: 5627.48 (r/w/o: 3936.89/1127.20/563.40) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 60s ] thds: 32 tps: 279.50 qps: 5595.15 (r/w/o: 3917.53/1118.41/559.20) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 70s ] thds: 32 tps: 278.30 qps: 5565.72 (r/w/o: 3895.85/1113.38/556.49) lat (ms,95%): 132.49 err/s: 0.00 reconn/s: 0.00 [ 80s ] thds: 32 tps: 262.40 qps: 5254.69 (r/w