轉自:http://linuxperformance.top/index.php/archives/83/
推薦部落格位址:http://linuxperformance.top/
sysbench簡介
sysbench是一款開源的多線程性能測試工具,可以執行CPU/記憶體/線程/IO/資料庫等方面的性能測試。
支援MySQL/Oracle/PostgreSQL。
sysbench支援以下幾種測試模式:
1、CPU運算性能
2、磁盤IO性能
3、排程程式性能
4、記憶體配置設定及傳輸速度
5、POSIX線程性能
6、資料庫性能(OLTP基準測試)
-
下載下傳位址及安裝
下載下傳位址:https://github.com/akopytov/sysbench
安裝
./autogen.sh
./configure
如果出現:configure: error: mysql_config executable not found
需要安裝:mariadb-devel (yum install mariadb-devel 安裝mysql_config)
make && make install 完成安裝。
PS:此外還要安裝mariadb-server包,yum install mariadb-server。
-
CPU測試
對CPU的性能測試通常有:1.質數計算;2圓周率計算;sysbench使用的就是通過質數相加的測試。對CPU測試直接運作run即可。
sysbench --threads=20 --events=10000 --debug=on --test=cpu --cpu-max-prime=20000 run
20個線程執行1萬條請求,每個請求執行質數相加到20000
-
記憶體測試
測試8K順序配置設定:
sysbench --threads=12 --events=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run
測試8K随機配置設定。
sysbench --threads=12 --events=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run
-
檔案io測試
IO的測試主要用于測試IO的負載性能。主要測試選項為--file-test-mode。還有可以關注的參數包括--file-block-size、--file-io-mode、--file-fsync-freq 、--file-rw-ratio,具體參數含義請見參數解釋章節。
sysbench --threads=12 --events=10000 fileio --file-total-size=3G --file-test-mode=rndrw prepare
sysbench --threads=12 --events=10000 fileio --file-total-size=3G --file-test-mode=rndrw run
sysbench --threads=12 --events=10000 fileio --file-total-size=3G --file-test-mode=rndrw cleanup
對比兩台伺服器的io性能,需要跑相同的線程
-
鎖測試
互斥鎖測試模拟所有線程在同一時刻并發運作。
sysbench --threads=12 mutex --mutex-num=1024 --mutex-locks=10000 --mutex-loops=10000 run
-
線程測試
sysbench threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
-
OLTP測試
oltp是針對資料庫的基準測試,例如每次對資料庫進行優化後執行基準測試來測試不同的配置的tps。sysbench 0.5之後通過一系列LUA腳本來替換之前的oltp,來模拟更接近真實的基準測試環境。這些測試腳本包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua
預置條件:
a)建立資料庫:
mysqladmin create sbtest -uroot –p
或者
SQL>create database sbtest
b)增權重限:
grant usage on . to 'sbtest'@'%' identified by password '*2AFD99E79E4AA23DE141540F4179F64FFB3AC521';
其中密碼通過如下指令擷取:
select password('sbtest');
+-------------------------------------------+
| password('sbtest') |
| 2AFD99E79E4AA23DE141540F4179F64FFB3AC521 |
1 row in set (0.00 sec)
c)增權重限:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER,INDEX ON
sbtest
.TO 'sbtest'@"%";
grant all privileges on . to 'sbtest'@'%';
flush privileges;
或者簡單粗暴:
create user 'sbtest'@'127.0.0.1' identified by 'sbtest';
grant all privileges on . to
e)OLTP測試:
準備階段:
sysbench --test= /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sbtest --mysql-password=sbtest --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on prepare
測試階段:
指令如下:
sysbench --test= /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sbtest --mysql-password=sbtest --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on run
清理階段:
sysbench --test= /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sbtest --mysql-password=sbtest --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on cleanup
最後删除資料庫
SQL>drop database sbtest;
- 參數解釋