sysbench是一個模塊化的啊研、跨平臺御滩、多線程基準(zhǔn)測試工具,主要用于評估測試各種不同系統(tǒng)參數(shù)下的數(shù)據(jù)庫負(fù)載情況悲伶。
它主要包括以下幾種方式的測試:
1艾恼、cpu性能
2住涉、磁盤io性能
3麸锉、調(diào)度程序性能
4、內(nèi)存分配及傳輸速度
5舆声、POSIX線程性能
6花沉、數(shù)據(jù)庫性能(OLTP基準(zhǔn)測試)
目前sysbench主要支持 MySQL,pgsql,oracle 這3種數(shù)據(jù)庫柳爽。
一、sysbench安裝
首先碱屁,在 http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgz
下載源碼包磷脯。下載解壓后進(jìn)入安裝。
[root@localhost src]# tar zxvf sysbench-0.4.12-1.1.tgz
[root@localhost src]# cd sysbench-0.4.12-1.1
[root@localhost sysbench-0.4.12-1.1]# ls
autogen.sh configure.ac install-sh missing README-WIN.txt
ChangeLog COPYING m4 mkinstalldirs sysbench
config doc Makefile.am README TODO
解壓后發(fā)現(xiàn)娩脾,并沒有配置文件configure
這里需要直接運(yùn)行sysbench提供的腳本autogen.sh赵誓,運(yùn)行腳本autogen.sh之前,需要通過yum安裝環(huán)境
[root@localhost sysbench-0.4.12-1.1]# yum install m4 autoconf automake libtool
[root@localhost sysbench-0.4.12-1.1]# ./autogen.sh
生成文件配置文件之后柿赊,進(jìn)入配置階段俩功,如果你的mysql是標(biāo)準(zhǔn)安裝的話,可以直接運(yùn)行碰声,進(jìn)行安裝诡蜓。
[root@localhost sysbench-0.4.12-1.1]# ./configure
[root@localhost sysbench-0.4.12-1.1]# make && make install
如果不是mysql不是標(biāo)準(zhǔn)安裝的話,需要在配置文件中指定
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib --with-mysql
其中參數(shù):–with-mysql-includes的地址是mysql.h所在的目錄胰挑,可以通過find / -name mysql.h進(jìn)行查找
–with-mysql-libs的地址是libmysqlclient.so所在的目錄蔓罚,可以通過find / -name libmysqlclient.so進(jìn)行查找
配置完成之后就可以直接make && make install。
安裝過程中瞻颂,錯誤總結(jié):
錯誤提示1:
[root@localhost sysbench-0.4.12-1.1]# ./autogen.sh
automake 1.10.x (aclocal) wasn't found, exiting
通過yum安裝automake
[root@localhost sysbench-0.4.12-1.1]# yum -y install automake
錯誤提示2:
[root@localhost sysbench-0.4.12-1.1]# ./autogen.sh
libtoolize 1.4+ wasn't found, exiting
通過yun安裝libtool即可
[root@localhost sysbench-0.4.12-1.1]# yum -y install libtool
在運(yùn)行sysbench的時候豺谈,遇到:error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
這說明sysbench無法找到mysql的庫文件,這很可能是環(huán)境變量LD_LIBRARY_PATH沒有設(shè)置蘸朋,設(shè)置后即可解決該問題:
執(zhí)行bash代碼:export LD_LIBRARY_PATH=/usr/local/mysql/lib 可以臨時的修改環(huán)境變量核无,終端斷開之后,就會丟失 也可以在/etc/profile中添加export LD_LIBRARY_PATH=/usr/local/mysql/lib藕坯,永久的修改团南,這樣修改需要重啟機(jī)器就會永久生效。
安裝完成之后炼彪,開始做基準(zhǔn)測試吐根。
二、sysbench使用
sysbench常用參數(shù)詳解:
[root@localhost src]# sysbench
General options: #通用選項
--num-threads=N number of threads to use [1]#線程數(shù)辐马,默認(rèn)是1
--max-requests=N limit for total number of requests [10000]#請求限制拷橘,默認(rèn)是10000,0表示不限制
--max-time=N limit for total execution time in seconds [0]#最大執(zhí)行時間喜爷,默認(rèn)是0冗疮,表示不限制
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]#超時強(qiáng)制中斷,默認(rèn)關(guān)閉
--thread-stack-size=SIZE size of stack per thread [64K]#每個線程的堆棧大小檩帐,默認(rèn)是64K
--tx-rate=N target transaction rate (tps) [0]#嘗試像數(shù)據(jù)庫發(fā)送的事務(wù)數(shù)tps
--report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]#表示N秒輸出一次測試進(jìn)度報告术幔,0表示關(guān)閉測試進(jìn)度報告輸出,僅輸出最終的報告結(jié)果湃密,默認(rèn)值為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]#debug模式輸出四敞,默認(rèn)值為off。
--validate=[on|off] perform validation checks where possible [off]#在可能的情況下執(zhí)行驗證檢查拔妥,默認(rèn)為off忿危。
--help=[on|off] print help and exit#輸出help信息,默認(rèn)為off没龙。
--version=[on|off] print version and exit [off]#輸出版本信息铺厨,默認(rèn)為off。
--rand-init=[on|off] initialize random number generator [off]#初始化迭代器
--rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
表示隨機(jī)類型的模式硬纤,共有4種模式:uniform(固定)努释,gaussian(高斯)?,special(特定)咬摇,pareto(帕雷特)伐蒂,默認(rèn)值為:special。
--rand-spec-iter=N number of iterations used for numbers generation [12]#
--rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]
--rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]
--rand-seed=N seed for random number generator, ignored when 0 [0]
--rand-pareto-h=N parameter h for pareto distibution [0.2]
sysbench基準(zhǔn)測試cpu肛鹏,先查看幫助文檔
[root@localhost db]# sysbench --test=cpu help
sysbench 0.5: multi-threaded system evaluation benchmark
cpu options:
--cpu-max-prime=N upper limit for primes generator [10000]#素數(shù)生成上限逸邦,默認(rèn)是10000
sysbench對CPU的性能測試就是通過素數(shù)相加的測試。
[root@localhost db]# sysbench --num-threads=10 --max-requests=1000 --test=cpu --cpu-max-prime=20000 run #10個線程在扰,執(zhí)行1000個請求缕减,每個請求加到20000
執(zhí)行結(jié)果:
[root@localhost db]# sysbench --num-threads=10 --max-requests=1000 --test=cpu --cpu-max-prime=20000 run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 10 #線程數(shù)
Random number generator seed is 0 and will be ignored
Primer numbers limit: 20000 #素數(shù)生成上限
Threads started!
General statistics:
total time: 3.9331s #總耗時
total number of events: 1000 #事務(wù)總數(shù)
total time taken by event execution: 39.1176s #事件執(zhí)行所花費的總時間
response time: #響應(yīng)時間
min: 16.69ms #最小
avg: 39.12ms #平均
max: 76.07ms #最大
approx. 95 percentile: 51.44ms #95%以上的響應(yīng)時間
Threads fairness:
events (avg/stddev): 100.0000/0.00
execution time (avg/stddev): 3.9118/0.01
cpu性能測試:計算范圍內(nèi)素數(shù)相加時間越短越好
sysbench基準(zhǔn)測試文件io,先查看幫助文檔
[root@localhost src]# sysbench --test=fileio help #查看幫助
sysbench 0.5: multi-threaded system evaluation benchmark #多線程系統(tǒng)評測基準(zhǔn)
fileio options:
--file-num=N number of files to create [128] #創(chuàng)建的文件數(shù)目芒珠,默認(rèn)是128
--file-block-size=N block size to use in all IO operations [16384]#測試文件塊的大小桥狡,默認(rèn)是16384bite
--file-total-size=SIZE total size of files to create [2G]#創(chuàng)建的文件的總大小,默認(rèn)是2G
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}#讀寫模式
seqwr, 順序?qū)? seqrewr, 順序讀寫 seqrd, 順序讀 rndrd, 隨機(jī)讀 rndwr, 隨機(jī)寫 rndrw,隨機(jī)讀寫
--file-io-mode=STRING file operations mode {sync,async,mmap} [sync]# 文件操作模式皱卓,同步裹芝,異步
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []#使用額外的標(biāo)志來打開文件,默認(rèn)為空
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]#執(zhí)行fsync的頻率娜汁,0表示不使用fsync嫂易,默認(rèn)是100
fsync:同步內(nèi)存中的數(shù)據(jù)到硬盤
--file-fsync-all=[on|off] do fsync() after each write operation [off]#每執(zhí)行完一個操作就執(zhí)行一次fsync,默認(rèn)關(guān)閉
--file-fsync-end=[on|off] do fsync() at the end of test [on]#在測試結(jié)束的時候才執(zhí)行 fsync
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]#使用哪種方法來同步掐禁,fsync或者fdatasync
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]#如果可以合并最多的io請求數(shù)怜械,0不合并,默認(rèn)是0
--file-rw-ratio=N reads/writes ratio for combined test [1.5]#測試時候的讀寫比例默認(rèn)是1.5
文件io的測試步驟是:準(zhǔn)備測試文件傅事,運(yùn)行測試文件缕允,刪除測試文件
通過sysbench生成測試文件prepare:
[root@localhost sysbench_test]# sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=10G --file-test-mode=rndrw prepare
運(yùn)行run
[root@localhost sysbench_test]# sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=10G --file-test-mode=rndrw run
刪除測試文件
[root@localhost sysbench_test]# sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=10G --file-test-mode=rndrw cleanup
結(jié)果分析
[root@localhost sysbench_test]# sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=10G --file-test-mode=rndrw run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 12 #線程數(shù)
Random number generator seed is 0 and will be ignored
Extra file open flags: 0
128 files, 80Mb each
10Gb total file size #文件的總大小
Block size 16Kb
Number of IO requests: 10000
Read/Write ratio for combined random IO test: 1.50 #io讀寫比例
Periodic FSYNC enabled, calling fsync() each 100 requests. #每100個請求執(zhí)行fsync()
Calling fsync() at the end of test, Enabled. #測試完成的時候執(zhí)行一次fsync()
Using synchronous I/O mode
Doing random r/w test
Threads started!
Operations performed:
5999 reads,
4001 writes, 12800 Other = 22800 Total
Read 93.734Mb
Written 62.516Mb
Total transferred
156.25Mb (288.61Mb/sec)#吞吐量
18471.19 Requests/sec executed#每秒請求數(shù)
General statistics:
total time: 0.5414s#時間
total number of events: 10000#時間數(shù)量
total time taken by event execution: 3.9134s#執(zhí)行時間的時間
response time:
min: 0.00ms#最短
avg: 0.39ms#平均
max: 29.75ms#最長
approx. 95 percentile: 1.68ms #95%以上事件響應(yīng)事件
Threads fairness:
events (avg/stddev): 833.3333/70.29
execution time (avg/stddev): 0.3261/0.03
io性能指標(biāo)有:每秒鐘請求數(shù)、吞吐量蹭越、95%以上事件響應(yīng)時間障本。不同場景下io tps越大越好
sysbench基準(zhǔn)測試oltp,0.5版本之后oltp的參數(shù)沒找到般又,在網(wǎng)上找了一份參數(shù)詳解過來
--oltp-test-mode=STRING 測試類型:simple(簡單select測試),complex(事務(wù)測試),nontrx(非事務(wù)測試),sp(存儲過程) 彼绷;默認(rèn)complex
--oltp-reconnect-mode=STRING 連接類型:session(每個線程到測試結(jié)束不重新連接),transaction(執(zhí)行每個事務(wù)重新連接),query(每一個查詢重新連接),random(隨機(jī));默認(rèn) [session]
--oltp-sp-name=STRING 指定執(zhí)行測試的存儲過程名
--oltp-read-only=[on|off] 僅執(zhí)行select測試茴迁,默認(rèn)關(guān)閉
--oltp-avoid-deadlocks=[on|off] 更新過程中忽略死鎖寄悯,默認(rèn)[off]
--oltp-skip-trx=[on|off] 語句以bigin/commit開始結(jié)尾,默認(rèn)[off]
--oltp-range-size=N 范圍查詢的范圍大小堕义,默認(rèn) [100]猜旬,例如begin 100 and 200
--oltp-point-selects=N 單個事務(wù)中select查詢的數(shù)量,默認(rèn) [10]
--oltp-use-in-statement=N 每個查詢中主鍵查找(in 10個值)的數(shù)量倦卖,默認(rèn) [0]
--oltp-simple-ranges=N 單個事務(wù)中執(zhí)行范圍查詢的數(shù)量(SELECT c FROM sbtest WHERE id BETWEEN N AND M)洒擦,默認(rèn)[1]
--oltp-sum-ranges=N 單個事務(wù)中執(zhí)行范圍sum查詢的數(shù)量,默認(rèn) [1]
--oltp-order-ranges=N 單個事務(wù)中執(zhí)行范圍order by查詢的數(shù)量怕膛,默認(rèn)[1]
--oltp-distinct-ranges=N 單個事務(wù)中執(zhí)行范圍distinct查詢的數(shù)量熟嫩,默認(rèn)[1]
--oltp-index-updates=N 單個事務(wù)中執(zhí)行索引更新的操作的數(shù)量,默認(rèn)[1]
--oltp-non-index-updates=N 單個事務(wù)中執(zhí)行非索引更新操作的數(shù)量褐捻,默認(rèn)[1]
--oltp-nontrx-mode=STRING 指定單獨非事務(wù)測試類型進(jìn)行測試掸茅,默認(rèn)select {select, update_key, update_nokey, insert, delete} [select]
--oltp-auto-inc=[on|off] id列默認(rèn)自增,默認(rèn)[on]
--oltp-connect-delay=N 指定每一次重新連接延時的時長柠逞,默認(rè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 指定測試的表名昧狮,默認(rèn)[sbtest]
--oltp-table-size=N 指定表的記錄大小,默認(rèn)[10000]
--oltp-dist-type=STRING 隨機(jī)數(shù)分布狀態(tài)板壮。uniform(均勻分布)逗鸣、gauss(高斯分布)、special(特殊分布)绰精,默認(rèn) [special]
--oltp-dist-iter=N number of iterations used for numbers generation [12]
--oltp-dist-pct=N 啟用百分比特殊分布撒璧,默認(rè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所有列,默認(rèn)[off]
--oltp-secondary=[on|off] 索引不是主鍵索引而是二級索引笨使,默認(rèn)[off]
--oltp-num-partitions=N 指定表分區(qū)的數(shù)量沪悲,默認(rèn) [0]
--oltp-num-tables=N 指定測試表的數(shù)量,默認(rèn)[1]
General database options:
--db-driver=STRING 指定測試數(shù)據(jù)庫類型阱表,默認(rèn)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 []
在0.5版本的mysql測試的時候殿如,用到oltp.lua腳本,在解壓的安裝包中可以找到
[root@localhost db]# pwd
/usr/local/src/sysbench-0.4.12-1.1/sysbench/tests/db
[root@localhost db]# ls
common.lua insert.lua Makefile.am oltp.lua parallel_prepare.lua select_random_points.lua update_index.lua
delete.lua Makefile Makefile.in oltp_simple.lua select.lua select_random_ranges.lua update_non_index.lua
操作步驟:準(zhǔn)備數(shù)據(jù)最爬,運(yùn)行測試涉馁,刪除數(shù)據(jù)
[root@localhost db]# sysbench --test=./oltp.lua --oltp-table-size=2000000 --mysql-host=localhost --mysql-user=root --mysql-password=111111 prepare
[root@localhost db]# sysbench --test=./oltp.lua --oltp-table-size=2000000 --mysql-host=localhost --mysql-user=root --mysql-password=111111 run
[root@localhost db]# sysbench --test=./oltp.lua --oltp-table-size=2000000 --mysql-host=localhost --mysql-user=root --mysql-password=111111 cleanup
結(jié)果分析:
Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored
Threads started!
OLTP test statistics:
queries performed:
read: 140000 #讀總數(shù)
write: 40000 #寫總數(shù)
other: 20000 #其他總數(shù)(除select insert delete update之外的,比如commit)
total: 200000 #全部總數(shù)
transactions: 10000 (137.75 per sec.) #總事務(wù)數(shù)(每秒事務(wù)數(shù))
deadlocks: 0 (0.00 per sec.)#發(fā)生死鎖總數(shù)
read/write requests: 180000 (2479.53 per sec.)#讀寫總數(shù)(每秒讀此書)
other operations: 20000 (275.50 per sec.)#其他操作次數(shù)(每秒其他操作次數(shù))
General statistics:
total time: 72.5943s #總耗時間
total number of events: 10000 #總事務(wù)數(shù)
total time taken by event execution: 72.5352s #所有事務(wù)耗時相加(不考慮并行因素)
response time:#響應(yīng)時間
min: 3.16ms #最短
avg: 7.25ms#平均
max: 1103.70ms#最長
approx. 95 percentile: 13.28ms#95%的響應(yīng)時間
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 72.5352/0.00
oltp測試結(jié)果需要參考的數(shù)據(jù)有:
response time avg: 平均響應(yīng)時間爱致。(后面的95%的大小可以通過–percentile=98的方式去更改)
transactions: 精確的說是這一項后面的TPS 烤送。但如果使用了-oltp-skip-trx=on,這項事務(wù)數(shù)恒為0糠悯,需要用total number of events 去除以總時間帮坚,得到tps(其實還可以分為讀tps和寫tps)
read/write requests: 用它除以總時間妻往,得到吞吐量QPS
sysbench基本測試內(nèi)存
內(nèi)存分配測試,主要是針對不同的塊大小進(jìn)行內(nèi)存的連續(xù)讀寫或者隨機(jī)讀寫測試
內(nèi)存測試參數(shù)詳解:
[root@localhost db]# sysbench --test=memory help
sysbench 0.5: multi-threaded system evaluation benchmark
memory options:
--memory-block-size=SIZE size of memory block for test [1K]#內(nèi)存塊大小试和,默認(rèn)是1k
--memory-total-size=SIZE total size of data to transfer [100G]#測試的內(nèi)存大小
--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] #測試模式讯泣,隨機(jī)讀還是順序
運(yùn)行腳本
sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run #順序讀 8k
sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run #隨機(jī)讀 8k
內(nèi)存:以不同塊大小傳輸一定數(shù)量的數(shù)據(jù)吞吐量大小越大越好
三、衡量結(jié)果標(biāo)準(zhǔn):
cpu性能測試:找范圍內(nèi)最大素數(shù)時間越短越好
線程調(diào)度:線程并發(fā)執(zhí)行阅悍,循環(huán)響應(yīng)信號量花費的時間越少越好
互斥鎖:并發(fā)線程同時申請互斥鎖循環(huán)一定次數(shù)花費的時間越少越好
內(nèi)存:以不同塊大小傳輸一定數(shù)量的數(shù)據(jù)吞吐量大小越大越好
IO:不同場景下IO TPS越大越好
文章首發(fā)網(wǎng)址:http://www.17codes.com/archives/58?from=jianshu