sysbench压力测试
sysbench是一个模块化、跨平台、多线程基准测试工具,主要用于测试不同系统参数下的数据库负载情况,本文主要介绍0.4版本的使用。sysbench主要用于以下性能测试:
文件I/O性能
调度
内存分配和传输
POSIX线程
数据库
?
安装
1.安装插件
yuminstalllibtool-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
makeinstall
cp-rsysbench/tests/usr/local/sysbench-0.4.12
ln-s/usr/local/sysbench-0.4.12/bin/sysbench/usr/local/sysbench-0.4.12/sysbench
修改环境变量,在环境变量中加入
exportLD_LIBRARY_PATH=/usr/local/mysql/lib
注意:如果安装目录中没有configure那么需要执行以下操作:
chmod+xautogen.sh
./autogen.sh
如果想要让sysbench支持oracle/pgsql的话,就需要在编译的时候加上参数--with-oracle
或者
--with-pgsql
一般语法?
prepare:用于文件IO和数据库OLTP测试的数据准备阶段。
run:性能测试阶段
cleanup:移除测试过程中产生的数据
help:显示帮助信息,获取--test帮助可以使用--test=name--help
通用命令选项
这部分命令参数的通用的,不管--test测试什么内容都可以使用这些通用的命令。可以执行sysbench--help了解各参数的具体解释
Generaloptions:
--num-threads=Nnumberofthreadstouse[1]
--max-requests=Nlimitfortotalnumberofrequests[10000]
--max-time=Nlimitfortotalexecutiontimeinseconds[0]
--forced-shutdown=STRINGamountoftimetowaitafter--max-timebeforeforcingshutdown[off]
--thread-stack-size=SIZEsizeofstackperthread[32K]
--init-rng=[on|off]initializerandomnumbergenerator[off]
--seed-rng=Nseedforrandomnumbergenerator,ignoredwhen0[0]
--tx-rate=Ntargettransactionrate(tps)[0]
--tx-jitter=Ntargettransactionvariation,inmicroseconds[0]
--report-interval=Nperiodicallyreportintermediatestatisticswithaspecifiedintervalinseconds.0disablesintermediatereports[0]
--report-checkpoints=[LIST,...]dumpfullstatisticsandresetallcountersatspecifiedpointsintime.Theargumentisalistofcomma-separatedvaluesrepresentingtheamountoftimeinsecondselapsedfromstartoftestwhenreportcheckpoint(s)mustbeperformed.Reportcheckpointsareoffbydefault.[]
--test=STRINGtesttorun
--debug=[on|off]printmoredebugginginfo[off]
--validate=[on|off]performvalidationcheckswherepossible[off]
--help=[on|off]printhelpandexit
--version=[on|off]printversionandexit
Logoptions:
--verbosity=Nverbositylevel{5-debug,0-onlycriticalmessages}[4]
--percentile=Npercentilerankofqueryresponsetimestocount[95]
Compiled-intests:
fileio-FileI/Otest
cpu-CPUperformancetest
memory-Memoryfunctionsspeedtest
threads-Threadssubsystemperformancetest
mutex-Mutexperformancetest
oltp-OLTPtest
Commands:prepareruncleanuphelpversion
See''sysbench--test=help''foralistofoptionsforeachtest.
主要的参数有:
--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=20000run
上面的测试是: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=2run
memory测试
内存分配测试,主要是针对不同的块大小进行内存的连续读写或者随机读写测试。
memoryoptions:
--memory-block-size=SIZEsizeofmemoryblockfortest[1K]
--memory-total-size=SIZEtotalsizeofdatatotransfer[100G]
--memory-scope=STRINGmemoryaccessscope{global,local}[global]
--memory-hugetlb=[on|off]allocatememoryfromHugeTLBpool[off]
--memory-oper=STRINGtypeofmemoryoperations{read,write,none}[write]
--memory-access-mode=STRINGmemoryaccessmode{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=seqrun
?ViewCode
报告:时间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=rndrun
?ViewCode
报告: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=seqrun
?ViewCode
报告: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=rndrun
?ViewCode
报告:6.4S,15G/s
总结:对于分配同样大小的内存,块月大分配的速率越快,随机分配比顺序分配的速度要快
文件io测试
./sysbench--test=fileiohelp
文件IO的测试主要用于测试IO的负载性能。主要的测试选项为--file-test-mode。还有几个可以关注的参数包括--file-block-size、--file-io-mode、--file-fsync-freq、--file-rw-ratio
--file-num=N创建测试文件的数量,默认128个
--file-block-size=Nblocksize大小,默认16K
--file-total-size=SIZE所有文件的总大小,默认2G
--file-test-mode=STRING测试类型{seqwr(顺序写),seqrewr(顺序读写),seqrd(顺序读),rndrd(随机读),rndwr(随机写),rndrw(随机读写)}
--file-io-mode=STRINGI/O模式,需要系统支持默认sync[sync(同步IO),async(异步IO),mmap()]
--file-async-backlog=N每个线程的异步操作队列数,默认128个,需要--file-io-mode=async;
--file-extra-flags=STRINGadditionalflagstouseonopeningfiles{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=rndrwprepare
./sysbench--num-threads=12--max-requests=10000--test=fileio--file-total-size=3G--file-test-mode=rndrwrun
./sysbench--num-threads=12--max-requests=10000--test=fileio--file-total-size=3G--file-test-mode=rndrwclean
?上图中的第二部分的包括内容反映了当前系统的io性能大概:38M/S
互斥锁测试
互斥锁测试模拟所有线程在同一时刻并发运行
./sysbench--num-threads=12--test=mutex--mutex-num=1024--mutex-locks=10000--mutex-loops=10000run
[root@localhostsysbench-0.4.12]#./sysbench--num-threads=12--test=mutex--mutex-num=1024--mutex-locks=10000--mutex-loops=10000run
sysbench0.4.12.10:multi-threadedsystemwww.visa158.comevaluationbenchmark
Runningthetestwithfollowingoptions:
Numberofthreads:12
Randomnumbergeneratorseedis0andwillbeignored
Doingmutexperformancetest
Threadsstarted!
Done.
Generalstatistics:
totaltime:0.0869s
totalnumberofevents:12
totaltimetakenbyeventexecution:1.0301
responsetime:
min:83.86ms
avg:85.84ms
max:86.88ms
approx.95percentile:86.78ms
Threadsfairness:
events(avg/stddev):1.0000/0.00
executiontime(avg/stddev):0.0858/0.00
oltp测试
oltp是针对数据库的基准测试,例如每次对数据库进行优化后执行基准测试来测试不同的配置的tps。可以通过以下命令了解它的有关参数:
./sysbench--test=oltphelp
--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],例如begin100and200
--oltp-point-selects=N单个事务中select查询的数量,默认[10]
--oltp-use-in-statement=N每个查询中主键查找(in10个值)的数量,默认[0]
--oltp-simple-ranges=N单个事务中执行范围查询的数量(SELECTcFROMsbtestWHEREidBETWEENNANDM),默认[1]
--oltp-sum-ranges=N单个事务中执行范围sum查询的数量,默认[1]
--oltp-order-ranges=N单个事务中执行范围orderby查询的数量,默认[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=Nminimumtimeinmicrosecondstosleepaftereachrequest[0]
--oltp-user-delay-max=Nmaximumtimeinmicrosecondstosleepaftereachrequest[0]
--oltp-table-name=STRING指定测试的表名,默认[sbtest]
--oltp-table-size=N指定表的记录大小,默认[10000]
--oltp-dist-type=STRING随机数分布状态。uniform(均匀分布)、gauss(高斯分布)、special(特殊分布),默认[special]
--oltp-dist-iter=Nnumberofiterationsusedfornumbersgeneration[12]
--oltp-dist-pct=N启用百分比特殊分布,默认[1]
--oltp-dist-res=Nspecial百分比[75]
--oltp-point-select-mysql-handler=[on|off]UseMySQLHANDLERforpointselect[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]
Generaldatabaseoptions:
--db-driver=STRING指定测试数据库类型,默认mysql
--db-ps-mode=STRINGpreparedstatementsusagemode{auto,disable}[auto]
mysqloptions:
--mysql-host=[LIST,...]MySQLserverhost[localhost]
--mysql-port=NMySQLserverport[3306]
--mysql-socket=STRINGMySQLsocket
--mysql-user=STRINGMySQLuser[sbtest]
--mysql-password=STRINGMySQLpassword[]
--mysql-db=STRINGMySQLdatabasename[sbtest]
--mysql-table-engine=STRINGstorageenginetouseforthetesttable{myisam,innodb,bdb,heap,ndbcluster,www.hunanwang.net,federated}[innodb]
--mysql-engine-trx=STRINGwhetherstorageengineusedistransactionalornot{yes,no,auto}[auto]
--mysql-ssl=[on|off]useSSLconnections,ifavailableintheclientlibrary[off]
--myisam-max-rows=Nmax-rowsparameterforMyISAMtables[1000000]
--mysql-create-options=STRINGadditionaloptionspassedtoCREATETABLE[]
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=10prepare
./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=10run
./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=10cleanup
[root@localhostsysbench-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=10run
sysbench0.4.12.10:multi-threadedsystemevaluationbenchmark
NoDBdriversspecified,usingmysql
Runningthetestwithfollowingoptions:
Numberofthreads:12
Randomnumbergeneratorseedis0andwillbeignored
DoingOLTPtest.
RunningmixedOLTPtest
UsingSpecialdistribution(12iterations,1pctofvaluesarereturnedin75pctcases)
Using"BEGIN"forstartingtransactions
Usingauto_incontheidcolumn
MaximumnumberofrequestsforOLTPtestislimitedto100000
Using10testtables
Threadsstarted!
Done.
OLTPteststatistics:
queriesperformed:
read:1400910
write:500325
other:200130
total:2101365
transactions:100065(791.94persec.)
deadlocks:0(0.00persec.)
read/writerequests:1901235(15046.89persec.)
otheroperations:200130(1583.88persec.)
Generalstatistics:
totaltime:126.3540s
totalnumberofevents:100065
totaltimetakenbyeventexecution:1513.9202
responsetime:
min:5.82ms
avg:15.13ms
max:2352.66ms
approx.95percentile:18.00ms
Threadsfairness:
events(avg/stddev):8338.7500/207.
报告:执行当前测试花费126S,TPS:791/S,RQ:15046/S,95%的请求花费18毫秒
事务测试,每个事务包含如下语句:
(Pointqueries:
SELECTcFROMsbtestWHEREid=N
(Rangequeries:
SELECTcFROMsbtestWHEREidBETWEENNANDM
(RangeSUM()queries:
SELECTSUM(K)FROMsbtestWHEREidBETWEENNandM
(RangeORDERBYqueries:
SELECTcFROMsbtestWHEREidbetweenNandMORDERBYc
(RangeDISTINCTqueries:
SELECTDISTINCTcFROMsbtestWHEREidBETWEENNandMORDERBY
c
(UPDATEsonindexcolumn:
UPDATEsbtestSETk=k+1WHEREid=N
(UPDATEsonnon-indexcolumn:
UPDATEsbtestSETc=NWHEREid=M
(DELETEqueries:
DELETEFROMsbtestWHEREid=N
(INSERTqueries:
INSERTINTOsbtestVALUES(...
?非事务测试,执行语句如下
(Pointqueries:
SELECTpadFROMsbtestWHEREid=N
(UPDATEsonindexcolumn:
UPDATEsbtestSETk=k+1WHEREid=N
(UPDATEsonnon-indexcolumn:
UPDATEsbtestSETc=NWHEREid=M
(DELETEqueries:
DELETEFROMsbtestWHEREid=N
(ThegeneratedrowIDsareuniqueovereachtestrun,sonorow
isdeletedtwice.
(INSERTqueries:
INSERTINTOsbtest(k,c,pad)VALUES(N,M,S)
总结
?sysbench是使用最广泛的基准压测工具,功能也很齐全报告也非常的详细。
|
|