標籤:
sysbench是一款開源的多線程效能測試工具,可以執行CPU/記憶體/線程/IO/資料庫等方面的效能測試。資料庫目前支援MySQL/Oracle/PostgreSQL/Drizzle,它主要包括以下幾種方式的測試:
- cpu效能
- 磁碟io效能
- 發送器效能
- 記憶體配置及傳輸速度
- POSIX線程效能
- 資料庫效能(OLTP基準測試)
機器配置
[[email protected] ~]# grep -iE ‘MemTotal|MemFree‘ /proc/meminfo MemTotal: 8058060 kBMemFree: 2213240 kB[[email protected] ~]# grep "processor" /proc/cpuinfo | wc -l4[[email protected] ~]# uname -aLinux localhost 2.6.32-431.11.2.el6.x86_64 #1 SMP Tue Mar 25 19:59:55 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux[[email protected] ~]# cat /etc/redhat-release CentOS release 6.7 (Final)
一、安裝
官方地址:https://github.com/akopytov/sysbench
下載方法:git clone https://github.com/akopytov/sysbench.git
安裝
./autogen.sh./configuremake && make install
以上命令的編譯SysBench預設需要Mysql庫的支援,如果你機器已安裝Mysql但沒有指定位置(在PATH下找不到mysql_config),你必須在./configure得時候指定–with-mysql-includes和–with-mysql-libs
也可以使用–without-mysql命令,取消Mysql的支援
command命令的簡單描述及作用
prepare:為測試執行準備工作,例如為fileis測試在磁碟上建立必要的檔案,為OLTP測試準備測試資料run: 執行完整的測試,必須指定–-test選項cleanup: 在測試回合結束移除prepare準備的臨時資料help:顯示不同測試(根據–-test選項)的協助資訊,你也可以使用sysbench help命令(而不用–-test)去顯示協助資訊
一些參數的解釋
--num-threads #建立測試線程的數目 --max-requests #請求的最大數目,0表示不限制 --max-time #最大執行時間,單位秒,0表示不限制 --thread-stack-size #每個線程的堆棧大小32K--init-rng #在測試開始之前指定是否需要初始化隨機數發生器off--report-interval #隔多久列印一次統計資訊,注意的是統計資訊統計的是間隔時間而不是累計時間的資料。單位秒,0表示關閉該功能--test #指定測試專案名稱Required--debug #是否顯示更多的調試資訊off--validate #在可能的情況下是否進行驗證檢查off--help #協助資訊off--verbosity #詳細資訊層級,0-嚴重資訊,5-調試資訊--percentile #表示設定採樣比例,預設是 95%,即丟棄1%的長請求,在剩餘的99%裡取最大值
二、CPU的基準測試
CPU測試使用64位整數,測試計算質數直到某個最大值所需要的時間,cpu測試主要是進行素數的加法運算,在上面的例子中,指定了最大的素數為 20000,自己可以根據機器cpu的效能來適當調整數值,主要看total time所花費的時間
[[email protected] sysbench]# sysbench --test=cpu --cpu-max-prime=10000 runsysbench 0.5: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Random number generator seed is 0 and will be ignoredPrimer numbers limit: 10000Threads started!General statistics: total time: 14.5690s total number of events: 10000 total time taken by event execution: 14.5616s response time: min: 1.40ms avg: 1.46ms max: 10.59ms approx. 95 percentile: 1.52msThreads fairness: events (avg/stddev): 10000.0000/0.00 execution time (avg/stddev): 14.5616/0.00
相關選項
sysbench –test=cpu help--cpu-max-prime=N 最大質數發生器數量。預設是10000
三、線程基準測試
thread-locks小於線程數除以2,lock越少,處理時間越長
[[email protected] sysbench]# sysbench --test=threads --num-threads=800 --thread-yields=100 --thread-locks=10 run sysbench 0.5: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 800Random number generator seed is 0 and will be ignoredThreads started!General statistics: total time: 0.4644s total number of events: 10000 total time taken by event execution: 350.9839s response time: min: 0.04ms avg: 35.10ms max: 456.96ms approx. 95 percentile: 144.17msThreads fairness: events (avg/stddev): 12.5000/6.45 execution time (avg/stddev): 0.4387/0.01
相關參數
sysbench --test=threads helpsysbench 0.5: multi-threaded system evaluation benchmark threads options: --thread-yields=N 每個請求產生多少個線程。預設是1000 --thread-locks=N 每個線程的鎖的數量。預設是8
四、檔案IO基準測試
磁碟IO效能測試[主要看每秒請求數(request)和總體的輸送量(total)
[[email protected] sysbench]# sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw preparesysbench 0.5: multi-threaded system evaluation benchmark128 files, 16384Kb each, 2048Mb totalCreating files for the test...Extra file open flags: 0Creating file test_file.0Creating file test_file.1……Creating file test_file.1272147483648 bytes written in 67.56 seconds (30.32 MB/sec).[[email protected] sysbench]# sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw runsysbench 0.5: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 20Random number generator seed is 0 and will be ignoredExtra file open flags: 0128 files, 16Mb each2Gb total file sizeBlock size 16KbNumber of IO requests: 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!Operations performed: 5999 reads, 4001 writes, 12800 Other = 22800 TotalRead 93.734Mb Written 62.516Mb Total transferred 156.25Mb (19.3Mb/sec) 1235.21 Requests/sec executedGeneral statistics: total time: 8.0958s total number of events: 10000 total time taken by event execution: 1.4557s response time: min: 0.00ms avg: 0.15ms max: 1319.03ms approx. 95 percentile: 0.02msThreads fairness: events (avg/stddev): 500.0000/186.14 execution time (avg/stddev): 0.0728/0.29
相關參數
sysbench --test=fileio helpsysbench 0.5: multi-threaded system evaluation benchmark fileio options: --file-num=N 建立測試檔案的數量。預設是128 --file-block-size=N 測試時檔案塊的大小。預設是16384(16K) --file-total-size=SIZE 測試檔案的總大小。預設是2G --file-test-mode=STRING 檔案測試模式{seqwr(順序寫), seqrewr(順序讀寫), seqrd(順序讀), rndrd(隨機讀), rndwr(隨機寫), rndrw(隨機讀寫)} --file-io-mode=STRING 檔案操作模式{sync(同步),async(非同步),fastmmap(快速map映射),slowmmap(慢map映射)}。預設是sync --file-extra-flags=STRING 使用額外的標誌來開啟檔案{sync,dsync,direct} 。預設為空白 --file-fsync-freq=N 執行fsync()的頻率。(0 – 不使用fsync())。預設是100 --file-fsync-all=[on|off] 每執行完一次寫操作就執行一次fsync。預設是off --file-fsync-end=[on|off] 在測試結束時才執行fsync。預設是on --file-fsync-mode=STRING 使用哪種方法進行同步{fsync, fdatasync}。預設是fsync --file-merged-requests=N 如果可以,合并最多的IO請求數(0 – 表示不合并)。預設是0 --file-rw-ratio=N 測試時的讀寫比例。預設是1.5五、記憶體基準測試
測試了記憶體的連續讀寫效能
[[email protected] sysbench]# sysbench --test=memory --memory-block-size=8k --memory-total-size=1G runsysbench 0.5: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Random number generator seed is 0 and will be ignoredThreads started!Operations performed: 131072 (769179.70 ops/sec)1024.00 MB transferred (6009.22 MB/sec)General statistics: total time: 0.1704s total number of events: 131072 total time taken by event execution: 0.1387s response time: min: 0.00ms avg: 0.00ms max: 2.12ms approx. 95 percentile: 0.00msThreads fairness: events (avg/stddev): 131072.0000/0.00 execution time (avg/stddev): 0.1387/0.00
相關參數
sysbench --test=memory helpsysbench 0.5: multi-threaded system evaluation benchmark memory options: --memory-block-size=SIZE 測試時記憶體塊大小。預設是1K --memory-total-size=SIZE 傳輸資料的總大小。預設是100G --memory-scope=STRING 記憶體存取範圍{global,local}。預設是global --memory-hugetlb=[on|off] 從HugeTLB池記憶體配置。預設是off --memory-oper=STRING 記憶體操作類型。{read, write, none} 預設是write --memory-access-mode=STRING 儲存空間存取方式{seq,rnd} 預設是seq 六、互斥鎖基準測試
[[email protected] sysbench]# sysbench --test=mutex --num-threads=100 --mutex-num=1000 --mutex-locks=100000 --mutex-loops=10000 run sysbench 0.5: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 100Random number generator seed is 0 and will be ignoredThreads started!General statistics: total time: 4.9822s total number of events: 100 total time taken by event execution: 474.6478s response time: min: 1601.28ms avg: 4746.48ms max: 4981.76ms approx. 95 percentile: 4973.56msThreads fairness: events (avg/stddev): 1.0000/0.00 execution time (avg/stddev): 4.7465/0.40
相關參數
sysbench --test=mutex helpsysbench 0.5: multi-threaded system evaluation benchmark mutex options: --mutex-num=N 數組互斥的總大小。預設是4096 --mutex-locks=N 每個線程互斥鎖的數量。預設是50000 --mutex-loops=N 內部互斥鎖的空迴圈數量。預設是10000
七、OLTP基準測試
完整過程分為3個階段:prepare->run->cleanup,即分別為準備資料,測試,清理測試資料
[[email protected] sysbench]# sysbench --mysql-socket=/var/lib/mysql/mysql.sock --oltp-table-size=100000 --test=sysbench/tests/db/oltp.lua --mysql-user=root --mysql-password=123456 --report-interval=5 --num-threads=100 --oltp_tables_count=10 --rand-type=uniform --percentile=99 runsysbench 0.5: multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 100Report intermediate results every 5 second(s)Random number generator seed is 0 and will be ignoredThreads started![ 5s] threads: 100, tps: 894.57, reads/s: 12790.38, writes/s: 3646.48, response time: 340.91ms (99%)[ 10s] threads: 100, tps: 973.20, reads/s: 13608.42, writes/s: 3860.61, response time: 238.96ms (99%)OLTP test statistics: queries performed: read: 140000 write: 40000 other: 20000 total: 200000 transactions: 10000 (932.07 per sec.) deadlocks: 0 (0.00 per sec.) read/write requests: 180000 (16777.18 per sec.) other operations: 20000 (1864.13 per sec.)General statistics: total time: 10.7289s total number of events: 10000 total time taken by event execution: 1067.3242s response time: min: 9.75ms avg: 106.73ms max: 450.30ms approx. 99 percentile: 284.52msThreads fairness: events (avg/stddev): 100.0000/4.15 execution time (avg/stddev): 10.6732/0.05
相關參數
sysbench --test=oltp helpsysbench 0.5: multi-threaded system evaluation benchmark oltp options: --oltp-test-mode=STRING 執行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。預設是complex --oltp-reconnect-mode=STRING 重新串連模式{session(不使用重新串連。每個線程斷開只在測試結束),transaction(在每次事務結束後重新串連),query(在每個SQL語句執行完重新串連),random(對於每個事務隨機播放以上重新串連模式)}。預設是session --oltp-sp-name=STRING 預存程序的名稱。預設為空白 --oltp-read-only=[on|off] 唯讀模式。Update,delete,insert語句不可執行。預設是off --oltp-skip-trx=[on|off] 省略begin/commit語句。預設是off --oltp-range-size=N 查詢範圍。預設是100 --oltp-point-selects=N number of point selects [10] --oltp-simple-ranges=N number of simple ranges [1] --oltp-sum-ranges=N number of sum ranges [1] --oltp-order-ranges=N number of ordered ranges [1] --oltp-distinct-ranges=N number of distinct ranges [1] --oltp-index-updates=N number of index update [1] --oltp-non-index-updates=N number of non-index updates [1] --oltp-nontrx-mode=STRING 查詢類型對於非事務執行模式{select, update_key, update_nokey, insert, delete} [select] --oltp-auto-inc=[on|off] AUTO_INCREMENT是否開啟。預設是on --oltp-connect-delay=N 在多少微秒後串連資料庫。預設是10000 --oltp-user-delay-min=N 每個請求最短等待時間。單位是ms。預設是0 --oltp-user-delay-max=N 每個請求最長等待時間。單位是ms。預設是0 --oltp-table-name=STRING 測試時使用到的表名。預設是sbtest --oltp-table-size=N 測試表的記錄數。預設是10000 --oltp-dist-type=STRING 分布的隨機數{uniform(均勻分布),Gaussian(高斯分布),special(空間分布)}。預設是special --oltp-dist-iter=N 產生數的迭代次數。預設是12 --oltp-dist-pct=N 值的百分比被視為‘special‘ (for special distribution)。預設是1 --oltp-dist-res=N ‘special’的百分比值。預設是75 General database options: --db-driver=STRING 指定資料庫驅動程式(‘help‘ to get list of available drivers) --db-ps-mode=STRING 編製報表使用模式{auto, disable} [auto]Compiled-in database drivers: mysql - MySQL drivermysql options: --mysql-host=[LIST,...] 資料庫地址 --mysql-port=N 連接埠號碼,預設3306 --mysql-user=STRING 使用者名稱 --mysql-password=STRING 密碼 --mysql-db=STRING 測試資料庫名 --mysql-table-engine=STRING 資料庫儲存引擎,預設innodb{myisam,innodb,bdb,heap,ndbcluster,federated} --mysql-socket=STRING socket檔案的位置 --mysql-engine-trx=STRING 是否使用事務,與儲存引擎選擇有關,預設auto{yes,no,auto} --mysql-ssl=[on|off] 在用戶端是否使用SSL串連,預設off --myisam-max-rows=N MyISAM表最大行數,預設1000000 --mysql-create-options=STRING additional options passed to CREATE TABLE []
參考地址
https://launchpad.net/sysbench
https://github.com/akopytov/sysbench
使用sysbench進行壓力測試