sysbench是一個模組化的、跨平台、多線程基準測試載入器,主要用於評估測試各種不同系統參數下的資料庫負載情況。關於這個項目的詳細介紹請看:http://sysbench.sourceforge.net。
它主要包括以下幾種方式的測試:
1、cpu效能
2、磁碟io效能
3、發送器效能
4、記憶體配置及傳輸速度
5、POSIX線程效能
6、資料庫效能(OLTP基準測試)
目前sysbench主要支援 MySQL,pgsql,oracle 這3種資料庫。
一、安裝
首先,在 http://sourceforge.net/projects/sysbench 下載源碼包
但安裝過程一波三折,各種不順
安裝不走如下;
tar zxf sysbench-0.4.12.tar.gz
cd sysbench-0.4.12
./autogen.sh
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install
Server terminated with error (1). Closing log file.
../libtool: line 2415: Xsysbench: command not found
../libtool: line 2550: X-lmysqlclient_r: command not found
../libtool: line 2550: X-lrt: command not found
../libtool: line 2550: X-lm: command not found
../libtool: line 2632: X-L/root/sysbench-0.4.12/sysbench: No such file or directory
../libtool: line 2550: X-lmysqlclient_r: command not found
../libtool: line 2550: X-lrt: command not found
../libtool: line 2550: X-lm: command not found
../libtool: line 2632: X-L/root/sysbench-0.4.12/sysbench: No such file or directory
../libtool: line 2550: X-lmysqlclient_r: command not found
../libtool: line 2550: X-lrt: command not found
../libtool: line 2550: X-lm: command not found
報錯了,各種搜尋後
表示libtool版本低
cp /usr/bin/libtool /path/to/sysbench_source/
即拷貝系統的libtool到sysbench的源碼目錄下即可解決以上問題
另外,如果想要讓 sysbench 支援 pgsql/oracle 的話,就需要在編譯的時候加上參數
--with-pgsql
或者
--with-oracle
這2個參數預設是關閉的,只有 MySQL 是預設支援的。
[root@zgqiang sysbench-0.4.12]# cp /usr/bin/libtool .
cp:是否覆蓋"./libtool"。 y
[root@zgqiang sysbench-0.4.12]# make && make install
正確編譯通過
[root@zgqiang sysbench-0.4.12]# sysbench
sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[root@zgqiang sysbench-0.4.12]# vim /etc/profile #使用該指令碼設定LD_LIBRARY_PATH來解決sysbench找不到mysql的lib的問題 export LD_LIBRARY_PATH=/usr/local/mysql/lib
[root@zgqiang sysbench-0.4.12]# source /etc/profile
[root@zgqiang sysbench-0.4.12]# sysbench
Missing required command argument.
Usage:
sysbench [general-options]... --test=<test-name> [test-options]... command
General options:
--num-threads=N number of threads to use [1]
--max-requests=N limit for total number of requests [10000]
--max-time=N limit for total execution time in seconds [0]
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]
--thread-stack-size=SIZE size of stack per thread [32K]
--init-rng=[on|off] initialize random number generator [off]
--test=STRING test to run
--debug=[on|off] print more debugging info [off]
--validate=[on|off] perform validation checks where possible [off]
--help=[on|off] print help and exit
--version=[on|off] print version and exit
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
oltp - OLTP test
Commands: prepare run cleanup help version
See 'sysbench --test=<name> help' for a list of options for each test.
運行正常了
進行測試
編譯安裝成功後就可以開始進行效能測試了。測試的方法和選項很多,這裡大致介紹一下相關的命令和選項。
CPU效能測試
sysbench --test=cpu --cpu-max-prime=5000 run
CPU的效能測試主要通過素數的運算來進行,--cpu-max-prime用來選項指定最大的素數,具體參數可以根據CPU的效能來設定。
記憶體效能測試
sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run
--memory-block-size指定每個block的大小,--memory-total-size指定總的傳輸量,另外還有其他選項,可通過命令sysbench –test=memory help進行查看。
磁碟I/O效能測試
首先產生需要測試的檔案
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 prepare
然後執行測試
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 run
最後清理測試檔案
sysbench --test=fileio --num-threads=16 --file-num=2 --file-total-size=2G --file-test-mode=rndrw --file-rw-ratio=2 cleanup
--num-threads指定最大建立的線程數,--file-num指定檔案數目,--file-taotal-size指定建立的檔案總大小,--file-test-mode指定檔案讀寫入模式,rndrw為隨機讀,--file-rw-ratio指定讀寫比率。另外還有更多的選項可以通過命令sysbench –test=fileio help進行查看。
線程測試
sysbench --test=threads --num-threads=32 --thread-yields=100 --thread-locks=2 run
--num-threads指定線程數,--thread-yield指定每個請求的壓力,--thread-locks指定每個線程的鎖數量。
資料庫效能測試
首先,準備測試資料
sysbench --test=oltp --mysql-host=server1 --mysql-user=root --mysql-password=MySQLPASSWORD --mysql-db=test --oltp-table-name=sbtest --mysql-table-engine=MyISAM --oltp-table-size=1000000 prepare
然後執行測試
sysbench --test=oltp --mysql-host=server1 --mysql-port=3306 --mysql-user=root --mysql-password=MySQLPASSWORD --mysql-db=test --oltp-table-name=sbtest --mysql-table-engine=MyISAM --mysql-engine-trx=no --oltp-skip-trx=on --oltp-table-size=1000000 --max-requests=1000 --num-threads=100 run
最後清理測試資料
sysbench --test=oltp --mysql-host=server1 --mysql-user=root --mysql-password=MySQLPASSWORD --mysql-db=test --oltp-table-name=sbtest cleanup
--mysql-host指定使用的MySQL伺服器的地址,--mysql-user指定串連MySQL的使用者名稱,--mysql-password指定密碼,--mysql-db指定使用的資料庫,--oltp-table-name指定使用的表,--mysql-table-engine指定表所使用的資料庫引擎,--mysql-engine-trx說明使用的資料庫引擎是否是事務的,--oltp-skip-trx指定是否忽略事務語句(BEGIN/COMMIT),--oltp-table-size指定資料表中的記錄數,--max-requests指定最大請求數,--num-threads指定線程數,其他更多的選項可以使用命令sysbench –test=oltp help查看。