mysql io测试,MySQL自带的压力测试工具Mysqlslap

一、MySQL自带的压力测试工具Mysqlslap

mysqlslap是mysql自带的基准测试工具,该工具查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出查询更新,给出了性能测试数据而且提供了多种引擎的性能比较。mysqlslap为mysql性能优化前后提供了直观的验证依据,系统运维和DBA人员应该掌握一些常见的压力测试工具,才能准确的掌握线上数据库支撑的用户流量上限及其抗压性等问题。

1、更改其默认的最大连接数

在对MySQL进行压力测试之前,需要更改其默认的最大连接数,如下:

[root@mysql~]#vim/etc/my.cnf................[mysqld]max_connections=1024[root@mysql~]#systemctlrestartmysqld

查看最大连接数

mysql>showvariableslike'max_connections';+-----------------+-------+|Variable_name|Value|+-----------------+-------+|max_connections|1024|+-----------------+--------+1rowinset(0.00sec)

进行压力测试:

[root@mysql~]#mysqlslap--defaults-file=/etc/my.cnf--concurrency=100,200--iterations=1--number-int-cols=20--number-char-cols=30--auto-generate-sql--auto-generate-sql-add-autoincrement--auto-generate-sql-load-type=mixed--engine=myisam,innodb--number-of-queries=2000-uroot-p123--verbose

上述命令测试说明:模拟测试两次读写并发,第一次100,第二次200,自动生成SQL脚本,测试表包含20个init字段,30个char字段,每次执行2000查询请求。测试引擎分别是myisam,innodb。(上述选项中有很多都是默认值,可以省略,如果想要了解各个选项的解释,可以使用mysqlslap--help进行查询)。

测试结果说明:

Myisam第一次100客户端同时发起增查用0.557/s,第二次200客户端同时发起增查用0.522/s

Innodb第一次100客户端同时发起增查用0.256/s,第二次200客户端同时发起增查用0.303/s

可以根据实际需求,一点点的加大并发数量进行压力测试。

7fc028acb7015b0a68c85865a4b13035.png

二、使用第三方sysbench工具进行压力测试

1、安装sysbench工具

[root@mysql~]#yum-yinstallepel-release#安装第三方epel源[root@mysql~]#yum-yinstallsysbench#安装sysbench工具[root@mysql~]#sysbench--version#确定工具已安装sysbench1.0.17

sysbench可以进行以下测试:

CPU运算性能测试

磁盘IO性能测试

调度程序性能测试

内存分配及传输速度测试

POSIX线程性能测试

数据库性能测试(OLTP基准测试,需要通过/usr/share/sysbench/目录中的Lua脚本执行,例如oltp_read_only.lua脚本执行只读测试)。

sysbench还可以通过运行命令时指定自己的Lua脚本来自定义测试。

2、查看sysbench工具的帮助选项

help'foralistofoptionsforeachtest.

3、sysbench测试MySQL数据库性能

1)准备测试数据

#查看sysbench自带的lua脚本使用方法[root@mysql~]#sysbench/usr/share/sysbench/oltp_common.luahelp#必须创建sbtest库,sbtest是sysbench默认使用的库名[root@mysql~]#mysqladmin-uroot-p123createsbtest;#然后,准备测试所用的表,这些测试表放在测试库sbtest中。这里使用的lua脚本为/usr/share/sysbench/oltp_common.lua。[root@mysql~]#sysbench--mysql-host=127.0.0.1--mysql-port=3306--mysql-user=root--mysql-password=123/usr/share/sysbench/oltp_common.lua--tables=10--table_size=100000prepare#其中--tables=10表示创建10个测试表,#--table_size=100000表示每个表中插入10W行数据,#prepare表示这是准备数的过程。

2)确认测试数据以存在

[root@mysql~]#mysql-uroot-p123sbtest;#登录到sbtest库mysql>showtables;#查看相应的表+------------------+|Tables_in_sbtest|+------------------+|sbtest1||sbtest10||sbtest2||sbtest3||sbtest4||sbtest5||sbtest6||sbtest7||sbtest8||sbtest9|+------------------+10rowsinset(0.00sec)mysql>selectcount(*)fromsbtest1;#随机选择一个表,确认其有100000条数据+----------+|count(*)|+----------+|100000|+----------+1rowinset(0.01sec)

3)数据库测试和结果分析

稍微修改下之前准备数据的语句,就可以拿来测试了。需要注意的是,之前使用的lua脚本为oltp_common.lua,它是一个通用脚本,是被其它lua脚本调用的,它不能直接拿来测试。

所以,我这里用oltp_read_write.lua脚本来做读、写测试。还有很多其它类型的测试,比如只读测试、只写测试、删除测试、大批量插入测试等等。可找到对应的lua脚本进行调用即可。

#执行测试命令如下:[root@mysql~]#sysbench--threads=4--time=20--report-interval=5--mysql-host=127.0.0.1--mysql-port=3306--mysql-user=root--mysql-password=123/usr/share/sysbench/oltp_read_write.lua--tables=10--table_size=100000run

上述命令返回的结果如下:

[root@mysql~]#sysbench--threads=4--time=20--report-interval=5--mysql-host=127.0.0.1--mysql-port=3306--mysql-user=root--mysql-password=123/usr/share/sysbench/oltp_read_write.lua--tables=10--table_size=100000runsysbench1.0.17(usingsystemLuaJIT2.0.4)Runningthetestwithfollowingoptions:Numberofthreads:4Reportintermediateresultsevery5second(s)InitializingrandomnumbergeneratorfromcurrenttimeInitializingworkerthreads...Threadsstarted!#以下是每5秒返回一次的结果,统计的指标包括:#线程数、tps(每秒事务数)、qps(每秒查询数)、#每秒的读/写/其它次数、延迟、每秒错误数、每秒重连次数[5s]thds:4tps:1040.21qps:20815.65(r/w/o:14573.17/4161.25/2081.22)lat(ms,95%):7.17err/s:0.00reconn/s:0.00[10s]thds:4tps:1083.34qps:21667.15(r/w/o:15165.93/4334.55/2166.68)lat(ms,95%):6.55err/s:0.00reconn/s:0.00[15s]thds:4tps:1121.57qps:22429.09(r/w/o:15700.64/4485.30/2243.15)lat(ms,95%):6.55err/s:0.00reconn/s:0.00[20s]thds:4tps:1141.69qps:22831.98(r/w/o:15982.65/4566.16/2283.18)lat(ms,95%):6.09err/s:0.00reconn/s:0.00SQLstatistics:queriesperformed:read:307146#执行的读操作数量write:87756#执行的写操作数量other:43878#执行的其它操作数量total:438780transactions:21939(1096.57persec.)#执行事务的平均速率queries:438780(21931.37persec.)#平均每秒能执行多少次查询ignorederrors:0(0.00persec.)reconnects:0(0.00persec.)Generalstatistics:totaltime:20.0055s#总消耗时间totalnumberofevents:21939#总请求数量(读、写、其它)Latency(ms):min:1.39avg:3.64max:192.0595thpercentile:6.67#采样计算的平均延迟sum:79964.26Threadsfairness:events(avg/stddev):5484.7500/15.12executiontime(avg/stddev):19.9911/0.00

4、cpu/io/内存等测试

sysbench内置的几个测试指标如下:

[root@mysql~]#sysbench--help..........#省略部分内容Compiled-intests:fileio-FileI/Otestcpu-CPUperformancetestmemory-Memoryfunctionsspeedtestthreads-Threadssubsystemperformancetestmutex-Mutexperformancetest

可以直接help输出测试方法,例如,fileio测试:

[root@mysql~]#sysbenchfileiohelpsysbench1.0.17(usingsystemLuaJIT2.0.4)fileiooptions:--file-num=Nnumberoffilestocreate[128]--file-block-size=NblocksizetouseinallIOoperations[16384]--file-total-size=SIZEtotalsizeoffilestocreate[2G]--file-test-mode=STRINGtestmode{seqwr,seqrewr,seqrd,rndrd,rndwr,rndrw}--file-io-mode=STRINGfileoperationsmode{sync,async,mmap}[sync]--file-async-backlog=Nnumberofasynchronousoperatonstoqueueperthread[128]--file-extra-flags=[LIST,...]listofadditionalflagstousetoopenfiles{sync,dsync,direct}[]--file-fsync-freq=Ndofsync()afterthisnumberofrequests(0-don'tusefsync())[100]--file-fsync-all[=on|off]dofsync()aftereachwriteoperation[off]--file-fsync-end[=on|off]dofsync()attheendoftest[on]--file-fsync-mode=STRINGwhichmethodtouseforsynchronization{fsync,fdatasync}[fsync]--file-merged-requests=NmergeatmostthisnumberofIOrequestsifpossible(0-don'tmerge)[0]--file-rw-ratio=Nreads/writesratioforcombinedtest[1.5]

1)测试io性能

例如,创建5个文件,总共2G,每个文件大概400M。

[root@mysql~]#sysbenchfileio--file-num=5--file-total-size=2Gprepare[root@mysql~]#ll-lhtest*-rw-------1rootroot410MMay2616:05test_file.0-rw-------1rootroot410MMay2616:05test_file.1-rw-------1rootroot410MMay2616:05test_file.2-rw-------1rootroot410MMay2616:05test_file.3-rw-------1rootroot410MMay2616:05test_file.4

然后运行测试:

[root@mysql~]#sysbench--events=5000--threads=16fileio--file-num=5--file-total-size=2G--file-test-mode=rndrw--file-fsync-freq=0--file-block-size=16384run

返回的结果如下:

Runningthetestwithfollowingoptions:Numberofthreads:16InitializingrandomnumbergeneratorfromcurrenttimeExtrafileopenflags:(none)5files,409.6MiBeach2GiBtotalfilesizeBlocksize16KiBNumberofIOrequests:5000Read/WriteratioforcombinedrandomIOtest:1.50Callingfsync()attheendoftest,Enabled.UsingsynchronousI/OmodeDoingrandomr/wtestInitializingworkerthreads...Threadsstarted!Fileoperations:reads/s:9899.03writes/s:6621.38fsyncs/s:264.33Throughput:#吞吐量read,MiB/s:154.66#表示读带宽written,MiB/s:103.46#表示写的带宽Generalstatistics:totaltime:0.3014stotalnumberofevents:5000Latency(ms):min:0.00avg:0.81max:53.5695thpercentile:4.10sum:4030.48Threadsfairness:events(avg/stddev):312.5000/27.64executiontime(avg/stddev):0.2519/0.02

2)测试cpu性能

[root@mysql~]#sysbenchcpu--threads=40--events=10000--cpu-max-prime=20000run

压测时,还请小心谨慎!!!!

责任编辑:lq

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值