摘要:
sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,能夠用來進行CPU、內存、磁盤I/O、線程、數據庫的性能測試。目前支持的數據庫有MySQL、Oracle和PostgreSQL。當前功能容許測試的系統參數有:mysql
file I/O performance (文件I / O性能) scheduler performance (調度性能) memory allocation and transfer speed (內存分配和傳輸速度) POSIX threads implementation performance (POSIX線程執行績效) database server performance (OLTP benchmark) (數據庫服務器性能)
root@db2:~# 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] #建立測試線程的數目。默認爲1. --max-requests=N limit for total number of requests [10000] #請求的最大數目。默認爲10000,0表明不限制。 --max-time=N limit for total execution time in seconds [0] #最大執行時間,單位是s。默認是0,不限制。 --forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off] #超過max-time強制中斷。默認是off。 --thread-stack-size=SIZE size of stack per thread [32K] #每一個線程的堆棧大小。默認是32K。 --init-rng=[on|off] initialize random number generator [off] #在測試開始時是否初始化隨機數發生器。默認是off。 --test=STRING test to run #指定測試項目名稱。 --debug=[on|off] print more debugging info [off] #是否顯示更多的調試信息。默認是off。 --validate=[on|off] perform validation checks where possible [off] #在可能狀況下執行驗證檢查。默認是off。 --help=[on|off] print help and exit #幫助信息。 --version=[on|off] print version and exit #版本信息。 Compiled-in tests: #測試項目 fileio - File I/O test #IO cpu - CPU performance test #CPU memory - Memory functions speed test #內存 threads - Threads subsystem performance test #線程 mutex - Mutex performance test #互斥性能測試 oltp - OLTP test # 數據庫,事務處理 Commands: prepare:測試前準備工做; run:正式測試 cleanup:測試後刪掉測試數據 help version See 'sysbench --test=<name> help' for a list of options for each test. #查看每一個測試項目的更多選項列表
root@db2:~# sysbench --test=fileio help sysbench 0.4.12: 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
--cpu-max-prime=N 最大質數發生器數量。默認是10000
root@db2:~# sysbench --test=memory help sysbench 0.4.12: 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
sysbench 0.4.12: multi-threaded system evaluation benchmark threads options: --thread-yields=N 每一個請求產生多少個線程。默認是1000 --thread-locks=N 每一個線程的鎖的數量。默認是8
root@db2:~# sysbench --test=mutex help sysbench 0.4.12: multi-threaded system evaluation benchmark mutex options: --mutex-num=N 數組互斥的總大小。默認是4096 --mutex-locks=N 每一個線程互斥鎖的數量。默認是50000 --mutex-loops=N 內部互斥鎖的空循環數量。默認是10000
root@db2:~# sysbench --test=oltp help sysbench 0.4.12: 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 driver mysql options: --mysql-host=[LIST,...] MySQL server host [localhost] --mysql-port=N MySQL server port [3306] --mysql-socket=STRING MySQL socket --mysql-user=STRING MySQL user [sbtest] --mysql-password=STRING MySQL password [] --mysql-db=STRING MySQL database name [sbtest] --mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb] --mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto] --mysql-ssl=[on|off] use SSL connections, if available in the client library [off] --myisam-max-rows=N max-rows parameter for MyISAM tables [1000000] --mysql-create-options=STRING additional options passed to CREATE TABLE []
root@db2:~# sysbench --test=cpu --cpu-max-prime=2000 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: 2000 Test execution summary: total time: 3.7155s total number of events: 10000 total time taken by event execution: 3.7041 per-request statistics: min: 0.36ms avg: 0.37ms max: 2.53ms approx. 95 percentile: 0.37ms Threads fairness: events (avg/stddev): 10000.0000/0.00 execution time (avg/stddev): 3.7041/0.00
root@db2:~# sysbench --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run sysbench 0.4.12: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 500 Doing thread subsystem performance test Thread yields per test: 100 Locks used: 4 Threads started! Done. Test execution summary: total time: 1.0644s total number of events: 10000 total time taken by event execution: 501.3952 per-request statistics: min: 0.05ms avg: 50.14ms max: 587.05ms approx. 95 percentile: 190.28ms Threads fairness: events (avg/stddev): 20.0000/4.72 execution time (avg/stddev): 1.0028/0.01
prepare階段,生成須要的測試文件,完成後會在當前目錄下生成不少小文件。sql
sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare
數據庫
run階段數組
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run
服務器
清理測試時生成的文件session
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup
多線程
root@db2:~/io# sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare sysbench 0.4.12: multi-threaded system evaluation benchmark 128 files, 16384Kb each, 2048Mb total Creating files for the test... root@db2:~/io# sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run sysbench 0.4.12: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 20 Extra file open flags: 0 128 files, 16Mb each 2Gb 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: 6010 Read, 3997 Write, 12803 Other = 22810 Total Read 93.906Mb Written 62.453Mb Total transferred 156.36Mb (6.6668Mb/sec) 426.68 Requests/sec executed Test execution summary: total time: 23.4534s total number of events: 10007 total time taken by event execution: 111.5569 per-request statistics: min: 0.01ms avg: 11.15ms max: 496.18ms approx. 95 percentile: 53.05ms Threads fairness: events (avg/stddev): 500.3500/37.50 execution time (avg/stddev): 5.5778/0.21 root@db2:~/io# sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup sysbench 0.4.12: multi-threaded system evaluation benchmark Removing test files...
sysbench 0.4.12: multi-threaded system evaluation benchmark Operations performed: 1310720 (396525.32 ops/sec) 10240.00 MB transferred (3097.85 MB/sec) Test execution summary: total time: 3.3055s total number of events: 1310720 total time taken by event execution: 205.0560 per-request statistics: min: 0.00ms avg: 0.16ms max: 1066.04ms approx. 95 percentile: 0.02ms Threads fairness: events (avg/stddev): 13107.2000/3870.38 execution time (avg/stddev): 2.0506/0.28
Test execution summary: total time: 12.5606s total number of events: 100 total time taken by event execution: 1164.4236 per-request statistics: min: 9551.87ms avg: 11644.24ms max: 12525.32ms approx. 95 percentile: 12326.25ms Threads fairness: events (avg/stddev): 1.0000/0.00 execution time (avg/stddev): 11.6442/0.59
# 下面的測試命令表明的是:對mysql進行oltp基準測試 # 表數量10 # 每錶行數約50w(幾乎delete多少就會insert的多少),而且是非事務的只讀測試 # 持續60s # 併發線程數12。 #1.prepare sysbench --test=/tmp/sysbench/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua \ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root \ --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=500000 \ --report-interval=3 --oltp-dist-type=uniform --rand-init=on --max-requests=0 \ --oltp-read-only=on --oltp-skip-trx=on \ --max-time=120 --num-threads=12 prepare #2.run sysbench --test=/tmp/sysbench/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua \ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root \ --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=500000 \ --report-interval=3 --oltp-dist-type=uniform --rand-init=on --max-requests=0 \ --oltp-read-only=on --oltp-skip-trx=on \ --max-time=120 --num-threads=12 run } #3.clean sysbench --test=/tmp/sysbench/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua \ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root \ --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=500000 \ --report-interval=3 --oltp-dist-type=uniform --rand-init=on --max-requests=0 \ --oltp-read-only=on --oltp-skip-trx=on \ --max-time=120 --num-threads=12 clean
--test=/tmp/sysbench/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua 表示調用 tests/db/oltp.lua 腳本進行 oltp 模式測試 --mysql-table-engine=innodb 表示選擇測試表的存儲引擎 --oltp_tables_count=10 表示會生成 10 個測試表 --oltp-table-size=100000 表示每一個測試表填充數據量爲 100000 --rand-init=on 表示每一個測試表都是用隨機數據來填充的 若是在本機,也可使用 –mysql-socket 指定 socket 文件來鏈接。加載測試數據時長視數據量而定,若過程比較久須要稍加耐心等待。
--oltp-read-only=off 表示不要進行只讀測試,也就是會採用讀寫混合模式測試 --report-interval=10 表示每10秒輸出一次測試進度報告 --rand-type=uniform 表示隨機類型爲固定模式,其餘幾個可選隨機模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累託) --max-time=120 表示最大執行時長爲 120秒 --max-requests=0 表示總請求數爲 0,由於上面已經定義了總執行時長,因此總請求數能夠設定爲 0;也能夠只設定總請求數,不設定最大執行時長 --percentile=99 表示設定採樣比例,默認是 95%,即丟棄1%的長請求,在剩餘的99%裏取最大值
#mysql-db=sbtest:測試使用的目標數據庫,這個庫名要事先建立 #--oltp-tables-count=10:產生表的數量 #--oltp-table-size=500000:每一個表產生的記錄行數 #--oltp-dist-type=uniform:指定隨機取樣類型,可選值有 uniform(均勻分佈), Gaussian(高斯分佈), special(空間分佈)。默認是special #--oltp-read-only=off:表示不止產生只讀SQL,也就是使用oltp.lua時會採用讀寫混合模式。默認 off,若是設置爲on,則不會產生update,delete,insert的sql。 #--oltp-test-mode=nontrx:執行模式,這裏是非事務式的。可選值有simple,complex,nontrx。默認是complex #simple:簡單查詢,SELECT c FROM sbtest WHERE id=N #complex (advanced transactional):事務模式在開始和結束事務以前加上begin和commit, 一個事務裏能夠有多個語句,如點查詢、範圍查詢、排序查詢、更新、刪除、插入等,而且爲了避免破壞測試表的數據,該模式下一條記錄刪除後會 在同一個事務裏添加一條相同的記錄。 #nontrx (non-transactional):與simple類似,可是能夠進行update/insert等操做,因此若是作連續的對比壓測,你可能須要從新cleanup,prepare。 #--oltp-skip-trx=[on|off]:省略begin/commit語句。默認是off # #--rand-init=on:是否隨機初始化數據,若是不隨機化那麼初始好的數據每行內容除了主鍵不一樣外其餘徹底相同 # #--num-threads=12: 併發線程數,能夠理解爲模擬的客戶端併發鏈接數 #--report-interval=10:表示每10s輸出一次測試進度報告 #--max-requests=0:壓力測試產生請求的總數,若是如下面的max-time來記,這個值設爲0 #--max-time=120:壓力測試的持續時間,這裏是2分鐘。
結果輸出例子:併發
#每10秒鐘報告一次測試結果,tps、每秒讀、每秒寫、95%以上的響應時長統計 [ 10s] threads: 8, tps: 66.60, reads: 943.67, writes: 269.62, response time: 431.72ms (95%), errors: 0.00, reconnects: 0.00 [ 20s] threads: 8, tps: 34.30, reads: 480.20, writes: 137.20, response time: 598.28ms (95%), errors: 0.00, reconnects: 0.00 [ 30s] threads: 8, tps: 36.60, reads: 512.40, writes: 146.40, response time: 494.87ms (95%), errors: 0.00, reconnects: 0.00 OLTP test statistics: queries performed: read: 941248 #讀總數 write: 268928 #寫總數 other: 134464 #其餘操做總數(SELECT、INSERT、UPDATE、DELETE以外的操做,例如COMMIT等) total: 1344640 #所有總數 transactions: 67232 (112.04 per sec.) #總事務數(每秒事務數) read/write requests: 1210176 (2016.73 per sec.) #讀寫總數(每秒讀寫次數) other operations: 134464 (224.08 per sec.) #其餘操做總數(每秒其餘操做次數) ignored errors: 0 (0.00 per sec.) reconnects: 0 (0.00 per sec.) General statistics: total time: 600.0698s #總耗時 total number of events: 67232 #共發生多少事務數 total time taken by event execution: 4799.8569s # 全部事務耗時相加(不考慮並行因素) response time: min: 2.09ms #最小耗時 avg: 71.39ms #平均耗時 max: 839.32ms #最大耗時 approx. 95 percentile: 309.40ms 超過95%平均耗時 Threads fairness: events (avg/stddev): 8404.0000/17.56 execution time (avg/stddev): 599.9821/0.02