sysbench-1.0.14使用說明
一、軟件功能介紹
sysbench是基於LuaJIT開發的多線程基準測試工具,被廣泛的用於數據庫基準測試,
但也可以用於創建負載環境。sysbench的cpu測試是在指定時間內,循環進行素數計算
素數(也叫質數)就是從1開始的自然數中,無法被整除的數,比如2、3、5、7、11、13、17等。
編程公式:對正整數n,如果用2到根號n之間的所有整數去除,均無法整除,則n爲素數。
- sysbench可以實現如下基準測試:
- oltp_*.lua: OLTP類的數據庫基準測試;
- fileio:文件系統的(IO)基準測試;
- cpu: 簡單的CPU基準測試;
- memory: 內存訪問基準測試;
- threads: 基於線程的調度基準測試;
- mutex: POSIX互斥量基準測試;
sysbench能夠生成和跟蹤每秒數百億次事件。
》》》》》》》》》》安裝篇》》》》》》》》》》
對MySQL5.6及以後或MySQL Cluster7.3及以後的版本用sysbench-1.0測試,之前的用sysbench-0.4.8.tar測試;
二、安裝包及腳本下載
GITHub:
https://github.com/akopytov/sysbench
1、安裝方法1:yum安裝
在頁中位置的‘Installing from Binary Packages’裏有各個平臺安裝說明。
下載並執行環境監測腳本:
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
通過yum安裝sysbench
sudo yum -y install sysbench
2、安裝方法2:源碼安裝
在頁中位置的‘Building and Installing From Source’裏有說明。
手動下載最新版本,不要master(主幹)版本,要已發佈的,本說明使用1.0版本。
具體安裝步驟如下。
三、依賴包安裝
安裝需要的依賴包
yum -y install make automake libtool pkgconfig libaio-devel
安裝對MySQL支持的包(安裝這個)
yum -y install mysql-devel
安裝對mariadb支持的包(這裏不使用)
yum -y install mariadb-devel
安裝對PostgreSQL支持的包(這裏不使用)
yum -y install postgresql-devel
四、解壓源碼包
unzip sysbench-1.0.14zip
五、編譯安裝
cd sysbench-1.0
1)執行按之前對環境監測及自動配置
./autogen.sh
2)編譯前配置:
./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
--prefix==>指定安裝路徑,默認會自動在/usr/local/下生成sysbench這個目錄。
備註:
1、./configure --help 可查看幫助
2、默認支持MySQL,如果MySQL不是默認安裝的,需要指定MySQL頭文件(--with-mysql-includes)和庫文件位置(--with-mysql-libs)
3、如果要支持PostgreSQL需要添加--with-pgsql選項
4、如果不需要對MySQL做支持,則使用--without-mysql參數;
5、如果不是對數據庫做測試(當然也就沒有安裝什麼數據庫了),那麼除去數據庫相關的腳本功能,其他功能都可用;
6、源碼文件夾中README.md爲安裝說明,README-Oracle.md爲Oracle的支持安裝說明
3)編譯
make -j
4)安裝
make install
六、配置環境變量
vim /etc/profile
export PATH=$PATH:/usr/local/sysbench/bin
source /etc/profile
七、驗證
sysbench --help
如果出現如下錯誤:
[root@localhost bin]# sysbench --help
sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
則需要在環境變量中指定mysql的lib庫位置:
vim /etc/profile
export LD_LIBRARY_PATH=/usr/local/mysql/lib
source /etc/profile
如果沒有問題,到此安裝完畢!!
》》》》》》》》》》使用篇》》》》》》》》》》
一、語法
sysbench [options]... [testname] [command]
options ==>一個或多個命令行的列表,它們以'--'開頭。
testname ==>它是一個可選的內部測試項名稱(例如:fileio,memory,cpu等),或者是綁定了Lua腳本的名稱(如:oltp_read_only), 亦或者是自定義Lua腳本名。如沒有指定testname也就沒有對應的命令被執行(因爲testname還和用例名對應着),這時sysben將執行默認的測試。
command ==>它是一個可選的參數項,它將被轉遞給前面testname。它定義了測試將要執行的動作。可用的命令取決於要執行的測試項。默寫測試項實現了自己的命令。
下面是典型的測試命令及其描述:
prepare: 爲要執行的測試做測試前準備,如爲fileio測試創建磁盤上的必要文件,爲數據庫基準測試填充測試數據庫。
run: 執行由testname及參數指定的測試項。
cleanup: 清除之前執行測試生成的測試數據。
help: 顯示由testname及參數指定的測試使用信息,其中包括了指定測試項的完整的可用命令列表。
二、通用命令行選項
sysbench --help ==>顯示所以命令行的幫助信息
下表列出支持的命令選項及其描述、默認值
--threads ==>要創建的併發線程數,默認爲1;
--events ==>列出總的請求數限制,默認爲0即不限制;
--time ==>指定執行測試的時間限制,默認爲10,0爲不限制;
--rate ==>平均事務率,指定所有線程每秒執行的事物總數,默認爲0即不限制,越快越好;
--thread-stack-size ==>指定每個線程棧的大小,默認32K;
--report-interval ==>指定統計數據輸出時間間隔,單位秒。此項產生的統計數據不是累計的,是每間隔的。默認爲0,即禁止輸出。
--debug ==>打印調試信息,默認off;
--validate ==>在可能的情況下對測試結果進行驗證,默認off;
--help ==>對語法或在使用--test的測試模式下顯示幫助並退出。
--forced-shutdown ==>超過max-time強制中斷, 默認是off
--report-checkpoints=[LIST,...]==>轉儲完全統計信息並在指定時間點復位所有計數器。
參數是逗號分隔值的列表,表示從必須執行報告檢查點的測試開始
所經過的時間(以秒爲單位)。默認情況下,報告檢查點處於關閉狀態
--config-file=FILENAME ==>通過文件指定測試參數配置
備註:涉及到空間大小的選項,要指定對應的單位(K\M\G)。
僞隨機數發生器的選擇:
--rand-type ==>隨機數分佈方式,[uniform 均勻、gaussian 高斯(正態分佈)、special 特定的、pareto 帕累託(2\8分佈)],默認special
--rand-spec-iter==>數字生成的迭代次數,默認12;
--rand-spec-pct ==>被用於'special'處理的數據百分比(special分佈),默認1;
--rand-spec-res ==>'special'分佈的值中被使用的百分比(special分佈),默認75;
--rand-seed ==>隨機數生成器的種子,當爲0時,當前時間被用作RNG種子。
--rand-pareto-h ==>帕累託分佈的H參數,默認0.2;
日誌選項:
--verbosity ==>信息顯示級別,0只顯示致命級別信息,5顯示debug信息。默認爲4。
--percentile==>指定查詢執行時間的百分比級別,默認95%;(95%的查詢用的時間值)
--histogram ==>在報表中打印響應時間直方圖
數據庫選項:
--db-driver ==>指定使用的數據庫驅動,默認mysql,使用help查看可用的驅動列表;
--db-ps-mode==>prepared語句使用的模式{auto, disable},默認auto;
如設置爲disable則效果就是每個線程會一直使用一個會話來執行所有SQL;否則每個線程在每次執行SQL時都重新連入MySQL。
--db-debug ==>打印數據庫特有的調試信息,默認off;
mysql選項:
--mysql-host ==>被測mysql服務的ip地址,默認localhost
--mysql-port ==>被測mysql服務的端口,默認3306
--mysql-socket ==>被測mysql服務的socket
--mysql-user ==>測試mysql服務的用戶,默認sbtest
--mysql-password==>測試mysql服務的密碼,默認空
--mysql-db ==>被測試庫名,默認sbtest
--mysql-ssl ==>使用SSL連接,默認off
--mysql-ssl-cipher ==>使用SSL連接的祕密
--mysql-compression==>使用壓縮,默認off
--mysql-debug ==>跟蹤所有客戶端庫調用,默認off
--mysql-ignore-errors==>列出要忽略的錯誤的編號列表,all是全部,[LIST,...]
--mysql-dry-run ==>幹運行,假設所有的MySQL客戶端API調用都是成功的,而不用執行它們,默認off;
已編譯的內部測試(用例):
fileio ==>文件I/O測試
cpu ==>CPU性能測試
memory ==>內存功能速率測試
threads==>線程子系統性能測試
mutex ==>互斥量性能測試
備註:使用sysbench <testname> help查看每個用例的幫助信息。
三、執行OLTP測試
特別說明:
1)在安裝完成後生成的(--prefix指定的目錄)/share/sysbench/目錄下有許多OLTP相關的測試腳本可供選擇,腳本名就是testname。
2)構建測試數據相關參數可以使用sysbench <testname> help來查看,或者修改安裝完成後生成的
share/sysbench/oltp_common.lua文件。
1、創建測試數據庫:
create database sbtest;
2、創建測試用戶
create user dbtest@'%' identified by '123456';
grant all privileges on sbtest.* to dbtest@'%';
flush privileges;
3、查看幫助信息:
sysbench oltp_write_only help ==>所有oltp測試腳本的幫助信息都一樣。
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2)
oltp_write_only options:
--auto_inc[=on|off] ==>使用 AUTO_INCREMENT列作爲主鍵(MySQL),其他DBMS使用相應得自增列做主鍵;當禁用時,使用客戶端生成ID做主鍵,默認[on]。
--create_secondary[=on|off] ==>創建輔助所以,默認[on]
--delete_inserts=N ==>每個事務包含的DELETE/INSERT操作得數量,默認[1]
--distinct_ranges=N ==>每個事務包含的SELECT DISTINCT查詢的數量,默認[1]
--index_updates=N ==>每個事務包含的有索引的UPDATE的數量,默認[1]
--mysql_storage_engine=STRING ==>MySQL存儲引擎,默認[innodb]
--non_index_updates=N ==>每個事務包含的無索引的UPDATE的數量,默認[1]
--order_ranges=N ==>每個事務包含的SELECT ORDER BY查詢的數量,默認[1]
--pgsql_variant=STRING ==>使用PostgreSQL驅動程序運行時使用此PostgreSQL變種。目前唯一支持的變體是'redshift'。啓用後,將自動禁用create_secondary,並將delete_inserts設置爲0。
--point_selects=N ==>每個事務包含的等值查詢的數量,默認[10]
--range_selects[=on|off] ==>啓用/停用 範圍查詢,默認[on]
--range_size=N ==>範圍查詢時,指定的範圍大小,默認[100]
--secondary[=on|off] ==>使用輔助索引代替主鍵,默認[off]
--simple_ranges=N ==>每個事務包含的簡單範圍查詢的數量,默認[1]
--skip_trx[=on|off] ==>在AUTOCOMMIT模式下,不顯示開啓事務而且執行所有查詢,默認[off]
--sum_ranges=N ==>每個事務包含的SELECT SUM()的數量,默認[1]
--table_size=N ==>每個表包含的行數,默認[10000]
--tables=N ==>表的數量,默認[1]
4、測試建議:
下面是使用sysbench的一些建議:
1)、在開始測試之前,應該首先明確:應採用針對整個系統的基準測試,還是針對MySQL的基準測試,還是二者都需要。
2)、如果需要針對MySQL的基準測試,那麼還需要明確精度方面的要求:是否需要使用生產環境的真實數據,還是使用工具生成也可以;
前者實施起來更加繁瑣。如果要使用真實數據,儘量使用全部數據,而不是部分數據。
3)、基準測試要進行多次纔有意義。
4)、測試時需要注意主從同步的狀態。
5)、測試必須模擬多線程的情況,單線程情況不但無法模擬真實的效率,也無法模擬阻塞甚至死鎖情況。
6)、每輪測試完成後,都重啓mysqld實例,並且用下面的方法刪除系統cache,釋放swap(如果用到了swap的話),甚至可以重啓整個OS。
# sync -- 將髒數據刷新到磁盤
# echo 3 > /proc/sys/vm/drop_caches -- 清除OS Cache
# swapoff -a && swapon -a -- 清除OS swap緩存
5、OLTP測試數據準備
5個表,每個表500W數據
sysbench oltp_common --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=10.0.212.0 --mysql-port=3306 \
--mysql-user=dbtest --mysql-password=123456 --mysql-db=sbtest --threads=8 --table_size=5000000 --tables=5 prepare
6、OLTP測試
1)oltp_write_only ==>只寫測試
測試5個innodb表每個500W 8線程300s的併發寫入
sysbench oltp_write_only --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=10.0.212.0 --mysql-port=3306 \
--mysql-user=dbtest --mysql-password=123456 --mysql-db=sbtest --threads=8 --table_size=5000000 --tables=5 \
--time=300 --histogram --report-interval=10 --db-ps-mode=disable run
備註:如果使用了--db-ps-mode=disable則不會執行prepare語句。
2)其他OLTP測試用例:
備註:
1>測試時只需更換開頭的測試用例名稱即可;
2>由於MGR在對大事務支持和事務衝突檢測上的限制和不足,導致對MGR直接並行壓測是不可能的。Oracle官方的Multi-Primary Mode測試是在每個結點上,
對不同的測試庫進行壓測,即這樣可以避免了工具無法並行壓測的問題,同時,這樣也減少了衝突的可能性。切記,Multi-Primary Mode一定要避免熱點數據衝突的場景。
例如MGR集羣中有3個節點,分別爲A、B、C;那麼,壓測時需要建立至少3個庫;這樣每個sysbench壓測都使用1個線程來測試一個庫,並且同時啓動多個sysbench來測試。
可以這樣測試:
A節點:
sysbench oltp_write_only ... --mysql-user=dbtest1 ...
B節點:
sysbench oltp_write_only ... --mysql-user=dbtest2 ...
C節點:
sysbench oltp_write_only ... --mysql-user=dbtest3 ...
不過對Multi-Primary Mode壓測並不會有一個很好的結果,因爲熱點太過集中,會導致提交失敗很多,或許反而會導致了性能的下降。
oltp_read_only ==>只讀測試
oltp_read_write ==>讀寫測試
oltp_insert ==>簡單插入測試
bulk_insert ==>批量插入測試
oltp_delete ==>delete刪除測試
oltp_update_index ==>帶索引的更新測試
oltp_update_non_index ==>不帶索引的更新測試
oltp_point_select ==>等值查詢測試
select_random_points ==>隨機等值查詢測試
select_random_ranges ==>隨機範圍查詢測試
7、清除測試數據:
sysbench oltp_common --mysql_storage_engine=innodb --db-driver=mysql --mysql-host=10.0.212.0 --mysql-port=3306 \
--mysql-user=dbtest --mysql-password=123456 --mysql-db=sbtest --threads=8 --table_size=5000000 --tables=5 cleanup
8、測試報告關注:
TPS:每秒處理事務數,如:淘寶11.11 幾十萬TPS,小公司500以下
QPS:每秒處理請求數,增刪改查請求;
遊戲領域:1張2000W的表,500個線程併發,最大請求數量2000W的讀寫混合測試,要avg<10ms!!
#報告內容如下:
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 8
Report intermediate results every 10 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started! -- 線程啓動
-- 每10秒鐘報告一次測試結果,tps、qps、每10秒內讀、每10秒內寫、其他操作、99%以上的響應時長統計
[ 10s ] thds: 8 tps: 1268.61 qps: 7615.07 (r/w/o: 0.00/5076.64/2538.42) lat (ms,95%): 9.73 err/s: 0.40 reconn/s: 0.00
[ 20s ] thds: 8 tps: 1316.89 qps: 7902.83 (r/w/o: 0.00/5268.86/2633.98) lat (ms,95%): 9.22 err/s: 0.20 reconn/s: 0.00
[ 30s ] thds: 8 tps: 1376.95 qps: 8262.82 (r/w/o: 0.00/5508.51/2754.31) lat (ms,95%): 8.90 err/s: 0.40 reconn/s: 0.00
[ 40s ] thds: 8 tps: 1374.08 qps: 8244.95 (r/w/o: 0.00/5496.40/2748.55) lat (ms,95%): 9.06 err/s: 0.40 reconn/s: 0.00
[ 50s ] thds: 8 tps: 1328.17 qps: 7970.01 (r/w/o: 0.00/5313.37/2656.64) lat (ms,95%): 9.39 err/s: 0.30 reconn/s: 0.00
[ 60s ] thds: 8 tps: 1386.86 qps: 8319.77 (r/w/o: 0.00/5546.24/2773.52) lat (ms,95%): 8.90 err/s: 0.20 reconn/s: 0.00
[ 70s ] thds: 8 tps: 1369.29 qps: 8216.06 (r/w/o: 0.00/5477.38/2738.69) lat (ms,95%): 9.06 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 8 tps: 1370.33 qps: 8223.50 (r/w/o: 0.00/5482.54/2740.97) lat (ms,95%): 8.90 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: 8 tps: 1354.04 qps: 8124.53 (r/w/o: 0.00/5416.16/2708.38) lat (ms,95%): 9.06 err/s: 0.30 reconn/s: 0.00
[ 100s ] thds: 8 tps: 1348.60 qps: 8091.17 (r/w/o: 0.00/5394.18/2696.99) lat (ms,95%): 9.06 err/s: 0.00 reconn/s: 0.00
[ 110s ] thds: 8 tps: 1328.88 qps: 7973.77 (r/w/o: 0.00/5315.71/2658.06) lat (ms,95%): 9.39 err/s: 0.10 reconn/s: 0.00
[ 120s ] thds: 8 tps: 1340.61 qps: 8044.37 (r/w/o: 0.00/5362.94/2681.42) lat (ms,95%): 9.06 err/s: 0.30 reconn/s: 0.00
--響應時間、次數柱狀圖
Latency histogram (values are in milliseconds)
value ------------- distribution ------------- count
1.891 | 1
1.925 | 2
1.960 | 4
1.996 | 4
2.032 | 5
2.069 | 14
2.106 | 24
2.145 | 19
2.184 | 26
2.223 | 25
2.264 |* 50
2.305 |* 62
2.347 |* 83
2.389 |* 90
2.433 |* 122
2.477 |* 145
2.522 |** 172
2.568 |** 200
2.615 |** 237
2.662 |*** 308
2.710 |**** 361
2.760 |**** 412
2.810 |**** 416
2.861 |***** 489
2.913 |****** 584
2.966 |****** 634
3.020 |******** 741
3.075 |******** 805
3.130 |********* 899
3.187 |********** 955
3.245 |*********** 1096
3.304 |************* 1262
3.364 |************* 1304
3.425 |*************** 1487
3.488 |**************** 1612
3.551 |****************** 1757
3.615 |******************* 1845
3.681 |******************** 1981
3.748 |********************* 2103
3.816 |*********************** 2275
3.885 |************************* 2439
3.956 |************************** 2540
4.028 |**************************** 2738
4.101 |**************************** 2794
4.176 |****************************** 2949
4.252 |******************************** 3141
4.329 |********************************* 3280
4.407 |********************************** 3369
4.487 |*********************************** 3425
4.569 |************************************ 3511
4.652 |************************************* 3613
4.737 |************************************* 3641
4.823 |************************************ 3591
4.910 |**************************************** 3932
4.999 |************************************** 3786
5.090 |*************************************** 3838
5.183 |**************************************** 3951
5.277 |*************************************** 3850
5.373 |**************************************** 3915
5.470 |************************************* 3666
5.570 |************************************* 3702
5.671 |************************************* 3607
5.774 |************************************ 3583
5.879 |*********************************** 3453
5.986 |*********************************** 3467
6.095 |********************************** 3388
6.205 |******************************* 3082
6.318 |****************************** 2978
6.433 |****************************** 2973
6.550 |**************************** 2803
6.669 |*************************** 2650
6.790 |************************* 2498
6.913 |*********************** 2287
7.039 |********************** 2210
7.167 |******************** 1973
7.297 |******************** 1974
7.430 |****************** 1767
7.565 |***************** 1683
7.702 |**************** 1557
7.842 |************** 1383
7.985 |************** 1373
8.130 |************ 1193
8.277 |************ 1173
8.428 |********** 969
8.581 |********* 932
8.737 |********* 862
8.895 |******** 779
9.057 |******* 735
9.222 |******* 646
9.389 |****** 606
9.560 |***** 506
9.734 |***** 471
9.910 |***** 448
10.090 |**** 377
10.274 |**** 355
10.460 |*** 322
10.651 |*** 304
10.844 |*** 247
11.041 |** 203
11.242 |** 194
11.446 |** 167
11.654 |* 142
11.866 |** 149
12.081 |* 119
12.301 |* 126
12.524 |* 94
12.752 |* 88
12.984 |* 114
13.219 |* 83
13.460 |* 74
13.704 |* 72
13.953 |* 52
14.207 |* 58
14.465 | 49
14.728 |* 53
14.995 | 47
15.268 | 48
15.545 | 32
15.828 | 37
16.115 | 36
16.408 | 46
16.706 | 35
17.010 | 33
17.319 | 37
17.633 | 43
17.954 | 47
18.280 | 34
18.612 | 36
18.950 | 34
19.295 | 29
19.645 | 17
20.002 | 30
20.366 | 23
20.736 | 25
21.112 | 26
21.496 | 21
21.886 | 21
22.284 | 11
22.689 | 24
23.101 | 21
23.521 | 20
23.948 | 6
24.384 | 14
24.827 | 16
25.278 | 17
25.737 | 14
26.205 | 16
26.681 | 16
27.165 | 17
27.659 | 13
28.162 | 10
28.673 | 12
29.194 | 8
29.725 | 8
30.265 | 8
30.815 | 9
31.375 | 7
31.945 | 7
32.525 | 4
33.116 | 2
33.718 | 8
34.330 | 5
34.954 | 5
35.589 | 7
36.236 | 4
36.894 | 3
37.565 | 4
38.247 | 4
38.942 | 6
39.650 | 2
40.370 | 2
41.104 | 2
41.851 | 3
42.611 | 2
43.385 | 1
44.173 | 2
44.976 | 4
45.793 | 1
46.625 | 2
47.472 | 1
51.018 | 6
51.945 | 4
52.889 | 7
53.850 | 12
54.828 | 12
55.824 | 22
56.839 | 25
57.871 | 26
58.923 | 46
59.993 |* 54
61.083 | 40
62.193 |* 54
63.323 |* 55
64.474 | 47
65.645 | 46
66.838 | 31
68.053 | 37
69.289 | 32
70.548 | 18
71.830 | 16
73.135 | 18
74.464 | 17
75.817 | 27
77.194 | 11
78.597 | 8
80.025 | 9
81.479 | 8
82.959 | 6
84.467 | 5
86.002 | 5
87.564 | 5
89.155 | 5
90.775 | 7
92.424 | 1
95.814 | 3
97.555 | 1
99.327 | 3
102.969 | 4
104.840 | 3
106.745 | 7
108.685 | 1
110.659 | 3
112.670 | 3
114.717 | 2
116.802 | 10
118.924 | 6
121.085 | 16
123.285 | 3
125.525 | 4
130.128 | 3
132.492 | 5
134.899 | 2
137.350 | 1
139.846 | 3
142.387 | 1
144.974 | 4
147.608 | 4
150.290 | 3
204.114 | 5
207.823 | 3
SQL statistics: --SQL統計
queries performed:
read: 0 -- 讀總數
write: 646611 -- 寫總數
other: 323312 -- 其他操作總數(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
total: 969923 -- 全部總數
transactions: 161643 (1346.83 per sec.) -- 總事務數(每秒事務數)TPS
queries: 969923 (8081.51 per sec.) -- 總請求數(每秒請求數)QPS
ignored errors: 26 (0.22 per sec.) -- 忽略的總錯誤數(每秒忽略的錯誤數)
reconnects: 0 (0.00 per sec.) -- 重連總數(每秒重連數)
General statistics: --一般統計
total time: 120.0165s -- 總耗時
total number of events: 161643 -- 共發生多少事務數
Latency (ms): -- 響應時間
min: 1.90 -- 最小耗時
avg: 5.94 -- 平均耗時
max: 208.35 -- 最長耗時
95th percentile: 9.06 -- 95%的測試平均耗時
sum: 959723.32 -- 總耗時
Threads fairness: -- 線程的穩定性
events (avg/stddev): 20205.3750/37.94 -- 事件(平均值/偏差)
execution time (avg/stddev): 119.9654/0.01 -- 執行時間(平均值/偏差)
四、CPU測試:
sysbench採用尋找最大素數的方式來測試CPU的性能
1、查看幫助信息
sysbench cpu help
2、默認測試
默認參數,素數上限10000,時間10秒,單線程
sysbench cpu run
3、指定參數測試
sysbench cpu --cpu-max-prime=10000 --threads=8 run
4、常用參數
--cpu-max-prime: 素數生成數量的上限
-若設置爲3,則表示2、3、5(這樣要計算1-5共5次)
-若設置爲10,則表示2、3、5、7、11、13、17、19、23、29(這樣要計算1-29共29次)
-默認值爲10000
--threads: 線程數
-若設置爲,則 sysbench 僅啓動個線程進行素數的計算
-若設置爲 2 ,則 sysbench 會啓動 2 個線程,同時分別進行素數的計算
-默認值爲
--time: 運行時長,單位秒
-若設置爲5,則sysbench會在5秒內循環往復進行素數計算,從輸出結果可以看到在5秒內完成了幾次,
比如配合--cpu-max-prime=3,則表示第一輪算得3個素數,如果時間還有剩就再進行一輪素數計算,直到時間耗盡。
每完成一輪就叫一個event
-默認值爲10
-相同時間,比較的是誰完成的event多
--events: event上限次數
-若設置爲100,則表示當完成100次event後,即使時間還有剩,也停止運行
-默認值爲0,則表示不限event次數
-相同event次數,比較的是誰用時更少
5、案例結果分析
素數上限2萬,時間10秒,2個線程
sysbench cpu --cpu-max-prime=20000 --threads=2 run
結果分析
sysbench 1.0.9 (using system LuaJIT 2.0.4)
Running the test with following options :
Number of threads : 2 // 指定線程數爲2
Initializing random number generator from current time
Prime numbers limit : 20000 // 每個線程產生的素數上限均爲2萬個
Initializing worker threads ...
Threads started !
CPU speed :
events per second : 650.74 // 所有線程每秒完成了650.74次event
General statistics :
total time : 10.0017s // 共耗時10秒
total number of events : 6510 // 10秒內所有線程一共完成了6510次event
Latency (ms ):
min : 3.03 // 完成1次event的最少耗時3.03秒
avg : 3.07 // 所有event的平均耗時3.07毫秒
max : 3.27 // 完成1次event的最多耗時3.27毫秒
95th percentile : 3.13 // 95%次event在3.13秒毫秒內完成
sum : 19999.91 // 每個線程耗時10秒,2個線程疊加耗時就是20秒
Threads fairness :
events (avg / stddev ): 3255.0000 / 44.00 // 平均每個線程完成3255次event,標準差爲44
execution time (avg / stddev ): 10.0000 / 0.00 // 每個線程平均耗時10秒,標準差爲0
備註:
event: 完成了幾輪的素數計算
stddev(標準差): 在相同時間內,多個線程分別完成的素數計算次數是否穩定,如果數值越低,則表示多個線程的結果越接近(即越穩定)。該參數對於單線程無意義。
6、結果分析
如果有2臺服務器進行CPU性能對比,當素數上限和線程數一致時:
相同時間,比較event
相同event,比較時間
時間和event都相同,比較stddev(標準差)
五、文件系統測試
可以對比不同raid卡raid模式、不同文件系統、不同系統分區格式、不同IO下磁盤的性能;
由於其模擬了innodb的IO特點,所以更能表現出innodb的性能特點。要注意,測試時保證
測試的數據文件要大於內存,不然測試的都是緩存了。
1、查看幫助信息
sysbench fileio help
2、數據準備
sysbench fileio --file-total-size=1G prepare
3、執行測試
sysbench fileio --file-total-size=1G --file-test-mode=rndrw --report-interval=1 --threads=8 run
--file-test-mode=rndrw ==>混合隨機讀寫模式,更貼近數據庫實際情況。
--num-threads ==>併發進程數
--report-interval ==>輸出統計信息時間間隔
4、清除測試文件
sysbench fileio cleanup
六、內存測試
1、查看幫助信息
sysbench memory help
2、執行測試
sysbench memory --memory-block-size=16K --memory-total-size=2G --threads=8 run
七、線程測試
1、查看幫助信息
sysbench threads help
2、執行測試
sysbench threads --thread-yields=1000 --thread-locks=10 --threads=8 run
八、互斥量測試
1、查看幫助信息
sysbench mutex help
2、執行測試
sysbench mutex --mutex-num=4096 --mutex-locks=50000 --mutex-loops=10000 --threads=8 run
完畢!