现在的压力测试工具各种各样,只要上手好几款功能强大点的而且比较大众化的压力测试工具即可,以下跟大家交流下sysbench的安装和压力测试

sysbench支持以下几种测试模式

1、CPU运算性能

2、磁盘IO性能

3、内存分配及传输速度

4、内存分配及传输速度

5、POSIX线程性能

6、数据库性能(OLTP基准测试)

目前sysbench主要支持mysql,drizzle,pgsql,oracle等几种数据库

下面安装sysbench

一、 下载源码包,安装epel包后以便安装bzr客户端:

[root ~]$ rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
warning: /var/tmp/rpm-tmp.wgHSDP: Header V3 DSA/SHA1 Signature, key ID 217521f6: NOKEY
Preparing... ########################################### [%]
:epel-release ########################################### [%]

然后就可以开始安装bzr客户端了:

以下安装报错了:

[root yum.repos.d]$ yum install bzr
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
epel | 3.7 kB :
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bzr.x86_64 :2.1.-.el5 will be installed
--> Processing Dependency: python(abi) = 2.4 for package: bzr-2.1.-.el5.x86_64
--> Processing Dependency: python-paramiko for package: bzr-2.1.-.el5.x86_64
--> Processing Dependency: python-elementtree for package: bzr-2.1.-.el5.x86_64
--> Running transaction check
---> Package bzr.x86_64 :2.1.-.el5 will be installed
--> Processing Dependency: python(abi) = 2.4 for package: bzr-2.1.-.el5.x86_64
--> Processing Dependency: python-elementtree for package: bzr-2.1.-.el5.x86_64
---> Package python-paramiko.noarch :1.7.-.el5 will be installed
--> Processing Dependency: python(abi) = 2.4 for package: python-paramiko-1.7.-.el5.noarch
--> Finished Dependency Resolution
Error: Package: bzr-2.1.-.el5.x86_64 (epel)
Requires: python(abi) = 2.4
Installed: python-2.6.-.el6.x86_64 (@updates)
python(abi) = 2.6
Available: python26-2.6.-.el5.x86_64 (epel)
python(abi) = 2.6
Error: Package: python-paramiko-1.7.-.el5.noarch (epel)
Requires: python(abi) = 2.4
Installed: python-2.6.-.el6.x86_64 (@updates)
python(abi) = 2.6
Available: python26-2.6.-.el5.x86_64 (epel)
python(abi) = 2.6
Error: Package: bzr-2.1.-.el5.x86_64 (epel)
Requires: python-elementtree
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest

解决方法把旧版本的epel源删除,使用新的:(这个坑说白了,下载的epel源要跟自己使用系统符合,例如你用的是32位系统和64位的系统,下载epel源是不同的)

[root ~]$ cd /etc/yum.repos.d/
[root yum.repos.d]$ ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo epel.repo epel-testing.repo
[root yum.repos.d]$ rm -rf epel.repo
[root yum.repos.d]$ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.eyCDYb: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [%]
file /etc/yum.repos.d/epel-testing.repo from install of epel-release--.noarch conflicts with file from package epel-release--.noarch
file /etc/yum.repos.d/epel.repo from install of epel-release--.noarch conflicts with file from package epel-release--.noarch

二、再安装安装bzr客户端

[root yum.repos.d]$ yum install bzr -y
.....
.......
Running Transaction
Installing : python-paramiko-1.7.-2.1.el6.noarch /
Installing : bzr-2.1.-.el6.x86_64 /
Installed:
bzr.x86_64 :2.1.-.el6
Dependency Installed:
python-paramiko.noarch :1.7.-2.1.el6
Complete!

之后就可以用bzr客户端下载sysbench源码了。

[root ~]$ bzr branch lp:sysbench
You have not informed bzr of your Launchpad ID, and you must do this to
write to Launchpad or access private data. See "bzr help launchpad-login".
Branched revision(s).
[root ~]$ ll -d /root/sysbench/
drwxr-xr-x 7 root root 4096 11月 25 14:45 /root/sysbench/

可以看到,已经下载好sysbench目录了

三、 以下准备安装sysbench,涉及到sysbench源码的配置和编译,首先确认系统安装了gcc gcc-c++编译器:

[root sysbench]$ yum install autoconf automake libtool make cmake gcc gcc-c++ gcc4 -y 
[root sysbench]$ pwd
/root/sysbench
[root sysbench]$ ./autogen.sh

查看./counfiure支持的选项再进行编译安装:

[root sysbench]$ ./configure --help | grep with | grep mysql
  --with-mysql            compile with MySQL support (default is enabled)
  --with-mysql-includes   path to MySQL header files
  --with-mysql-libs       path to MySQL libraries [root sysbench]$ ./configure --with-mysql=/usr/local/mysql-5.5./ --with-mysql-includes=/usr/local/mysql-5.5./include/ \
> --with-mysql-libs=/usr/local/mysql-5.5./lib/
[root sysbench]$ make && make insall

第二种安装方法:

http://sourceforge.net/projects/sysbench 下载sysbench的源码包。

也可以在大牛的MySQL中文网上下载:http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgz

[root src]$wget http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgz
[root src]$ tar zxf sysbench-0.4.-1.1.tgz
[root sysbench-0.4.-1.1]$ ls
aclocal.m4 autom4te.cache config config.status configure.ac doc libtool Makefile Makefile.in mkinstalldirs README-WIN.txt TODO
autogen.sh ChangeLog config.log configure COPYING install-sh m4 Makefile.am missing README sysbench
[root sysbench-0.4.-1.1]$ ./autogen.sh
[root sysbench-0.4.12-1.1]$./configure --with-mysql=/usr/local/mysql-5.5.40/ --with-mysql-includes=/usr/local/mysql-5.5.40/include/ \
> --with-mysql-libs=/usr/local/mysql-5.5.40/lib/
[root sysbench]$ make && make insall

以上的安装只是下载方式不同,安装都是一样的^.^

四、下面进行使用说明:

测试磁盘IOPS可以分为:prepare、run、cleanup三个阶段:(准备数据、运行压测、清理数据)

创建测试数据库:

mysql> create database sbtest;
Query OK, 1 row affected (0.08 sec)
mysql>
[root sysbench]$ pwd
/root/sysbench-0.4.-1.1/sysbench
[root sysbench]$ ./sysbench --mysql-host=localhost --mysql-port= --mysql-user=root --mysql-password= --mysql-socket=/data/mysql-5.5/mysql.sock \
> --test=tests/db/oltp.lua --oltp_tables_count= --oltp-table-size= --rand-init=on prepare

若运行过程报以下错:

./sysbench: error while loading shared libraries: libmysqlclient.so.: cannot open shared object file: No such file or directory
解决方法:
ln -s /usr/local/mysql-5.5./lib/libmysqlclient.so. /usr/lib64/

关于这几个参数的解释:

--test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=50000 表示每个测试表填充数据量为 50000
--rand-init=on 表示每个测试表都是用随机数据来填充的

五、进行OLTP测试

./sysbench --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --mysql-socket=/data/mysql-5.5/mysql.sock \
> --test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=50000 --num-threads=8 \
> --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=5 --max-requests=0 --percentile=99 run

参数解释:

--num-threads=8      表示发起 8个并发连接
--oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
--report-interval=10 表示每10秒输出一次测试进度报告
--rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大执行时长为 120秒
--max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值

六、结果解读:

sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads:
Report intermediate results every second(s)
Random number generator seed is and will be ignored Threads started!
-- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、%以上的响应时长统计
[ 10s] threads: , tps: 119.03, reads/s: 1677.65, writes/s: 478.93, response time: .40ms (%)
[ 20s] threads: , tps: 76.80, reads/s: 1074.47, writes/s: 307.19, response time: .75ms (%)
[ 30s] threads: , tps: 88.20, reads/s: 1232.94, writes/s: 351.61, response time: .98ms (%)
[ 40s] threads: , tps: 149.79, reads/s: 2099.73, writes/s: 600.78, response time: .18ms (%)
[ 50s] threads: , tps: 78.09, reads/s: 1093.32, writes/s: 312.38, response time: .12ms (%)
[ 60s] threads: , tps: 79.30, reads/s: 1109.76, writes/s: 316.82, response time: .75ms (%)
[ 70s] threads: , tps: 35.50, reads/s: 497.52, writes/s: 142.41, response time: .36ms (%)
[ 80s] threads: , tps: 45.40, reads/s: 635.57, writes/s: 180.39, response time: .67ms (%)
[ 90s] threads: , tps: 73.00, reads/s: 1019.58, writes/s: 290.49, response time: .84ms (%)
[ 100s] threads: , tps: 148.01, reads/s: 2069.14, writes/s: 591.64, response time: .85ms (%)
[ 110s] threads: , tps: 60.60, reads/s: 850.90, writes/s: 242.90, response time: .81ms (%)
[ 120s] threads: , tps: 88.20, reads/s: 1237.71, writes/s: 354.20, response time: .94ms (%)
OLTP test statistics:
queries performed:
read: -- 读总数
write: -- 写总数
other: -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
total: -- 全部总数
transactions: (86.74 per sec.) -- 总事务数(每秒事务数)
deadlocks: (0.00 per sec.) -- 发生死锁总数
read/write requests: (1561.37 per sec.) -- 读写总数(每秒读写次数)
other operations: (173.49 per sec.) -- 其他操作总数(每秒其他操作次数) General statistics: -- 一些统计结果
total time: .1714s -- 总耗时
total number of events: -- 共发生多少事务数
total time taken by event execution: .6432s -- 所有事务耗时相加(不考虑并行因素)
response time:
min: .35ms -- 最小耗时
avg: .16ms -- 平均耗时
max: .05ms -- 最长耗时
approx. percentile: .23ms -- 超过99%平均耗时 Threads fairness:
events (avg/stddev): 1303.0000/24.81
execution time (avg/stddev): 120.0804/0.00

测试建议:
1、真实测试场景中,数据表建议不低于10个,单表数据量不低于500万行,当然了,要视服务器硬件配置而定。如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,则建议单表数据量最少不低于1亿行

2、真实测试场景中,建议持续压测时长不小于30分钟,否则测试数据可能不具参考意义。

想了解更多关于sysbench的相关说明,可以参考大牛的博客:http://imysql.com/2014/10/17/sysbench-full-user-manual.shtml

作者:陆炫志

出处:xuanzhi的博客 http://www.cnblogs.com/xuanzhi201111

您的支持是对博主最大的鼓励,感谢您的认真阅读。本文版权归作者所有,欢迎转载,但请保留该声明。

sysbench安装及性能测试的更多相关文章

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

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

  2. sysbench——服务器cpu性能测试

    一.前言 最近在工作中需要测试cpu占用率.内存占用率,我想要寻找一种合适的能提高cpu占用率的工具及方法.先尝试了使用 echo "scale=5000; 4*a(1)" | b ...

  3. Sysbench安装步骤及详情

    Sysbench安装步骤及详情 Sysbench是压力测试工具,可以测试系统的CPU,内存,I/O等,也可以用于数据库的性能测试 Sysbench安装步骤: 安装具体分为Ubuntu16.04和Cen ...

  4. sysbench 安装、使用和测试

    摘要:      sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL.Oracle和Post ...

  5. 给CentOS6.3 + PHP5.3 安装PHP性能测试工具 XHProf-0.9.2

    一.什么是XHProf XHProf官网:http://pecl.php.net/package/xhprof XHProf是一个分层PHP性能分析工具.它报告函数级别的请求次数和各种指标,包括 阻塞 ...

  6. 给Windows + Apache 2.2 + PHP 5.3 安装PHP性能测试工具 xhprof_0.10.3_php53_vc9.dll

    1.下载XHProf 到这里 http://dev.freshsite.pl/php-extensions/xhprof.html 下载Windows版本的XHProf,我这里选择下载 XHProf ...

  7. sysbench 安装

    sysbench源代码可以在https://launchpad.net/sysbench找到.也可以从本文件附件中下载. 先安装好mysql,记录下安装目录.默认为 /usr/local/mysql ...

  8. sysbench安装

    sysbench安装 1.下载软件mkdir -p /usr/local/softwarecd /usr/local/softwaregit clone https://github.com/akop ...

  9. linux sysbench (一): CPU性能测试详解

    网上sysbench教材众多,但没有一篇中文教材对cpu测试参数和结果进行详解. 本文旨在能够让读者对sysbench的cpu有一定了解. 小慢哥的原创文章,欢迎转载 1.sysbench基础知识 s ...

随机推荐

  1. Python3 - DBUtils 和 pymysql 整合

    之前一篇Python 封装DBUtils 和pymysql 中写过一个basedao.py,最近几天又重新整理了下思绪,优化了下 basedao.py,目前支持的方法还不多,后续会进行改进.添加. 主 ...

  2. 【设计模式】—— 中介者模式Mediator

    前言:[模式总览]——————————by xingoo 模式意图 使用一个中介的对象,封装一组对象之间的交互,这样这些对象就可以不用彼此耦合. 这个中介者常常起着中间桥梁的作用,使其他的对象可以利用 ...

  3. boost.asio学习-----reslover 域名解析

    将域名解析为ip地址并输出: #include "stdafx.h" #include "boost/asio.hpp" #include <boost/ ...

  4. JDK7新特性try-with-resources语句

    try-with-resources语句是一种声明了一种或多种资源的try语句.资源是指在程序用完了之后必须要关闭的对象.try-with-resources语句保证了每个声明了的资源在语句结束的时候 ...

  5. 牛客网-湘潭大学校赛重现H题 (线段树 染色问题)

    链接:https://www.nowcoder.com/acm/contest/105/H来源:牛客网 n个桶按顺序排列,我们用1~n给桶标号.有两种操作: 1 l r c 区间[l,r]中的每个桶中 ...

  6. 洛谷 P2051 [AHOI2009]中国象棋 解题报告

    P2051 [AHOI2009]中国象棋 题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法. ...

  7. Qt QGraphicsItem 绕中心旋转、放缩

    最近用到了QGraphicsItem,可以通过QGraphicsItemAnimation使其产生动画效果. QGraphicsItemAnimation自带了setPosAt().setRotati ...

  8. exgcd模板

    逆元模板P1082 #include <cstdio> #include <algorithm> int exgcd(int a, int b, int &x, int ...

  9. Stanford机器学习笔记-9. 聚类(K-means算法)

    9. Clustering Content 9. Clustering 9.1 Supervised Learning and Unsupervised Learning 9.2 K-means al ...

  10. springboot整合mybatis中的mapper不影响使用,但是总是提示红线

    解决方案: 如图: