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]# sysbenchMissing 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測試cpuCPU效能測試memory記憶體配置與傳輸速度測試threads線程子系統效能測試mutex互斥體效能測試oltp資料庫OLTP測試 1. 檔案IO測試 [root@RedHat test]# sysbench --test=fileio helpsysbench 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 totalCreating 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: 0128 files, 4Mb each512Mb total file sizeBlock size 16KbNumber of random requests for random IO: 10000Read/Write ratio for combined random IO test: 1.50Periodic FSYNC enabled, calling fsync() each 100 requests.Calling fsync() at the end of test, Enabled.Using synchronous I/O modeDoing random r/w testThreads started!Done. Operations performed: 6000 Read, 4000 Write, 12800 Other = 22800 TotalRead 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 helpsysbench 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 runsysbench v0.4.8: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Doing CPU performance benchmarkThreads started!Done.Maximum prime number checked in CPU test: 20000Test 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 helpsysbench 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 helpsysbench 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 runsysbench v0.4.8: multi-threaded system evaluation benchmark Running the test with following options:Number of threads: 64 Doing thread subsystem performance testThread yields per test: 100 Locks used: 2Threads 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 helpsysbench 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 runsysbench v0.4.8: multi-threaded system evaluation benchmark Running the test with following options:Number of threads: 16 Doing mutex performance testThreads 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測試不做分析了