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 --help
Usage:
sysbench [options]... [testname] [command] Commands implemented by most tests: prepare run cleanup help General options:
--threads=N number of threads to use []
--events=N limit for total number of events []
--time=N limit for total execution time in seconds []
--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=N average transactions rate. for unlimited rate []
--report-interval=N periodically report intermediate statistics with a specified interval in seconds. disables intermediate reports []
--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 []
--max-requests=N deprecated alias for --events []
--max-time=N deprecated alias for --time []
--num-threads=N deprecated alias for --threads [] 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 []
--rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) []
--rand-spec-res=N percentage of 'special' values to use (for special distribution) []
--rand-seed=N seed for random number generator. When , the current time is used as a RNG seed. []
--rand-pareto-h=N parameter h for pareto distribution [0.2] Log options:
--verbosity=N verbosity level { - debug, - only critical messages} [] --percentile=N percentile to calculate in latency statistics (-). Use the special value of to disable percentile calculations []
--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 driver mysql options:
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=[LIST,...] MySQL server port []
--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" [,,]
--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 []
--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= --mysql-user=testsbuser  --mysql-password='textpwd' --mysql-db=tssysbench --db-driver=mysql  --tables=  --table-size=  --report-interval= --threads=   --time= run

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

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

step 3 清理压测数据

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

补充

OLTP基准测试模拟了一个简单的事务处理系统的工作负载。若要对数据库性能进行测试就要使用OLTP相关的脚本。

在/usr/share/sysbench/目录下有相关的lua脚本:

压测结果中包含了很多的信息,其中重点需要我们关注的信息是:
A:总的事务数 (total number of events);
B:每秒事务数;
C:时间统计信息(最小,平均,最大响应时间,以及95%百分比响应时间);
D:线程公平性统计信息,表示负载的公平性(thread-fairness)。

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 times)
FATAL: error : 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 , aborting...
(last message repeated times)
FATAL: error : Unknown database 'sysbench_db'
(last message repeated times)

或是(不指定数据库)

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

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

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

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

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

通过sysbench工具实现MySQL数据库的性能测试的更多相关文章

  1. MYSQL启用日志,查看日志,利用mysqlbinlog工具恢复MySQL数据库【转载】

    转自 MYSQL启用日志,查看日志,利用mysqlbinlog工具恢复MySQL数据库 - _安静 - 博客园http://www.cnblogs.com/xionghui/archive/2012/ ...

  2. 使用percona-xtrabackup工具对mysql数据库的备份方案

    使用percona-xtrabackup工具对mysql数据库的备份方案 需要备份mysql的主机 172.16.155.23存放备份mysql的主机 172.16.155.22 目的:将155.23 ...

  3. pycharm工具连接mysql数据库失败

    在使用pycharm开发工具连接mysql数据库时提示错误,信息如下: Server returns invalid timezone. Go to 'Advanced' tab and set 's ...

  4. DBsever工具连接mysql数据库

    当我们安装网DBeaver的时候,怎么通过这个工具来连接Mysql数据库呢 像这个地方就按平时你的数据库信息输入就可以了 接下来配置JDBC的内容 重点说一下驱动包的版本问题,因为我安装的mysql是 ...

  5. 利用mysqltuner工具对mysql数据库进行优化

    mysqltuner工具使用,本工具建议定期运行,发现目前MYSQL数据库存在的问题及修改相关的参数 工具的下载及部署 解决环境依赖,因为工具是perl脚本开发的,需要perl脚本环境 # yun i ...

  6. 通过xtrabackup工具对mysql数据库做全备

    需求描述: 使用xtrabackup工具对mysql实例中的所有的数据库进行备份,并且将备份的过程输出到指定的日志文件中. 操作过程: 1.使用xtrabacup工具备份mysql实例 xtrabac ...

  7. Navicat工具导出mySQL数据库某个视图结构的.sql脚本

    用Navicat工具怎么都导不出来mySQL数据库的某个视图.sql脚本,即使导出来也只是包含视图记录,不包含视图结构.经过一番研究,终于克服,操作如下: 1.在某个数据库中,新建备份,如下图 2.选 ...

  8. 常用工具说明--mysql数据库安装

    MySQL安装文件分为两种,一种是msi格式的,一种是zip格式的.如果是msi格式的可以直接点击安装,按照它给出的安装提示进行安装(相信大家的英文可以看懂英文提示),一般MySQL将会安装在C:\P ...

  9. mysqldump工具实现mysql数据库的备份还原

    简介 冷.温.热备份 冷备:读写操作均不可进行 温备:读操作可执行:但写操作不可执行 热备:读写操作均可执行 MyISAM:温备,不支持热备 InnoDB:都支持 不管是热备还原还是冷备还原,还原时都 ...

随机推荐

  1. 2019年5月23日 AY 程序员调侃语录

    我是AY,杨洋,做wpf开发的,最近得了一种病,程序员患得患失综合征.同事说,我年纪在变大,技术跟不上.业余之间,我原创了写了一些语录,给大家中午休息,累疲惫的时候,开心放松下. 1.有很多公司找我谈 ...

  2. 网络基础与FTP准备

    一网络基础 1.端口: 端口是为了将同一台电脑上的不同程序进行隔离 (IP是在找电脑,端口是在找电脑上的程序) 实例: MySQL是一个软件,帮助我们在硬盘上进行操作,默认端口是3306 Redis是 ...

  3. Web框架之Django重要组件(Django中间件、csrf跨站请求伪造)

    Web框架之Django_09 重要组件(Django中间件.csrf跨站请求伪造)   摘要 Django中间件 csrf跨站请求伪造 一.Django中间件: 什么是中间件? 官方的说法:中间件是 ...

  4. Binary classification - 聊聊评价指标的那些事儿【实战篇】

    分类问题就像披着羊皮的狼,看起来天真无害用起来天雷滚滚.比如在建模前你思考过下面的问题么? 你的分类模型输出的概率只是用来做样本间的相对排序,还是概率本身? 你的训练数据本身分布如何是否存在Imbal ...

  5. pybind11在Windows下的使用

      Pybind11算是目前最方便的Python调用C++的工具了, 介绍一下在vs2019上写Python的扩展的HelloWorld   1. 去下载pybind11 https://github ...

  6. TensorFlow 2.0 入门教程实战案例

    中文文档 TensorFlow 2 / 2.0 中文文档 知乎专栏 欢迎关注知乎专栏 https://zhuanlan.zhihu.com/geektutu 一.实战教程之强化学习 TensorFlo ...

  7. ElasticSearch 7.1.1 集群环境搭建

    1. 集群简介 三台机器,均用于保存数据且可被选为master节点 服务版本 服务 版本 elasticsearch 7.1.1 jdk 1.8 1. 创建elsearch用户 不建议直接使用root ...

  8. 深入理解Java虚拟机笔记——垃圾收集器与内存分配策略

    目录 判断对象是否死亡 引用计数器算法 可达性分析算法 各种引用 回收方法区 垃圾收集算法 标记-清除算法 复制算法 标记-整理算法 分代收集算法 HotSpot算法实现 枚举根节点 GC停顿(Sto ...

  9. HDU 6043:Colorful Tree(树上统计所有路径总颜色数)***

    题目链接 题意 给出一棵有n个结点的树,每个结点有一个颜色,问在这棵树的所有路径中,每条路径的颜色数求和是多少. 思路 求每种颜色的贡献可以转化为总的和减去每种颜色在哪些路径上没有出现的贡献,一个颜色 ...

  10. 探究Hybrid-APP技术原理

    探究Hybrid-APP技术原理 author: @TiffanysBear 背景 随着Web技术的发展和移动互联网的发展,Hybrid技术已经成为一种前端开发的主流技术方案.那什么是Hybrid A ...