侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

通过sysbench工具实现MySQL数据库的性能测试的方法

数据库  /  管理员 发布于 8年前   262

1.背景

 sysbench是一款压力测试工具,可以测试系统的硬件性能,也可以用来对数据库进行基准测试。sysbench 支持的测试有CPU运算性能测试、内存分配及传输速度测试、磁盘IO性能测试、POSIX线程性能测试、互斥性测试测试、数据库性能测试(OLTP基准测试)。目前支持的数据库主要是MySQL数据库和PG数据库。

在新服务器上线时,建议对服务器的性能做一次测试,最好与既往的同类型的服务器的性能测试报表做一个横线比较,发现潜在问题。及新机器上线前,对服务器做一次体检。

对数据库而言,我们可以通过sysbench工具实现对数据库的基准测试。在现在的系统架构中,前端都比较容易弹性水平拓展,数据库相对较难,因此,基准测试对数据库具有很重要的作用。而对数据库的基准测试的作用,就是分析在当前的配置下(包括硬件配置、OS、数据库设置等),数据库的性能表现,从而找出MySQL的性能阈值,并根据实际系统的要求调整配置。

2.sysbench的安装

1)安装命令

yum -y install sysbench

2)查看安装的版本

sysbench --version

3)查看已安装软件的信息(主要是通 rpm 命令)。

 查询sysbench的安装信息,主要是测试mysql时,需要使用sysbench自带的lua脚本进行测试。如果使用快速安装的方式,默认的脚本路径为:/usr/share/sysbench。

 如果不在这个命令,我们我们执行以下命令查看,查找已安装在本机Linux系统上面的所有的sysbench软件的程序:

rpm -qa sysbench

列出该软件所有的文件与目录所在完整文件名(list):

rpm -ql sysbench

3.sysbench 语法

sysbench --helpUsage: sysbench [options]... [testname] [command]Commands implemented by most tests: prepare run cleanup helpGeneral options: --threads=N           number of threads to use [1] --events=N           limit for total number of events [0] --time=Nlimit for total execution time in seconds [10] --forced-shutdown=STRING    number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off] --thread-stack-size=SIZE    size of stack per thread [64K] --rate=Naverage transactions rate. 0 for unlimited rate [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. [] --debug[=on|off]        print more debugging info [off] --validate[=on|off]       perform validation checks where possible [off] --help[=on|off]         print help and exit [off] --version[=on|off]       print version and exit [off] --config-file=FILENAME     File containing command line options --tx-rate=N           deprecated alias for --rate [0] --max-requests=N        deprecated alias for --events [0] --max-time=N          deprecated alias for --time [0] --num-threads=N         deprecated alias for --threads [1]Pseudo-Random Numbers Generator options: --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [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. When 0, the current time is used as a RNG seed. [0] --rand-pareto-h=N parameter h for pareto distribution [0.2]Log options: --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3] --percentile=N    percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95] --histogram[=on|off] print latency histogram in report [off]General database options: --db-driver=STRING specifies database driver to use ('help' to get list of available drivers) [mysql] --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto] --db-debug[=on|off] print database-specific debug information [off]Compiled-in database drivers: mysql - MySQL driver pgsql - PostgreSQL drivermysql options: --mysql-host=[LIST,...]     MySQL server host [localhost] --mysql-port=[LIST,...]     MySQL server port [3306] --mysql-socket=[LIST,...]    MySQL socket --mysql-user=STRING       MySQL user [sbtest] --mysql-password=STRING     MySQL password [] --mysql-db=STRING        MySQL database name [sbtest] --mysql-ssl[=on|off]       use SSL connections, if available in the client library [off] --mysql-ssl-cipher=STRING    use specific cipher for SSL connections [] --mysql-compression[=on|off]   use compression, if available in the client library [off] --mysql-debug[=on|off]      trace all client library calls [off] --mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205] --mysql-dry-run[=on|off]     Dry run, pretend that all MySQL client API calls are successful without executing them [off]pgsql options: --pgsql-host=STRING   PostgreSQL server host [localhost] --pgsql-port=N     PostgreSQL server port [5432] --pgsql-user=STRING   PostgreSQL user [sbtest] --pgsql-password=STRING PostgreSQL password [] --pgsql-db=STRING    PostgreSQL database name [sbtest]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

基本语法如下:

sysbench [options]... [testname] [command]

command 是sysbench要执行的命令,包括prepare、run和cleanup。prepare是为测试提前准备数据,run是执行正式的测试,cleanup是在测试完成后对数据库进行清理

testname  指定了要进行的测试,在老版本的sysbench中,可以通过--test参数指定测试的脚本;而在新版本中,--test参数已经声明为废弃,可以不使用--test,而是直接指定脚本。测试时使用的脚本为lua脚本,可以使用sysbench自带脚本,也可以自己开发。

options 关于MySQL的主要包括MySQL 连接信息参数 和 MySQL 执行相关的参数。

4 测试

Step 1 准备压测数据

sysbench /usr/share/sysbench/oltp_insert.lua --mysql-host=XXX.XXX.XXX.XXX --mysql-port=3306 --mysql-user=testsbuser --mysql-password='textpwd' --mysql-db=tssysbench --db-driver=mysql --tables=15 --table-size=500000 --report-interval=10 --threads=128  --time=120 prepare

step 2  压测

sysbench /usr/share/sysbench/oltp_insert.lua --mysql-host=XXX.XXX.XXX.XXX --mysql-port=3306 --mysql-user=testsbuser --mysql-password='textpwd' --mysql-db=tssysbench --db-driver=mysql --tables=15 --table-size=500000 --report-interval=10 --threads=128  --time=120 run

也可以将测试结果导出到文件中,便于后续分析。

 sysbench /usr/share/sysbench/oltp_insert.lua --mysql-host=XXX.XXX.XXX.XXX --mysql-port=3306 --mysql-user=testsbuser --mysql-password='testpwd' --mysql-db=tssysbench --db-driver=mysql --tables=15 --table-size=500000 --report-interval=10 --threads=128  --time=120 run >> ./mysysbench.log

step 3 清理压测数据

sysbench /usr/share/sysbench/oltp_insert.lua --mysql-host=XXX.XXX.XXX.XXX --mysql-port=3306 --mysql-user=testsbuser --mysql-password='testpwd' --mysql-db=tssysbench --db-driver=mysql --tables=15 --table-size=500000 --report-interval=10 --threads=128  --time=120 cleanup

5.注意事项

(1) 测试数据库需要提前创建,及时测试账号拥有创建数据库的权限。

     --mysql-db 参数指定了测试的数据,默认是sbtest。

    不提前创建,报错信息如下;

FATAL: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:83: connection creation failed
(last message repeated 3 times)
FATAL: error 1049: Unknown database 'sysbench_db'
FATAL: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:83: connection creation failed
FATAL: unable to connect to MySQL server on host 'XXX.XXX.XXX.XXX', port 3306, aborting...
(last message repeated 1 times)
FATAL: error 1049: Unknown database 'sysbench_db'
(last message repeated 1 times)

或是(不指定数据库)

FATAL: `sysbench.cmdline.call_command' function failed: /usr/share/sysbench/oltp_common.lua:83: connection creation failed
FATAL: error 1049: Unknown database 'sbtest'
FATAL: unable to connect to MySQL server on host 'XXX.XXX.XXX.XXX', port 3306, aborting...

(2)不要在MySQL服务器运行的机器上进行测试,一方面可能无法体现网络(哪怕是局域网)的影响,另一方面,sysbench的运行(尤其是设置的并发数较高时)会影响MySQL服务器的表现.

(3)逐步增加客户端的并发连接数(--thread参数),观察在连接数不同情况下,MySQL服务器的表现。

(4)如果连续进行多次测试,注意确保之前测试的数据已经被清理干净。

(5)如果生成的报告,图形化分析,可以通过gnuplot工具进行分析。

总结

以上所述是小编给大家介绍的通过sysbench工具实现MySQL数据库的性能测试的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!


  • 上一条:
    如何将Excel文件导入MySQL数据库
    下一条:
    ubuntu安装mysql数据库方法
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 分库分表的目的、优缺点及具体实现方式介绍(0个评论)
    • DevDB - 在 VS 代码中直接访问数据库(0个评论)
    • 在ubuntu系统中实现mysql数据存储目录迁移流程步骤(0个评论)
    • 在mysql中使用存储过程批量新增测试数据流程步骤(0个评论)
    • php+mysql数据库批量根据条件快速更新、连表更新sql实现(0个评论)
    • 近期文章
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2017-06
    • 2017-08
    • 2017-09
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-05
    • 2018-10
    • 2018-11
    • 2020-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2021-02
    • 2021-04
    • 2021-07
    • 2021-08
    • 2021-11
    • 2021-12
    • 2022-02
    • 2022-03
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-07
    • 2023-08
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-03
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客