码迷,mamicode.com
首页 > 其他好文 > 详细

sysbench安装及性能测试

时间:2014-11-25 18:19:07      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   os   使用   

现在的压力测试工具各种各样,只要上手好几款功能强大点的而且比较大众化的压力测试工具即可,以下跟大家交流下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...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

然后就可以开始安装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     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bzr.x86_64 0:2.1.4-2.el5 will be installed
--> Processing Dependency: python(abi) = 2.4 for package: bzr-2.1.4-2.el5.x86_64
--> Processing Dependency: python-paramiko for package: bzr-2.1.4-2.el5.x86_64
--> Processing Dependency: python-elementtree for package: bzr-2.1.4-2.el5.x86_64
--> Running transaction check
---> Package bzr.x86_64 0:2.1.4-2.el5 will be installed
--> Processing Dependency: python(abi) = 2.4 for package: bzr-2.1.4-2.el5.x86_64
--> Processing Dependency: python-elementtree for package: bzr-2.1.4-2.el5.x86_64
---> Package python-paramiko.noarch 0:1.7.6-1.el5 will be installed
--> Processing Dependency: python(abi) = 2.4 for package: python-paramiko-1.7.6-1.el5.noarch
--> Finished Dependency Resolution
Error: Package: bzr-2.1.4-2.el5.x86_64 (epel)
           Requires: python(abi) = 2.4
           Installed: python-2.6.6-52.el6.x86_64 (@updates)
               python(abi) = 2.6
           Available: python26-2.6.8-2.el5.x86_64 (epel)
               python(abi) = 2.6
Error: Package: python-paramiko-1.7.6-1.el5.noarch (epel)
           Requires: python(abi) = 2.4
           Installed: python-2.6.6-52.el6.x86_64 (@updates)
               python(abi) = 2.6
           Available: python26-2.6.8-2.el5.x86_64 (epel)
               python(abi) = 2.6
Error: Package: bzr-2.1.4-2.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...                ########################################### [100%]
        file /etc/yum.repos.d/epel-testing.repo from install of epel-release-6-8.noarch conflicts with file from package epel-release-5-4.noarch
        file /etc/yum.repos.d/epel.repo from install of epel-release-6-8.noarch conflicts with file from package epel-release-5-4.noarch

二、再安装安装bzr客户端

[root yum.repos.d]$ yum install bzr -y
.....
....... Running Transaction Installing : python
-paramiko-1.7.5-2.1.el6.noarch 1/2 Installing : bzr-2.1.1-2.el6.x86_64 2/2 Installed: bzr.x86_64 0:2.1.1-2.el6 Dependency Installed: python-paramiko.noarch 0:1.7.5-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 128 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.40/ --with-mysql-includes=/usr/local/mysql-5.5.40/include/ > --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

第二种安装方法:

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.12-1.1.tgz [root sysbench-0.4.12-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.12-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-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.12-1.1/sysbench
 [root sysbench]$  ./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 --rand-init=on prepare

若运行过程报以下错:

./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解决方法:
ln -s /usr/local/mysql-5.5.40/lib/libmysqlclient.so.18 /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: 8
Report intermediate results every 10 second(s)
Random number generator seed is 0 and will be ignored


Threads started!
-- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、99%以上的响应时长统计
[  10s] threads: 8, tps: 119.03, reads/s: 1677.65, writes/s: 478.93, response time: 294.40ms (99%)
[  20s] threads: 8, tps: 76.80, reads/s: 1074.47, writes/s: 307.19, response time: 495.75ms (99%)
[  30s] threads: 8, tps: 88.20, reads/s: 1232.94, writes/s: 351.61, response time: 503.98ms (99%)
[  40s] threads: 8, tps: 149.79, reads/s: 2099.73, writes/s: 600.78, response time: 396.18ms (99%)
[  50s] threads: 8, tps: 78.09, reads/s: 1093.32, writes/s: 312.38, response time: 758.12ms (99%)
[  60s] threads: 8, tps: 79.30, reads/s: 1109.76, writes/s: 316.82, response time: 509.75ms (99%)
[  70s] threads: 8, tps: 35.50, reads/s: 497.52, writes/s: 142.41, response time: 956.36ms (99%)
[  80s] threads: 8, tps: 45.40, reads/s: 635.57, writes/s: 180.39, response time: 895.67ms (99%)
[  90s] threads: 8, tps: 73.00, reads/s: 1019.58, writes/s: 290.49, response time: 693.84ms (99%)
[ 100s] threads: 8, tps: 148.01, reads/s: 2069.14, writes/s: 591.64, response time: 472.85ms (99%)
[ 110s] threads: 8, tps: 60.60, reads/s: 850.90, writes/s: 242.90, response time: 1052.81ms (99%)
[ 120s] threads: 8, tps: 88.20, reads/s: 1237.71, writes/s: 354.20, response time: 592.94ms (99%)
OLTP test statistics:
    queries performed:
        read:                            145936  -- 读总数
        write:                           41696   -- 写总数
        other:                           20848   -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
        total:                           208480  -- 全部总数
    transactions:                        10424  (86.74 per sec.)  -- 总事务数(每秒事务数)
    deadlocks:                           0      (0.00 per sec.)   -- 发生死锁总数
    read/write requests:                 187632 (1561.37 per sec.)  -- 读写总数(每秒读写次数)
    other operations:                    20848  (173.49 per sec.)   -- 其他操作总数(每秒其他操作次数)

General statistics:  -- 一些统计结果
    total time:                          120.1714s   -- 总耗时
    total number of events:              10424       -- 共发生多少事务数
    total time taken by event execution: 960.6432s   -- 所有事务耗时相加(不考虑并行因素)
    response time:
         min:                                  5.35ms  -- 最小耗时
         avg:                                 92.16ms  -- 平均耗时
         max:                               3955.05ms  -- 最长耗时
         approx.  99 percentile:             649.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

sysbench安装及性能测试

标签:des   style   blog   http   io   ar   color   os   使用   

原文地址:http://www.cnblogs.com/xuanzhi201111/p/4115346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!