sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,能夠用來進行CPU、內存、磁盤I/O、線程、數據庫的性能測試。目前支持的數據庫有MySQL、Oracle和PostgreSQL。如下操做都將以支持MySQL數據庫爲例進行。
Sysbench的測試主要包括如下幾個方面:
一、磁盤io性能
二、cpu性能
三、內存分配及傳輸速度
四、POSIX線程性能
五、調度程序性能
六、數據庫性能(OLTP基準測試).html
2、基準測試的指標mysql
常見的數據庫指標包括:linux
對MySQL的基準測試,有以下兩種思路:c++
(1)針對整個系統的基準測試:經過http請求進行測試,如經過瀏覽器、APP或postman等測試工具。該方案的優勢是可以更好的針對整個系統,測試結果更加準確;缺點是設計複雜實現困難。git
(2)只針對MySQL的基準測試:優勢和缺點與針對整個系統的測試剛好相反。github
在針對MySQL進行基準測試時,通常使用專門的工具進行,例如mysqlslap、sysbench等。其中,sysbench比mysqlslap更通用、更強大,且更適合Innodb(由於模擬了許多Innodb的IO特性),下面介紹使用sysbench進行基準測試的方法。sql
4、安裝數據庫
https://github.com/akopytov/sysbench官網數組
#git clone https://github.com/akopytov/sysbench.git瀏覽器
#autogen.sh 運行生成configure
#./configure --prefix=/root/sysbench --with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/
#make && make install
默認支持MySQL,若是須要測試Oracle/PostgreSQL,則在configure時須要加上–with-oracle或者–with-pgsql參數.
依賴庫安裝
須要安裝m4 autoconf automake libtool 這幾個包,經過 yum install m4 autoconf automake libtool
可進行安裝,不然會報錯( xxx… wasn’t found, exiting) ./autogen.sh
(若是是源碼編譯安裝就不須要執行了)
執行後在目錄下會出現configure文件夾,就說明能夠開始執行配置了。
./configure --prefix=/root/sysbench --with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/
須要指定include和lib目錄。若是沒有,說明安裝時候沒有安裝安裝開發包,這個要單獨安裝的,找Development Libraries 包.
安裝完成後執行:
[root@localhost sysbench]# ll -rth sysbench
total 236K
-rw-r--r--. 1 root root 7.1K Jun 18 04:12 sysbench.h
[root@localhost sysbench]# make
Making all in doc
make[1]: Entering directory `/root/sysbench/doc' ...... [root@localhost sysbench]# make install Making install in doc make[1]: Entering directory `/root/sysbench/doc' .....
沒有報錯的話就在當前的/root/sysbench/sysbench目錄下會生成一個二進制可執行文件:sysbench
[root@localhost sysbench]# ll
total 4096
-rw-r--r--. 1 root root 3661 Jun 18 04:12 CMakeLists.txt -rw-r--r--. 1 root root 24391 Jun 18 04:12 db_driver.c -rw-r--r--. 1 root root 9911 Jun 18 04:12 db_driver.h -rw-r--r--. 1 root root 129832 Jun 18 08:49 db_driver.o drwxr-xr-x. 7 root root 4096 Jun 18 12:50 drivers -rw-r--r--. 1 root root 25253 Jun 18 12:50 Makefile -rw-r--r--. 1 root root 2020 Jun 18 04:12 Makefile.am -rw-r--r--. 1 root root 25998 Jun 18 06:12 Makefile.in -rw-r--r--. 1 root root 3640 Jun 18 04:12 sb_list.h -rw-r--r--. 1 root root 16223 Jun 18 04:12 sb_logger.c -rw-r--r--. 1 root root 4554 Jun 18 04:12 sb_logger.h -rw-r--r--. 1 root root 116256 Jun 18 08:49 sb_logger.o -rw-r--r--. 1 root root 13731 Jun 18 04:12 sb_options.c -rw-r--r--. 1 root root 3108 Jun 18 04:12 sb_options.h -rw-r--r--. 1 root root 109536 Jun 18 08:49 sb_options.o -rw-r--r--. 1 root root 3456 Jun 18 04:12 sb_percentile.c -rw-r--r--. 1 root root 1570 Jun 18 04:12 sb_percentile.h -rw-r--r--. 1 root root 64616 Jun 18 08:49 sb_percentile.o -rw-r--r--. 1 root root 5982 Jun 18 04:12 sb_timer.c -rw-r--r--. 1 root root 3796 Jun 18 04:12 sb_timer.h -rw-r--r--. 1 root root 54544 Jun 18 08:49 sb_timer.o -rw-r--r--. 1 root root 6860 Jun 18 04:12 sb_win.c -rw-r--r--. 1 root root 2747 Jun 18 04:12 sb_win.h drwxr-xr-x. 4 root root 4096 Jun 18 12:50 scripting -rwxr-xr-x. 1 root root 3300573 Jun 18 12:24 sysbench [root@localhost sysbench]# ./sysbench --help ./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory [root@localhost sysbench]# ldd sysbench linux-vdso.so.1 => (0x00007fff3dd70000) libmysqlclient.so.18 => not found //重點在這裏,連接庫沒找到,只好手動加一下 libdl.so.2 => /lib64/libdl.so.2 (0x00007f95b0e55000) librt.so.1 => /lib64/librt.so.1 (0x00007f95b0c4d000) libm.so.6 => /lib64/libm.so.6 (0x00007f95b09c9000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f95b07ab000) libc.so.6 => /lib64/libc.so.6 (0x00007f95b0417000) /lib64/ld-linux-x86-64.so.2 (0x00007f95b1068000) [root@localhost sysbench]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib //手動創建一個軟連接 [root@localhost sysbench]# ldconfig //生效 [root@localhost sysbench]# ldd sysbench //在查看就找到ibmysqlclient.so.18 linux-vdso.so.1 => (0x00007fffc5ffc000) libmysqlclient.so.18 => /usr/lib/libmysqlclient.so.18 (0x00007fa7895d8000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fa7893d4000) librt.so.1 => /lib64/librt.so.1 (0x00007fa7891cb000) libm.so.6 => /lib64/libm.so.6 (0x00007fa788f47000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa788d2a000) libc.so.6 => /lib64/libc.so.6 (0x00007fa788995000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fa78868f000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa788479000) /lib64/ld-linux-x86-64.so.2 (0x00007fa789bb0000) [root@localhost sysbench]# ./sysbench --help //執行help成功 [root@localhost ~]# sysbench --help Missing required command argument. Usage: sysbench [general-options]... --test=<test-name> [test-options]... command General options: --num-threads=N 使用線程數 默認[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 [64K] --tx-rate=N target transaction rate (tps) [0] --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] --report-checkpoints=[LIST,...]dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. [] --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 [off] --rand-init=[on|off] initialize random number generator [off] --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special] --rand-spec-iter=N number of iterations used for numbers generation [12] --rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1] --rand-spec-res=N percentage of 'special' values to use (for special distribution) [75] --rand-seed=N seed for random number generator, ignored