介紹 sysbench是一個模塊化、跨平臺、多線程基準測試工具,主要用於測試不同系統參數下的資料庫負載情況,本文主要介紹0.4版本的使用。sysbench主要用於以下性能測試: 文件I/O性能 調度 記憶體分配和傳輸 POSIX線程 資料庫 安裝 1.安裝插件 yum install libtool ...
介紹
sysbench是一個模塊化、跨平臺、多線程基準測試工具,主要用於測試不同系統參數下的資料庫負載情況,本文主要介紹0.4版本的使用。sysbench主要用於以下性能測試:
- 文件I/O性能
- 調度
- 記憶體分配和傳輸
- POSIX線程
- 資料庫
安裝
1.安裝插件
yum install libtool -y
2.安裝
./configure --prefix=/usr/local/sysbench-0.4.12 --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib make make install cp -r sysbench/tests /usr/local/sysbench-0.4.12 ln -s /usr/local/sysbench-0.4.12/bin/sysbench /usr/local/sysbench-0.4.12/sysbench
修改環境變數,在環境變數中加入
export LD_LIBRARY_PATH=/usr/local/mysql/lib
註意:如果安裝目錄中沒有configure那麼需要執行以下操作:
chmod +x autogen.sh
./autogen.sh
如果想要讓 sysbench 支持 oracle /pgsql 的話,就需要在編譯的時候加上參數
--with-oracle
或者
--with-pgsql
一般語法
prepare:用於文件IO和資料庫OLTP測試的數據準備階段。
run:性能測試階段
cleanup:移除測試過程中產生的數據
help:顯示幫助信息,獲取--test幫助可以使用--test=name --help
通用命令選項
這部分命令參數的通用的,不管--test測試什麼內容都可以使用這些通用的命令。可以執行sysbench --help瞭解各參數的具體解釋
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] --forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off] --thread-stack-size=SIZE size of stack per thread [32K] --init-rng=[on|off] initialize random number generator [off] --seed-rng=N seed for random number generator, ignored when 0 [0] --tx-rate=N target transaction rate (tps) [0] --tx-jitter=N target transaction variation, in microseconds [0] --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] --report-checkpoints=[LIST,...]dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. [] --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 --version=[on|off] print version and exit Log options: --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [4] --percentile=N percentile rank of query response times to count [95] 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 version See 'sysbench --test=<name> help' for a list of options for each test.
主要的參數有:
--num-threads、
--max-requests、
--test
以下幾個參數也經常會使用:
--max-time 最大的測試時長
--debug(開啟debug可以顯示更詳細的每個線程的執行情況)
CPU測試
對CPU的性能測試通常有:1. 通過算質數;2計算圓周率等;sysbench使用的就是通過質數相加的測試。對CPU測試直接運行run即可
./sysbench --num-threads=12 --max-requests=10000 --debug=on --test=cpu --cpu-max-prime=20000 run
上面的測試是:12個線程執行1萬條請求,每個請求執行質數相加到20000
thread測試
測試線程調度的性能,用於高負載下的線程性能測試。
--thread-yields=N 每個請求執行“lock/yield/unlock”迴圈的次數,預設1000
--thread-locks=N 每個線程的互斥鎖,預設8個
./sysbench --num-threads=12 --max-requests=10000 --test=threads --thread-yields=100 --thread-locks=2 run
memory測試
記憶體分配測試,主要是針對不同的塊大小進行記憶體的連續讀寫或者隨機讀寫測試。
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]
1.8k順序分配
./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run sysbench 0.4.12.10: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 12 Random number generator seed is 0 and will be ignored Doing memory operations speed test Memory block size: 8K Memory transfer size: 102400M Memory operations type: write Memory scope type: global Threads started! Done. Operations performed: 13107200 (993893.95 ops/sec) 102400.00 MB transferred (7764.80 MB/sec) General statistics: total time: 13.1877s total number of events: 13107200 total time taken by event execution: 91.9173 response time: min: 0.00ms avg: 0.01ms max: 0.93ms approx. 95 percentile: 0.02ms Threads fairness: events (avg/stddev): 1092266.6667/4629.30 execution time (avg/stddev): 7.6598/0.02View Code
報告:時間13S,7.7G/S
2.8k隨機分配
./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run sysbench 0.4.12.10: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 12 Random number generator seed is 0 and will be ignored Doing memory operations speed test Memory block size: 8K Memory transfer size: 102400M Memory operations type: write Memory scope type: global Threads started! Done. Operations performed: 13107200 (1036066.63 ops/sec) 102400.00 MB transferred (8094.27 MB/sec) General statistics: total time: 12.6509s total number of events: 13107200 total time taken by event execution: 71.5377 response time: min: 0.00ms avg: 0.01ms max: 0.90ms approx. 95 percentile: 0.02ms Threads fairness: events (avg/stddev): 1092266.6667/19850.15 execution time (avg/stddev): 5.9615/0.02View Code
報告:12.6S,8G/s
3.16K順序分配
./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=16K --memory-total-size=100G --memory-access-mode=seq run
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=16K --memory-total-size=100G --memory-access-mode=seq run sysbench 0.4.12.10: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 12 Random number generator seed is 0 and will be ignored Doing memory operations speed test Memory block size: 16K Memory transfer size: 102400M Memory operations type: write Memory scope type: global Threads started! Done. Operations performed: 6553600 (832528.85 ops/sec) 102400.00 MB transferred (13008.26 MB/sec) General statistics: total time: 7.8719s total number of events: 6553600 total time taken by event execution: 63.7133 response time: min: 0.00ms avg: 0.01ms max: 0.90ms approx. 95 percentile: 0.02ms Threads fairness: events (avg/stddev): 546133.3333/1321.35 execution time (avg/stddev): 5.3094/0.01View Code
報告:7S,13G/S
4.16K隨機分配
./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=16K --memory-total-size=100G --memory-access-mode=rnd run
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=16K --memory-total-size=100G --memory-access-mode=rnd run sysbench 0.4.12.10: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 12 Random number generator seed is 0 and will be ignored Doing memory operations speed test Memory block size: 16K Memory transfer size: 102400M Memory operations type: write Memory scope type: global Threads started! Done. Operations performed: 6553600 (1018696.38 ops/sec) 102400.00 MB transferred (15917.13 MB/sec) General statistics: total time: 6.4333s total number of events: 6553600 total time taken by event execution: 36.1789 response time: min: 0.00ms avg: 0.01ms max: 0.88ms approx. 95 percentile: 0.02ms Threads fairness: events (avg/stddev): 546133.3333/5577.58 execution time (avg/stddev): 3.0149/0.01 [root@localhost sysbench-0.4.12]#View Code
報告:6.4S,15G/s
總結:對於分配同樣大小的記憶體,塊月大分配的速率越快,隨機分配比順序分配的速度要快
文件io測試
./sysbench --test=fileio help
文件IO的測試主要用於測試IO的負載性能。主要的測試選項為--file-test-mode。還有幾個可以關註的參數包括--file-block-size、--file-io-mode、--file-fsync-freq 、--file-rw-ratio
--file-num=N 創建測試文件的數量,預設128個 --file-block-size=N block size大小,預設16K --file-total-size=SIZE 所有文件的總大小,預設2G --file-test-mode=STRING 測試類型 {seqwr(順序寫), seqrewr(順序讀寫), seqrd(順序讀), rndrd(隨機讀), rndwr(隨機寫), rndrw(隨機讀寫)} --file-io-mode=STRING I/O模式,需要系統支持預設sync[sync(同步IO),async(非同步IO),mmap()] --file-async-backlog=N 每個線程的非同步操作隊列數,預設128個,需要--file-io-mode=async; --file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} [] --file-fsync-freq=N 當請求數達到多少時執行fsync()刷新,預設100,0代表過程中不執行fsync() --file-fsync-all=[on|off] 執行每一個寫操作後執行fsync()刷新操作,預設關閉off --file-fsync-end=[on|off] 測試結束執行fsync()操作,預設開啟on --file-fsync-mode=STRING 同步刷新方法,預設fsync {fsync, fdatasync} --file-merged-requests=N 合併指定數量的IO請求,0代表不合併,預設0 --file-rw-ratio=N 讀寫比例,預設1.5/1
./sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=3G --file-test-mode=rndrw prepare ./sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=3G --file-test-mode=rndrw run ./sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=3G --file-test-mode=rndrw clean
上圖中的第二部分的包括內容反映了當前系統的io性能大概:38M/S
互斥鎖測試
互斥鎖測試模擬所有線程在同一時刻併發運行
./sysbench --num-threads=12 --test=mutex --mutex-num=1024 --mutex-locks=10000 --mutex-loops=10000 run
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --test=mutex --mutex-num=1024 --mutex-locks=10000 --mutex-loops=10000 run sysbench 0.4.12.10: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 12 Random number generator seed is 0 and will be ignored Doing mutex performance test Threads started! Done. General statistics: total time: 0.0869s total number of events: 12 total time taken by event execution: 1.0301 response time: min: 83.86ms avg: 85.84ms max: 86.88ms approx. 95 percentile: 86.78ms Threads fairness: events (avg/stddev): 1.0000/0.00 execution time (avg/stddev): 0.0858/0.00
oltp測試
oltp是針對資料庫的基準測試,例如每次對資料庫進行優化後執行基準測試來測試不同的配置的tps。可以通過以下命令瞭解它的有關參數:
./sysbench --test=oltp help
--oltp-test-mode=STRING 測試類型:simple(簡單select測試),complex(事務測試),nontrx(非事務測試),sp(存儲過程) ;預設complex --oltp-reconnect-mode=STRING 連接類型:session(每個線程到測試結束不重新連接),transaction(執行每個事務重新連接),query(每一個查詢重新連接),random(隨機);預設 [session] --oltp-sp-name=STRING 指定執行測試的存儲過程名 --oltp-read-only=[on|off] 僅執行select測試,預設關閉 --oltp-avoid-deadlocks=[on|off] 更新過程中忽略死鎖,預設[off] --oltp-skip-trx=[on|off] 語句以bigin/commit開始結尾,預設[off] --oltp-range-size=N 範圍查詢的範圍大小,預設 [100],例如begin 100 and 200 --oltp-point-selects=N 單個事務中select查詢的數量,預設 [10] --oltp-use-in-statement=N 每個查詢中主鍵查找(in 10個值)的數量,預設 [0] --oltp-simple-ranges=N 單個事務中執行範圍查詢的數量(SELECT c FROM sbtest WHERE id BETWEEN N AND M),預設[1] --oltp-sum-ranges=N 單個事務中執行範圍sum查詢的數量,預設 [1] --oltp-order-ranges=N 單個事務中執行範圍order by查詢的數量,預設[1] --oltp-distinct-ranges=N 單個事務中執行範圍distinct查詢的數量,預設[1] --oltp-index-updates=N 單個事務中執行索引更新的操作的數量,預設[1] --oltp-non-index-updates=N 單個事務中執行非索引更新操作的數量,預設[1] --oltp-nontrx-mode=STRING 指定單獨非事務測試類型進行測試,預設select {select, update_key, update_nokey, insert, delete} [select] --oltp-auto-inc=[on|off] id列預設自增,預設[on] --oltp-connect-delay=N 指定每一次重新連接延時的時長,預設1秒 [10000] --oltp-user-delay-min=N minimum time in microseconds to sleep after each request [0] --oltp-user-delay-max=N maximum time in microseconds to sleep after each request [0] --oltp-table-name=STRING 指定測試的表名,預設[sbtest] --oltp-table-size=N 指定表的記錄大小,預設[10000] --oltp-dist-type=STRING 隨機數分佈狀態。uniform(均勻分佈)、gauss(高斯分佈)、special(特殊分佈),預設 [special] --oltp-dist-iter=N number of iterations used for numbers generation [12] --oltp-dist-pct=N 啟用百分比特殊分佈,預設 [1] --oltp-dist-res=N special 百分比[75] --oltp-point-select-mysql-handler=[on|off] Use MySQL HANDLER for point select [off] --oltp-point-select-all-cols=[on|off] select查詢測試時select所有列,預設[off] --oltp-secondary=[on|off] 索引不是主鍵索引而是二級索引,預設[off] --oltp-num-partitions=N 指定表分區的數量,預設 [0] --oltp-num-tables=N 指定測試表的數量,預設[1] General database options: --db-driver=STRING 指定測試資料庫類型,預設mysql --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto] 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 []
oltp測試主要會有以下相關參數的測試,,其它相關參數預設即可,有需求也可以自定義:
--mysql-engine-trx=STRING 指定不同的存儲引擎測試。 --oltp-test-mode=STRING 測試類型:simple(簡單select測試),complex(事務測試),nontrx(非事務測試),sp(存儲過程) ;預設complex --oltp-sp-name=STRING 指定存儲過程進行語句測試 --oltp-table-size=N 指定表的記錄大小,預設[10000] --oltp-num-tables=N 指定測試表的數量,預設[1]
需要先創建好測試資料庫sbtest。
1.事務測試,測試12個線程執行1萬條請求,10個表,每個表大小100W
./sysbench --num-threads=12 --max-requests=100000 --test=oltp --mysql-user=root --mysql-password=root --oltp-test-mode=complex --mysql-db=sbtest --oltp-table-size=1000000 --oltp-num-tables=10 prepare
./sysbench --num-threads=12 --max-requests=100000 --test=oltp --mysql-user=root --mysql-password=root --oltp-test-mode=complex --mysql-db=sbtest --oltp-table-size=1000000 --oltp-num-tables=10 run
./sysbench --num-threads=12 --max-requests=100000 --test=oltp --mysql-user=root --mysql-password=root --oltp-test-mode=complex --mysql-db=sbtest --oltp-table-size=1000000 --oltp-num-tables=10 cleanup
[root@localhost sysbench-0.4.12]# ./sysbench --num-threads=12 --max-requests=100000 --test=oltp --mysql-user=root --mysql-password=root --oltp-test-mode=complex --mysql-db=sbtest --oltp-table-size=1000000 --oltp-num-tables=10 run sysbench 0.4.12.10: multi-threaded system evaluation benchmark No DB drivers specified, using mysql Running the test with following options: Number of threads: 12 Random number generator seed is 0 and will be ignored Doing OLTP test. Running mixed OLTP test Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases) Using "BEGIN" for starting transactions Using auto_inc on the id column Maximum number of requests for OLTP test is limited to 100000 Using 10 test tables Threads started! Done. OLTP test statistics: queries performed: read: 1400910 write: 500325 other: 200130 total: 2101365 transactions: 100065 (791.94 per sec.) deadlocks: 0 (0.00 per sec.) read/write requests: 1901235 (15046.89 per sec.) other operations: 200130 (1583.88 per sec.) General statistics: total time: 126.3540s total number of events: 100065 total time taken by event execution: 1513.9202 response time: min: 5.82ms avg: 15.13ms max: 2352.66ms approx. 95 percentile: 18.00ms Threads fairness: events (avg/stddev): 8338.7500/207.
報告:執行當前測試花費126S,TPS:791/S,RQ:15046/S,95%的請求花費18毫秒
事務測試,每個事務包含如下語句:
Point queries: SELECT c FROM sbtest WHERE id= N Range queries: SELECT c FROM sbtest WHERE id BETWEEN N AND M Range SUM() queries: SELECT SUM(K) FROM sbtest WHERE id BETWEEN N and M Range ORDER BY queries: SELECT c FROM sbtest WHERE id between N and M ORDER BY c Range DISTINCT queries: SELECT DISTINCT c FROM sbtest WHERE id BETWEEN N and M ORDER BY c UPDATEs on index column: UPDATE sbtest SET k=k+1 WHERE id= N UPDATEs on non-index column: UPDATE sbtest SET c= N WHERE id= M DELETE queries: DELETE FROM sbtest WHERE id= N INSERT queries: INSERT INTO sbtest VALUES ( ...
非事務測試,執行語句如下
Point queries: SELECT pad FROM sbtest WHERE id= N UPDATEs on index column: UPDATE sbtest SET k=k+1 WHERE id= N UPDATEs on non-index column: UPDATE sbtest SET c= N WHERE id= M DELETE queries: DELETE FROM sbtest WHERE id= N The generated row IDs are unique over each test run, so no row is deleted twice. INSERT queries: INSERT INTO sbtest (k, c, pad) VALUES( N , M , S )
總結
sysbench是使用最廣泛的基準壓測工具,功能也很齊全報告也非常的詳細。
備註: 作者:pursuer.chen 博客:http://www.cnblogs.com/chenmh 本站點所有隨筆都是原創,歡迎大家轉載;但轉載時必須註明文章來源,且在文章開頭明顯處給明鏈接。 《歡迎交流討論》 |