Sysbench-一種系統性能benchmark
SysBench是一款開源的、跨平台的、模塊化的、多線程的性能測試工具,通過高負載地運行在數據庫上,可以執行CPU/內存/線程/IO/數據庫等方面的性能測試。用於評估操作系統的性能參數。
1 sysbench簡介
Sysbench使得我們無需采用真正的復雜的數據庫benchmark而獲取系統的性能概況。
目前主要支持的數據庫有mysql、oracle、postgresql。
可評估的系統性能參數有:
1. Cpu性能
2. 內存分配與傳輸速度測試
3. 互斥體測試
4. 文件I/O性能
5. 線程調度性能
6. 數據庫服務性能(OLTP基准)
本來sysbench主要是為mysql編寫的benchmark。但是現在SysBench將進一步擴展,以支持更多的數據庫backends,distributed benchmarks和第三方插件模塊。
sysbench按照指定的數量開啟線程,每個線程與mysql建立一個連接,每個線程不停地進行事務操作,打開事務,然後進行一些查詢、更新、插入操作,提交事務,再開始新的事務;所有的sql只訪問一個表-sbtest,是由sysbench的prepare命令建好的。其中的記錄數,也是在prepare時指定好並創建的。測試結束,會有一個統計結果,包括例如每秒事務數、平均響應時間等等;
2 sysbench下載與安裝
1.下載
下載地址:http://sourceforge.net/projects/sysbench/
獲得sysbench-0.4.8.tar.gz源碼。sysbench-0.4.8.tar.gz編譯未通過。
2.安裝
默認支持MySQL,如果需要測試Oracle/PostgreSQL,則在configure時需要加上–with-oracle或者–with-pgsql參數
[root@RedHat sysbench-0.4.8]# ./configure --without-mysql
[root@RedHat sysbench-0.4.8]# make
[root@RedHat sysbench-0.4.8]# make install
如果需要測試mysql,則需要配置參數選項:
./configure
--with-mysql-includes=/opt/mysql/include/mysql 表示mysql頭文件目錄
--with-mysql-libs=/opt/mysql/lib/mysql表示mysql模塊目錄
如股票缺少libtool請至ftp://ftp.gnu.org/gnu/libtool/下載
3 性能測試與結果分析
請查看sysbench幫助
[root@RedHat sysbench-0.4.8]# 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]
--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
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
See 'sysbench --test=<name> help' for a list of options for each test.
[root@RedHat sysbench-0.4.8]#
其中通用參數
參數名
參數描述
--num-threads=N
測試時使用的線程數,默認為1
--max-requests=N
請求數最大現在,默認10000
-max-time=N
執行時間最大限制,默認為0
--thread-stack-size=SIZE
每個線程的stack大小,默認是32K
--init-rng=[on|off]
是否初始化隨機數生成器
--test=STRING
運行的測試
--debug=[on|off]
是否打印更多的debug信息
--validate=[on|off]
是否執行有效性檢查
--help=[on|off]
打印幫助並退出
其中--test=STRING中的STRING可選項有:
STRING
描述
fileio
文件IO測試
cpu
CPU性能測試
memory
內存分配與傳輸速度測試
threads
線程子系統性能測試
mutex
互斥體性能測試
oltp
數據庫OLTP測試
1. 文件IO測試
[root@RedHat test]# sysbench --test=fileio help
sysbench v0.4.8: multi-threaded system evaluation benchmark
fileio options:
--file-num=N number of files to create [128]
--file-block-size=N block size to use in all IO operations [16384]
--file-total-size=SIZE total size of files to create [2G]
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
--file-io-mode=STRING file operations mode {sync,async,fastmmap,slowmmap} [sync]
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]
--file-fsync-all=[on|off] do fsync() after each write operation [off]
--file-fsync-end=[on|off] do fsync() at the end of test [on]
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
--file-merged-requests=N merge at most this number of IO requests if poss ible (0- don't merge) [0]
--file-rw-ratio=N reads/writes ratio for combined test [1.5]
[root@RedHat test]#
參數選項說明:
參數名
描述
--file-num=N
創建的文件數目,默認為128個
--file-block-size=N
所有IO操作中的block大小,默認是16384
--file-total-size=SIZE
創建的文件的總大小,默認為2G
--file-test-mode=STRING
測試的訪問模式,可選一下6個參數:seqwr(順序寫)/seqrewr(順序讀寫)/seqrd(順序讀)/ rndwr(隨機寫)/rndrw(隨機讀寫)/rndrd(隨機讀);
--file-io-mode=STRING
文件操作模式,有以下四種選擇:sync,async,fastmmap,slowmmap默認為sync
--file-extra-flags=STRING
打開文件是的標識,有以下選擇:sync,dsync,direct
--file-fsync-freq=N
在N個請求之後執行fsync(),默認值為100,0表示不執行fsync()
--file-fsync-all=[on|off]
是否每一次寫操作之後均執行fsync()
--file-fsync-end=[on|off]
在測試結束時執行fsync(),默認開啟
--file-fsync-mode=STRING
同步使用什麼方法:fsync, fdatasync,默認為fsync
--file-merged-requests=N
盡可能的合並N個請求,0表示不合並,默認為0
--file-rw-ratio=N
讀寫比例默認為1.5:1
測試案例:
創建2個進程,創建的文件總大小為3G,文件讀寫模式為隨機讀。
可以獲取讀寫速度~
[root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw prepare (准備測試文件)
sysbench v0.4.8: multi-threaded system evaluation benchmark
128 files, 4096Kb each, 512Mb total
Creating files for the test...
[root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw run (運行測試)
sysbench v0.4.8: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 2
Extra file open flags: 0
128 files, 4Mb each
512Mb total file size
Block size 16Kb
Number of random requests for random IO: 10000
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Threads started!
Done.
Operations performed: 6000 Read, 4000 Write, 12800 Other = 22800 Total
Read 93.75Mb Written 62.5Mb Total transferred 156.25Mb (3.2979Mb/sec)
211.07 Requests/sec executed
Test execution summary:
total time: 47.3783s
total number of events: 10000
total time taken by event execution: 36.6912
per-request statistics:
min: 0.0000s
avg: 0.0037s
max: 0.2687s
approx. 95 percentile: 0.0230s
Threads fairness:
events (avg/stddev): 5000.0000/180.00
execution time (avg/stddev): 18.3456/0.19
[root@RedHat test]# sysbench --test=fileio --num-threads=2 --file-total-size=512M --file-test-mode=rndrw cleanup (清除測試文件)
sysbench v0.4.8: multi-threaded system evaluation benchmark
Removing test files...
[root@RedHat test]#
2. CPU性能測試
Sysbench采用尋找最大素數的方式測試CPU性能:
[root@RedHat ~]# sysbench --test=cpu help
sysbench v0.4.8: multi-threaded system evaluation benchmark
cpu options:
--cpu-max-prime=N upper limit for primes generator [10000]
[root@RedHat ~]#
參數解析
參數名
描述
--cpu-max-prime=N
素數的最大限制,默認為10000;
測試案例
[root@RedHat ~]# sysbench --test=cpu --cpu-max-prime=20000 run
sysbench v0.4.8: 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: 20000
Test execution summary:
total time: 124.1761s
total number of events: 10000
total time taken by event execution: 123.3658
per-request statistics:
min: 0.0051s
avg: 0.0123s
max: 0.1908s
approx. 95 percentile: 0.0171s
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 123.3658/0.00
[root@RedHat ~]#
3.內存性能測試
[root@RedHat ~]# sysbench --test=memory help
sysbench v0.4.8: multi-threaded system evaluation benchmark
memory options:
--memory-block-size=SIZE size of memory block for test [1K]
--memory-total-size=SIZE total size of data to transfer [100G]
--memory-scope=STRING memory access scope {global,local} [global]
--memory-hugetlb=[on|off] allocate memory from HugeTLB pool [off]
--memory-oper=STRING type of memory operations {read, write, none} [write]
--memory-access-mode=STRING memory access mode {seq,rnd} [seq]
[root@RedHat ~]#
參數名
描述
--memory-block-size=SIZE
內存塊大小,默認為1K
--memory-total-size=SIZE
傳輸的數據量,默認為100G
--memory-scope=STRING
內存訪問是局部local還是全局global,默認為global
--memory-hugetlb=[on|off]
從hugetlb中分配內存
--memory-oper=STRING
內存操作類型read, write, none,默認為寫
--memory-access-mode=STRING
內存訪問模式seq,rnd,默認為seq;
[root@RedHat test]# sysbench --test=memory --memory-block-size=4k --memory-total-size=64M run
4.線程性能測試
[root@RedHat ~]# sysbench --test=threads help
sysbench v0.4.8: multi-threaded system evaluation benchmark
threads options:
--thread-yields=N number of yields to do per request [1000]
--thread-locks=N number of locks per thread [8]
[root@RedHat ~]#
參數名
描述
--thread-yields=N
內存塊大小,默認為1K
--thread-locks=N
傳輸的數據量,默認為100G
測試案例
[root@RedHat test]# sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
sysbench v0.4.8: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 64
Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 2
Threads started!
Done.
Test execution summary:
total time: 24.8159s
total number of events: 10000
total time taken by event execution: 1575.5529
per-request statistics:
min: 0.0002s
avg: 0.1576s
max: 2.0173s
approx. 95 percentile: 0.5627s
Threads fairness:
events (avg/stddev): 156.2500/12.62
execution time (avg/stddev): 24.6180/0.08
[root@RedHat test]#
5互斥體性能測試
[root@RedHat ~]# sysbench --test=mutex help
sysbench v0.4.8: multi-threaded system evaluation benchmark
mutex options:
--mutex-num=N total size of mutex array [4096]
--mutex-locks=N number of mutex locks to do per thread [50000]
--mutex-loops=N number of empty loops to do inside mutex lock [10000]
[root@RedHat ~]#
參數名
描述
--mutex-num=N
互斥體數據大小,默認為4096
--mutex-locks=N
每個線程上互斥鎖的數目,默認為50000;
--mutex-loops=N
互斥鎖內空循環的數目,默認為10000
測試案例
[root@RedHat test]# sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
sysbench v0.4.8: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Doing mutex performance test
Threads started!
Done.
Test execution summary:
total time: 0.0482s
total number of events: 16
total time taken by event execution: 0.2271
per-request statistics:
min: 0.0015s
avg: 0.0142s
max: 0.0312s
approx. 95 percentile: 0.0126s
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 0.0142/0.01
[root@RedHat test]#
6 OLTP測試
不做分析了