Linux – SysBench

Loading

Linux 下常見的壓力測試工具不多,而且通常很分散,要不然就是協力廠商所開發的工具需收費而且所費不貲,不過現在 Linux 下有一套比較完整的壓力測試工具 sysbench http://sysbench.sourceforge.net/
使用上很簡單,用 apt-get install 就可以安裝 sysbench ,安裝完成之後就可以直接使用了.

ben@ben-SDV:~$ apt-get install sysbench

sysbench 提供 File I/O, CPU , Memory , Threads , Mutx , OLTP 的測試,下面我們一一來詳細了解.

ben@ben-SDV:~$ sysbench
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

cpu – CPU performance test

一般我們透過 SPEC CPU 測試 CPU 的效能與評分,sysbench 有提供測試 CPU 的效能與評分,其實他使用的方式也很簡單,只有參數 –cpu-max-prime=100000 就是讓 CPU 去計算出100000 的最大質數是多少,需要花多少時間來計算.

ben@ben-SDV:~$ sysbench --test=cpu --cpu-max-prime=100000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1

Doing CPU performance benchmark

Threads started!
Done.

Maximum prime number checked in CPU test: 100000

Test execution summary:
total time: 284.5265s
total number of events: 10000
total time taken by event execution: 284.5207
per-request statistics:
min: 28.37ms
avg: 28.45ms
max: 32.47ms
approx. 95 percentile: 28.55ms

Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 284.5207/0.00

不過這程式很難當作評斷 CPU 好壞的工具,在執行程式後仔細觀察 CPU 的使用狀況,你會發現他只用到單一顆核心去執行該程式.
sysbench02

mutex – Mutex performance test

因為剛剛 CPU 無法發揮所有的效能所以查了他另外一個參數 Mutex – http://sysbench.sourceforge.net/docs/#threads_mode
This test mode was written to emulate a situation when all threads run concurrently most of the time, acquiring the mutex lock only for a short period of time (incrementing a global variable). So the purpose of this benchmarks is to examine the performance of mutex implementation.

官網的說明就是採用多執行緒同時跑,看系統需要多少時間才能執行完畢.

ben@ben-SDV:~$ sysbench --test=mutex --num-threads=10000 --mutex-locks=100000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 10000

Doing mutex performance test
Threads started!
Done.

Test execution summary:
total time: 174.8060s
total number of events: 10000
total time taken by event execution: 1643228.7121
per-request statistics:
min: 94317.58ms
avg: 164322.87ms
max: 174452.17ms
approx. 95 percentile: 173901.13ms

Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 164.3229/9.72

主要我用了 2 個參數.

  • mutex-num
    Number of mutexes. The actual mutex to lock is chosen randomly before each lock 預設值為4096
  • mutex-locks
    Number of mutex locks to acquire per each request 預設值為 50000

雖然 CPU 的負載是平均分配但沒有辦法達到全速 100% 的運作.可能需要再搭配 sysbench 其他的壓力測試工具才會讓系統效能開到 100% 吧.

下面幾項我就沒有特別再試,透過 man sysbench 就可以查到一些相關的測試方式.

memory – Memory functions speed test

ben@ben-SDV:~$ sysbench --test=memory --memory-block-size=8K --memory-total-size=1G --memory-oper=read run
ben@ben-SDV:~$ sysbench --test=memory --memory-block-size=8K --memory-total-size=1G --memory-oper=write run

threads – Threads subsystem performance test

還沒有仔細研究過.

oltp – OLTP test

步驟可以分為 prepare , run , cleanup ,詳細說明請參考 https://benjr.tw/95251 , https://benjr.tw/95619

ben@ben-SDV:~$ sysbench --test=oltp --mysql-table-type=myisam --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock prepare
ben@ben-SDV:~$ sysbench --num-threads=16 --max-requests=100000 --test=oltp --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --oltp-read-only run

fileio – File I/O test

ben@ben-SDV:~$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw prepare
ben@ben-SDV:~$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw run
ben@ben-SDV:~$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw cleanup
沒有解決問題,試試搜尋本站其他內容

6 thoughts on “Linux – SysBench

  1. 自動引用通知: CentOS7 – Sysbench – Benjr.tw
  2. 自動引用通知: Sysbench – oltp – Benjr.tw

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料