使用sysbench 对mysql进行性能测试

sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。以下操作都将以支持MySQL数据库为例进行。

1. 安装

操作系统:Centos 6.8 x86-64

安装依赖

yum install m4 autoconf automake libtool

安装sysbench

wget http://olvimidkv.bkt.clouddn.com/sysbench-0.4.12-1.1.tgz
tar -xf sysbench-0.4.12-1.1.tgz
cd sysbench-0.4.12-1.1
./autogen.sh
编译
./configure --with-mysql-includes=/home/xiaohe/mysql-3306/include/ --with-mysql-libs=/home/xiaohe/mysql-3306/lib/
# 默认安装只支持MySQL,如果要支持pgsql/oracle 就需要在编译的时候加上--with-pgsql 或 --with-oracle
安装
make && make install 因为是指定路径编译安装的所以会报下面的错误 sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory 说明sysbench无法找到mysql的库文件,因此需要指定mysqllib的路径 export LD_LIBRARY_PATH=/home/xiaohe/mysql-3306/lib/
最好写到/etc/profile里面,这样就不会每次登陆都要设置了 sysbench --help 如果不报错,就说明成功了。 按照文档一般不会出错,要是还是出错,请Google。

参数说明

好多英文,自己体会,用的时候仔细看看。

[root@XH-TEST-01 ~]# sysbench --help
Usage: 用法:
sysbench [general-options]... --test=<test-name> [test-options]... command General options: 基本选项
--num-threads=N number of threads to use [1]
--max-requests=N limit for total number of requests [10000]
--max-time=N limit for total execution time in seconds [0]
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]
--thread-stack-size=SIZE size of stack per thread [64K]
--tx-rate=N target transaction rate (tps) [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. []
--test=STRING test to run
--debug=[on|off] print more debugging info [off]
--validate=[on|off] perform validation checks where possible [off]
--help=[on|off] print help and exit
--version=[on|off] print version and exit [off]
--rand-init=[on|off] initialize random number generator [off]
--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, ignored when 0 [0]
--rand-pareto-h=N parameter h for pareto distibution [0.2] Log options:
--verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3] --percentile=N percentile rank of query response times to count [95] Compiled-in tests:
fileio - File I/O test 磁盘IO
cpu - CPU performance test CPU
memory - Memory functions speed test 内存分配及速度
threads - Threads subsystem performance test 多线程性能
mutex - Mutex performance test 调度程序性能

还有具体的项的帮助,如下,具体的自行查看。

sysbench --test=fileio help
sysbench --test=cup help
sysbench --test=memory help
sysbench --test=threads help
sysbench --test=mutex help
sysbench --test=oltp help

测试实例

1. 磁盘测试

创建初始化fileio文件
sysbench --test=fileio --file-num=16 --file-total-size=2G prepare

开始测试

接下来开始对这些文件进行测试,使用16个线程随机读进行测试结果如下:

sysbench --test=fileio --file-total-size=2G --file-test-mode=rndrd --max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on --file-num=16 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run

随机读写每秒2.3817Mb IOPS 每秒152.43 说明很糟糕。

仿真环境的数据如下

好了不少,但还是比较慢的。

测试完成之后记得删除测试文件。
sysbench --test=fileio --file-num=16 --file-total-size=2G cleanup

如果需要测试seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)等6种模式,并且还可能需要测试不同的线程和不同的文件块下磁盘的性能表现,这时,可以使用如下脚本达到测试目的。

#!/bin/bash

for size in {8G,64G}
do
for mode in {seqwr,seqrewr,seqrd,rndrd,rndwr,rndrw}
do
for blksize in {4096,16384}
do
sysbench --test=fileio --file-num=64 --file-total-size=$size prepare
for threads in {1,4,8,16,32}
do
echo "=============testing $blksize in $threads threads"
echo PARAS $size $mode $threads $blksize > sysbench-size-$size-mode-$mode-threads-$threads-blksz-$blksize
for i in {1,2,3}
do
sysbench --test=fileio --file-total-size=$size --file-test-mode=$mode --max-time=180 --max-requests=100000 --num-threads=$threads --init-rng=on --file-num=64 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=$blksize run|tee -a sysbench-size-$size-mo
de-$mode-threads-$threads-blksz-$blksize 2>&1
done
done
sysbench --test=fileio --file-total-size=$size cleanup
done
done
done

内存测试

sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run

![](media/14879298422832/14881811382311.jpg)

内存差距一般不大,测试io意义更大些。

3.对MySQL事务型OLTP的测试 以这个为例,其它的换对应的lua脚本即可。

对于mysql的OLTP测试,和file一样,同样需要经历prepare,run,cleanup三个阶段。prepare阶段会在数据库中产生一张指定行数的表,默认表在sbtest架构下,表名为

sbtest(sysbench默认生成表的存储引擎为innodb),如创建一张8000万条记录的表:

常用参数简单说明:
--report-interval=10:每隔多久打印一次统计信息,单位秒,0.5版本新增
--rand-init=on:是否随机初始化数据,如果不随机化那么初始好的数据每行内容除了主键不同外其他完全相同。
--rand-type=special:数据分布模式,special表示存在热点数据,uniform表示非热点数据模式
--mysql-table-engine=xxx:表的存储引擎类型,innodb、myisam、tokudb这些都可以
prepare准备阶段

初始化

sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --db-driver=mysql --mysql-socket=/home/xiaohe/mysql-3306/mysql.sock  --num-threads=16 --mysql-table-engine=InnoDB  --rand-init=on   --mysql-db=test prepare

run运行测试

压力测试

sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua  --oltp_tables_count=10 --oltp-table-size=100000 --oltp-dist-type=uniform   --report-interval=10 --rand-init=on  --mysql-table-engine=InnoDB  --mysql-db=test --max-time=3600 --max-requests=0 --num-threads=16 --thread-stack-size=256 --mysql-socket=/home/xiaohe/mysql-3306/mysql.sock  run > result.log

参数说明:

--max-time=3600 指定测试时长为1小时

--mysql-db=test 指定测试的数据库名

清理
sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua  --oltp_tables_count=10 --oltp-table-size=100000 --db-driver=mysql --mysql-socket=/home/xiaohe/mysql-3306/mysql.sock  --mysql-table-engine=InnoDB --mysql-db=test cleanup

使用sysbench 对mysql进行性能测试的更多相关文章

  1. Mysql多线程性能测试工具sysbench 安装、使用和测试

    From:http://www.cnblogs.com/zhoujinyi/archive/2013/04/19/3029134.html 摘要:      sysbench是一个开源的.模块化的.跨 ...

  2. 使用sysbench对mysql压力测试

    sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.关于这个项目的详细介绍请看:https://github.com/akopytov/sy ...

  3. sysbench - 数据库功能及性能测试工具

    sysbench 的 GitHub 参考资料 1.0 之后的版本使用方法跟之前的有所区别,下面所有内容基于 1.0.9 版本. 另外,为了方便管理测试,最好不要通过命令直接运行测试,而是写成脚本自动化 ...

  4. Sysbench对Mysql进行基准测试

    前言 1.基准测试(benchmarking)是性能测试的一种类型,强调的是对一类测试对象的某些性能指标进行定量的.可复现.可对比的测试. 进一步来理解,基准测试是在某个时候通过基准测试建立一个已知的 ...

  5. 使用sysbench对MySQL进行压力测试

    1.背景 ​出自percona公司,是一款多线程系统压测工具,可以根据影响数据库服务器性能的各种因素来评估系统的性能.例如,可以用来测试文件IO,操作系统调度器,内存分配和传输速度,POSIX线程以及 ...

  6. 使用sysbench测试mysql及postgresql(完整版)

    使用sysbench测试mysql及postgresql(完整版) 转载请注明出处https://www.cnblogs.com/funnyzpc/p/14592166.html 前言 使用sysbe ...

  7. 使用 sysbench对mysql进行压力测试介绍之一

    sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试.数据库目前支持MySQL/Oracle/PostgreSQL.本文只是简单演示一下几种测试的用 ...

  8. IBM Power PC安装sysbench 执行mysql基准测试 --- sysbench安装

    第一步:下载Sysbench http://dev.mysql.com/downloads/benchmarks.html 第二步:解压sysbench 第三步:执行安装步骤 1. ./autogen ...

  9. Mybatis与JDBC批量插入MySQL数据库性能测试及解决方案

    转自http://www.cnblogs.com/fnz0/p/5713102.html 不知道自己什么时候才有这种钻研精神- -. 1      背景 系统中需要批量生成单据数据到数据库表,所以采用 ...

随机推荐

  1. SPSS学习小记

    2013年1月8日 最近一直在SPSS中处理数据,涉及到函数部分,不是太懂,特记录于此,以便翻阅.   SPSS判断字符变量中是否含有某字符串的表示方式:  (INDEX(url,'ad')>0 ...

  2. HD-ACM算法专攻系列(9)——大菲波数

    题目描述: 源码: 运用Java大数求解. import java.math.BigInteger; import java.util.*; public class Main { //主函数 pub ...

  3. iReport5.6.0使用说明

    1,需要安装jdk1.7,因为目前还不支持最新的jdk1.8 2,安装好软件之后,打开安装目录下的etc/ireport.conf文件,配置关联自己的jdk1.7的路径,如下: #jdkhome=&q ...

  4. (转载) 清理缓存 IPackageStatsObserver

    清理缓存 IPackageStatsObserver 2016-04-10 13:40 2288人阅读 评论(0) 收藏 举报  分类: android(59)  版权声明:本文为博主原创文章,未经博 ...

  5. 前端学习之路——scss篇

    一.什么是SASS SASS是一种CSS的开发工具,提供了许多便利的写法,大大节省了设计者的时间,使得CSS的开发,变得简单和可维护. 二.安装和使用 Sass依赖于ruby环境,所以装sass之前先 ...

  6. servlet中Session的用法

    ## (1)什么是Session? 服务器端为了保存用户的状态而创建的一个特殊的对象(即session对象).          当浏览器第一次访问服务器时,服务器会创建session对象(该    ...

  7. Site Isolation Design Document

    This design document covers technical information about how Site Isolation is built.  For a general ...

  8. matlab Time-domain analysis 渐进式或者实时获取仿真值

    首先准备一个传递函数sys, 然后使用lsim(sys,u,t,x0)函数(通用的时序分析的函数) u: The input u is an array having as many rows as ...

  9. 每个人都能实现的vue自定义指令

    前文 先来bb一堆废话哈哈.. 用vue做项目也有一年多了.除了用别人的插件之外.自己也没尝试去封装指令插件之类的东西来用. 刚好最近在项目中遇到一个问题.(快速点击按钮多次触发多次绑定的方法),于是 ...

  10. idea 包的显示方式

    idea 可以通过点击Project的导航栏里的小齿轮里面有一个 Flatten packages 选项,将其勾上.就可以得到跟eclipse一样的包的显示方式. 没有设置默认是这样的 2018-06 ...