1、源碼編譯安裝
源碼下載地址(目前有0.4/0.5/1.0三個分支版本):https://github.com/akopytov/sysbench
編譯安裝:
unzip sysbench-1.0.zip //進入目錄,配置編譯安裝 ./autogen.sh ./configure --with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/ --prefix=/usr/local/sysbench/v1.0 make make install //配置環境變量 //...
可能遇到的問題:
編譯安裝完成以后,執行sysbench命令,會報如下錯誤:
sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
問題原因,沒有正確配置環境變量LD_LIBRARY_PATH,執行如下命令(我的MySQL采用源碼安裝方式,目錄在/usr/local/mysql,所以頭文件與庫文件都在該目錄下):
export LD_LIBRARY_PATH=/usr/local/mysql/lib/
2、執行sysbench命令,打印出幫助信息如下:
Missing required command argument.
Usage:
sysbench --test=<test-name> [options]... <command>
Commands: prepare run cleanup help version //Usage中的<command>部分,分別表示“准備”、“運行”、“清理”、“幫助”、“版本”
General options: //通用選項,用於設置線程數量,請求數目等多種測試屬性
--num-threads=N number of threads to use [1]
--max-requests=N limit for total number of requests [10000]
//略...
General database options: //通用的數據庫選項,sysbench支持MySQL、Oracle等多種數據庫測試
--db-driver=STRING specifies database driver to use ('help' to get list of available drivers) 指定測試用的數據庫驅動
--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
--db-debug=[on|off] print database-specific debug information [off] 數據庫調試信息是否打開
Compiled-in database drivers: //內建的數據庫驅動,對於MySQL數據庫測試直接使用內建驅動就可以了
mysql - MySQL driver
mysql options: //針對MySQL數據庫測試的一些選項
--mysql-host=[LIST,...] MySQL server host [localhost] 主機IP地址
--mysql-port=[LIST,...] MySQL server port [3306] 主機端口號
--mysql-socket=[LIST,...] MySQL socket 采用的socket
--mysql-user=STRING MySQL user [sbtest] 用戶名
--mysql-password=STRING MySQL password [] 密碼
--mysql-db=STRING MySQL database name [sbtest] 測試目標數據庫
//略...
Compiled-in tests: //內建的測試類型,如下5中測試直接在“--test=...”后面指定就可以了,如果內建測試不能滿足需求可以采用lua腳本自定義測試
fileio - File I/O test IO性能測試
cpu - CPU performance test CPU性能測試
memory - Memory functions speed test 內存連續讀寫性能測試
threads - Threads subsystem performance test 線程調度器性能測試
mutex - Mutex performance test 互斥鎖性能測試
3、內建測試1:fileio測試
①、准備測試數據集,使用prepare命令
[lj95801@localhost sysbench]$ sysbench --test=fileio --file-total-size=5G prepare
--test=fileio 表示測試類型為內建的fileio測試
--test-total-size=5G 表示准備測試數據集為50G大小
prepare 命令准備測試數據集
輸出結果如下:
sysbench 1.0: multi-threaded system evaluation benchmark
128 files, 40960Kb each, 5120Mb total
Creating files for the test...
Extra file open flags: 0
Creating file test_file.0
Creating file test_file.1
Creating file test_file.2
//...
從打印可以看出,程序會自動生成128個文件,每個文件4MB大小。
②、使用help命令,查看fileio測試的幫助文檔:
[luojun@localhost sysbench]$ sysbench --test=fileio help
sysbench 1.0: multi-threaded system evaluation benchmark
fileio options: //可用的選項
--file-num=N number of files to create [128] //文件數量
--file-block-size=N block size to use in all IO operations [16384] //文件塊大小設定
--file-total-size=SIZE total size of files to create [2G] //文件總大小
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw} //測試模式
--file-io-mode=STRING file operations mode {sync,async,mmap} [sync] //io模式,“同步”、“異步”
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100] //fsync()方法調用頻率
--file-fsync-all=[on|off] do fsync() after each write operation [off] //每一次寫操作都進行fsync()同步,默認為off
--file-fsync-end=[on|off] do fsync() at the end of test [on] //在測試結束之前調用fsync()同步方法
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]
--file-rw-ratio=N reads/writes ratio for combined test [1.5] //讀寫比率設定
有一個重要的測試選項:--file-test-mode=STRING。其可用的選項為:
seqwr:順序寫
seqrewr:順序重寫
seqrd:順序讀
rndrd:隨機讀取
rndwr:隨機寫入
rndrw:混合隨機讀/寫
③、作混合隨機讀寫測試:
[luojun@localhost sysbench]$ sysbench --test=fileio --file-test-mode=rndrw --file-total-size=5G --file-rw-ratio=2 run
選項解釋:
--test-fileio:測試類型為IO測試
--file-total-size=5G:測試文件總大小為5G
--file-test-mode=rndrw:文件IO測試模式為隨機混合讀寫方式
--file-rw-ratio=2:讀寫次數比率為2
④、分析打印結果
sysbench 1.0: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 1 //測試線程數 Initializing random number generator from current time //測試屬性設定,可以通過選項控制 Extra file open flags: 0 128 files, 40MiB each 5GiB total file size Block size 16KiB Number of IO requests: 10000 Read/Write ratio for combined random IO test: 2.00 Periodic FSYNC enabled, calling fsync() each 100 requests. Calling fsync() at the end of test, Enabled. Using synchronous I/O mode Doing random r/w test Initializing worker threads... Threads started! //測試過程中文件操作情況 File operations: reads/s: 95.45 //每秒鍾讀請求數 writes/s: 47.72 //每秒鍾寫請求數 fsyncs/s: 183.25 //沒表中同步次數 //吞吐率 Throughput: read, MiB/s: 1.49 //讀,1.49MB每秒 written, MiB/s: 0.75 //寫,0.75MB每秒 //統計數據 General statistics: total time: 69.8488s //測試總時長 total number of events: 10000 //事件數量 total time taken by event execution: 39.6674s //事件執行事件 response time: //事件響應事件統計 min: 0.02ms //最短 avg: 3.97ms //平均 max: 27.70ms //最長 approx. 95 percentile: 11.77ms //95%以上事件響應時長 Threads fairness: //線程公平性統計信息 events (avg/stddev): 10000.0000/0.00 execution time (avg/stddev): 39.6674/0.00
與文件IO性能評價密切相關的指標有:每秒鍾請求數、吞吐量、95%以上事件響應時間。
⑤、清除測試數據集
[luojun@localhost sysbench]$ sysbench --test=fileio --file-total-size=5G cleanup
參考文章:
http://beagoodboy.iteye.com/blog/1280907
《高性能MySQL》第三版
