From:http://www.cnblogs.com/zhoujinyi/archive/2013/04/19/3029134.html

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

file I/O performance (文件I / O性能)
scheduler performance (调度性能)
memory allocation and transfer speed (内存分配和传输速度)
POSIX threads implementation performance (POSIX线程执行绩效)
database server performance (OLTP benchmark) (数据库服务器性能)

安装:
     
1):Ubuntu系统可以直接apt,如:

apt-get install sysbench

2):其他系统的则可以编译安装[在/home/zhoujy/目录下]:(安装前先装automake,libtool)

wget http://nchc.dl.sourceforge.net/project/sysbench/sysbench/0.4.12/sysbench-0.4.12.tar.gz
tar zxvf sysbench-0.4.12.tar.gz
进入解压目录,并且创建安装目录:
root@m2:/home/zhoujy# cd sysbench-0.4.12/
root@m2:/home/zhoujy/sysbench-0.4.12# mkdir /usr/sysbench/
准备编译
root@m2:/home/zhoujy/sysbench-0.4.12# apt-get install automake
root@m2:/home/zhoujy/sysbench-0.4.12#apt-get install libtool
root@m2:/home/zhoujy/sysbench-0.4.12# ./autogen.sh

要是出现:perl: warning: Falling back to the standard locale ("C")。则需要设置locale:

echo "export LC_ALL=C" >> /root/.bashrc
source /root/.bashrc

要是没有安装开发包,即/usr/include/ 目录下面没有mysql文件夹。则需要执行安装(版本为12.04):

sudo apt-get install libmysqlclient-dev
sudo apt-get install libmysqld-dev
sudo apt-get install libmysqld-pic

执行configure操作:

./configure --prefix=/usr/sysbench/ --with-mysql-includes=/usr/include/mysql/ --with-mysql-libs=/usr/lib/mysql/ --with-mysql
说明:
--prefix=/usr/sysbench/ :指定sysbench的安装目录。
--with-mysql-includes=/usr/include/mysql/ :指定安装mysql时候的includes目录。
--with-mysql-libs=/usr/lib/mysql/ :指定装mysql时候的lib目录。
--with-mysql :sysbench默认支持mysql,如果需要测试oracle或者pgsql则需要制定–with-oracle或者–with-pgsql。

在这里需要先执行:

cp /usr/bin/libtool /home/zhoujy/sysbench-0.4.12/libtool

再make和make install。否者会出现 libtool 报出的 Xsysbench: command not found  错误,则表示编译文件包的libtool版本太低,需要替换。

选项说明(通用):

root@db2:~# sysbench
Missing required command argument.
Usage: #使用方法
sysbench [general-options]... --test=<test-name> [test-options]... command General options: #通用选项
--num-threads=N number of threads to use [1] #创建测试线程的数目。默认为1.
--max-requests=N limit for total number of requests [10000] #请求的最大数目。默认为10000,0代表不限制。
--max-time=N limit for total execution time in seconds [0] #最大执行时间,单位是s。默认是0,不限制。
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off] #超过max-time强制中断。默认是off。
--thread-stack-size=SIZE size of stack per thread [32K] #每个线程的堆栈大小。默认是32K。
--init-rng=[on|off] initialize random number generator [off] #在测试开始时是否初始化随机数发生器。默认是off。
--test=STRING test to run #指定测试项目名称。
--debug=[on|off] print more debugging info [off] #是否显示更多的调试信息。默认是off。
--validate=[on|off] perform validation checks where possible [off] #在可能情况下执行验证检查。默认是off。
--help=[on|off] print help and exit #帮助信息。
--version=[on|off] print version and exit #版本信息。 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 #互斥性能测试
oltp - OLTP test # 数据库,事务处理 Commands: prepare:测试前准备工作; run:正式测试 cleanup:测试后删掉测试数据 help version See 'sysbench --test=<name> help' for a list of options for each test. #查看每个测试项目的更多选项列表

更多选项:
1):sysbench  --test=fileio help

2):sysbench  --test=cpu help

3):sysbench  --test=memory help

4):sysbench  --test=threads help

5):sysbench  --test=mutex help

6): sysbench --test=oltp help

root@db2:~# sysbench --test=oltp help
sysbench 0.4.12: multi-threaded system evaluation benchmark oltp options:
--oltp-test-mode=STRING 执行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默认是complex
--oltp-reconnect-mode=STRING 重新连接模式{session(不使用重新连接。每个线程断开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个SQL语句执行完重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是session
--oltp-sp-name=STRING 存储过程的名称。默认为空
--oltp-read-only=[on|off] 只读模式。Update,delete,insert语句不可执行。默认是off
--oltp-skip-trx=[on|off] 省略begin/commit语句。默认是off
--oltp-range-size=N 查询范围。默认是100
--oltp-point-selects=N number of point selects [10]
--oltp-simple-ranges=N number of simple ranges [1]
--oltp-sum-ranges=N number of sum ranges [1]
--oltp-order-ranges=N number of ordered ranges [1]
--oltp-distinct-ranges=N number of distinct ranges [1]
--oltp-index-updates=N number of index update [1]
--oltp-non-index-updates=N number of non-index updates [1]
--oltp-nontrx-mode=STRING 查询类型对于非事务执行模式{select, update_key, update_nokey, insert, delete} [select]
--oltp-auto-inc=[on|off] AUTO_INCREMENT是否开启。默认是on
--oltp-connect-delay=N 在多少微秒后连接数据库。默认是10000
--oltp-user-delay-min=N 每个请求最短等待时间。单位是ms。默认是0
--oltp-user-delay-max=N 每个请求最长等待时间。单位是ms。默认是0
--oltp-table-name=STRING 测试时使用到的表名。默认是sbtest
--oltp-table-size=N 测试表的记录数。默认是10000
--oltp-dist-type=STRING 分布的随机数{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是special
--oltp-dist-iter=N 产生数的迭代次数。默认是12
--oltp-dist-pct=N 值的百分比被视为'special' (for special distribution)。默认是1
--oltp-dist-res=N ‘special’的百分比值。默认是75 General database options:
--db-driver=STRING 数据库类型,指定数据库驱动程序('help' to get list of available drivers)
--db-ps-mode=STRING 数据库预处理模式{auto, disable} [auto]
Compiled-in database drivers:
mysql - MySQL driver
mysql options:
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=N MySQL server port [3306]
--mysql-socket=STRING MySQL socket
--mysql-user=STRING MySQL user [sbtest]
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
--mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]
--mysql-ssl=[on|off] use SSL connections, if available in the client library [off]
--myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]
--mysql-create-options=STRING additional options passed to CREATE TABLE []

测试:
1)测试CPU: sysbench --test=cpu --cpu-max-prime=2000 run

2)测试线程:sysbench  --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run

3)测试IO:--num-threads 开启的线程     --file-total-size 总的文件大小
1,prepare阶段,生成需要的测试文件,完成后会在当前目录下生成很多小文件。
sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare    
2,run阶段
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run
3,清理测试时生成的文件
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup

4)测试内存:sysbench --test=memory --memory-block-size=8k --memory-total-size=1G run

5)测试mutex:sysbench –test=mutex –num-threads=100 –mutex-num=1000 –mutex-locks=100000 –mutex-loops=10000 run

6)测试OLTP:
1,prepare阶段,生成需要的测试表
sysbench
--test=oltp --mysql-table-engine=innodb --mysql-host=192.168.X.X
--mysql-db=test --oltp-table-size=500000 --mysql-user=root
--mysql-password=123456 prepare
2,run阶段
sysbench
--num-threads=16 --test=oltp --mysql-table-engine=innodb
--mysql-host=192.168.x.x --mysql-db=test --oltp-table-size=500000
--mysql-user=root --mysql-password=123456 run
3,清理测试时生成的测试表
sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb
--mysql-host=192.168.x.x --mysql-db=test --oltp-table-size=500000
--mysql-user=root --mysql-password=123456 cleanup

root@db2:~# sysbench --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=rep_test --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark No DB drivers specified, using mysql
Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...
root@db2:~# sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=rep_test --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 run
sysbench 0.4.12: multi-threaded system evaluation benchmark No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 16 Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Threads started!
Done. OLTP test statistics:
queries performed:
read: 140000
write: 50000
other: 20000
total: 210000
#—-事务数总计,每秒的事务处理量
transactions: 10000 (356.98 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 190000 (6782.56 per sec.)
other operations: 20000 (713.95 per sec.)
Test execution summary:
total time: 28.0130s
total number of events: 10000
total time taken by event execution: 447.7731
per-request statistics:
min: 3.91ms
avg: 44.78ms
max: 207.61ms
approx. 95 percentile: 76.48ms Threads fairness:
events (avg/stddev): 625.0000/22.96
execution time (avg/stddev): 27.9858/0.01 root@db2:~# sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=rep_test --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 cleanup
sysbench 0.4.12: multi-threaded system evaluation benchmark No DB drivers specified, using mysql
Dropping table 'sbtest'...
Done.

测试表信息:

mysql> desc sbtest;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| k | int(10) unsigned | NO | MUL | 0 | |
| c | char(120) | NO | | | |
| pad | char(60) | NO | | | |
+-------+------------------+------+-----+---------+----------------+
4 rows in set (0.01 sec) mysql> show create table sbtest\G;
*************************** 1. row ***************************
Table: sbtest
Create Table: CREATE TABLE `sbtest` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`k` int(10) unsigned NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
`pad` char(60) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `k` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8
1 row in set (0.01 sec) ERROR:
No query specified mysql> select count(*) from sbtest;
+----------+
| count(*) |
+----------+
| 1000000 |
+----------+
1 row in set (0.30 sec)
mysql> desc sbtest;
ERROR 1146 (42S02): Table 'rep_test.sbtest' doesn't exist

可以用这个测试:

sysbench --num-threads=4 --test=oltp --oltp-reconnect-mode=random --mysql-table-engine=innodb --mysql-host=192.168.200.201 --mysql-db=rep_test --ol
tp-table-size=500000 --mysql-user=zjy --mysql-password=1234#

###################################更新2016-07-27

今天使用sysbench的时候,发现0.5版本已经没有 --test=oltp的参数,现在就更新说明下0.5版本的sysbench 如何使用oltp的测试。

① 安装:通过apt-get install sysbench

root@t22:~# sysbench --test=oltp help
sysbench 0.5: multi-threaded system evaluation benchmark PANIC: unprotected error in call to Lua API (cannot open oltp: No such file or directory)

sysbench 0.5相比0.4版本有一些变化,包括oltp测试结合了lua脚本。通过dpkg -L sysbench查看相关文件:

root@t22:~# dpkg -L sysbench
/.
/usr
/usr/bin
/usr/bin/sysbench
/usr/share
/usr/share/doc
/usr/share/doc/sysbench
/usr/share/doc/sysbench/copyright
/usr/share/doc/sysbench/TODO
/usr/share/doc/sysbench/changelog.Debian.gz
/usr/share/doc/sysbench/README
/usr/share/doc/sysbench/manual.html
/usr/share/doc/sysbench/tests
/usr/share/doc/sysbench/tests/db
/usr/share/doc/sysbench/tests/db/oltp_simple.lua
/usr/share/doc/sysbench/tests/db/insert.lua
/usr/share/doc/sysbench/tests/db/select_random_ranges.lua
/usr/share/doc/sysbench/tests/db/oltp.lua
/usr/share/doc/sysbench/tests/db/common.lua
/usr/share/doc/sysbench/tests/db/select_random_points.lua
/usr/share/doc/sysbench/tests/db/delete.lua
/usr/share/doc/sysbench/tests/db/update_non_index.lua
/usr/share/doc/sysbench/tests/db/update_index.lua
/usr/share/doc/sysbench/tests/db/parallel_prepare.lua
/usr/share/doc/sysbench/tests/db/select.lua

②:参数介绍

--test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
--mysql-table-engine=innodb 表示选择测试表的存储引擎
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000
--rand-init=on 表示每个测试表都是用随机数据来填充的
如果在本机,也可以使用 –mysql-socket 指定 socket 文件来连接。加载测试数据时长视数据量而定,若过程比较久需要稍加耐心等待。
--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安装、使用、结果解读使用sysbench对mysql压力测试

③:使用说明

初始化数据:prepare。在本地数据库的dba_test库中,初始化三张表(sbtest1、sbtest2、sbtest3),存储引擎是innodb,每张表50万数据。

sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-db=dba_test --oltp-table-size=500000 --oltp_tables_count=3 --rand-init=on --mysql-user=zjy --mysql-password=zjy  prepare

因为是本机测试,所以也可以用也可以使用--mysql-socket指定socket文件来连接。

测试:run。模拟对3个表并发OLTP测试,每个表50万行记录,持续压测时间为5分钟。

sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-db=dba_test --num-threads=8 --oltp-table-size=500000 --oltp_tables_count=3 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=600 --max-requests=0 --percentile=99 --mysql-user=zjy --mysql-password=zjy run

上面跑完会出一个结果:

#每10秒钟报告一次测试结果,tps、每秒读、每秒写、95%以上的响应时长统计
[ 10s] threads: 8, tps: 66.60, reads: 943.67, writes: 269.62, response time: 431.72ms (95%), errors: 0.00, reconnects: 0.00
[ 20s] threads: 8, tps: 34.30, reads: 480.20, writes: 137.20, response time: 598.28ms (95%), errors: 0.00, reconnects: 0.00
[ 30s] threads: 8, tps: 36.60, reads: 512.40, writes: 146.40, response time: 494.87ms (95%), errors: 0.00, reconnects: 0.00 OLTP test statistics:
queries performed:
read: 941248 #读总数
write: 268928 #写总数
other: 134464 #其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
total: 1344640 #全部总数
transactions: 67232 (112.04 per sec.) #总事务数(每秒事务数)
read/write requests: 1210176 (2016.73 per sec.) #读写总数(每秒读写次数)
other operations: 134464 (224.08 per sec.) #其他操作总数(每秒其他操作次数)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.) General statistics:
total time: 600.0698s #总耗时
total number of events: 67232 #共发生多少事务数
total time taken by event execution: 4799.8569s # 所有事务耗时相加(不考虑并行因素)
response time:
min: 2.09ms #最小耗时
avg: 71.39ms #平均耗时
max: 839.32ms #最大耗时
approx. 95 percentile: 309.40ms 超过95%平均耗时 Threads fairness:
events (avg/stddev): 8404.0000/17.56
execution time (avg/stddev): 599.9821/0.02

清理数据:cleanup

 sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-db=dba_test --num-threads=8 --oltp-table-size=500000 --oltp_tables_count=3 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=600 --max-requests=0 --mysql-user=zjy --mysql-password=zjy  cleanup

更多0.5版本的sysbench可以看sysbench安装、使用、结果解读使用sysbench对mysql压力测试

Mysql多线程性能测试工具sysbench 安装、使用和测试的更多相关文章

  1. 开源多线程性能测试工具-sysbench

    导读 sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试.数据库目前支持MySQL/Oracle/PostgreSQL.本文主要演示Mysql测试 ...

  2. MySQL性能测试工具sysbench的安装和使用

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

  3. Linux 性能测试工具 sysbench 的安装与简单使用

    文章目录 Linux 性能测试工具 sysbench 的安装与简单使用        一 背景        二 实验环境            2.1 操作系统            2.2 其他配 ...

  4. MySQL多线程备份工具:mydumper

    MySQL多线程备份工具:mydumper http://www.orczhou.com/index.php/2011/12/how-to-split-mysqldump-file/ Mydumper ...

  5. python操作三大主流数据库(3)python操作mysql③python操作mysql的orm工具sqlaichemy安装配置和使用

    python操作mysql③python操作mysql的orm工具sqlaichemy安装配置和使用 手册地址: http://docs.sqlalchemy.org/en/rel_1_1/orm/i ...

  6. 安装性能测试工具:sysbench和使用apache的ab

    一.软件的用途,它主要包括以下几种方式的测试:1.cpu性能2.磁盘io性能3.调度程序性能4.内存分配及传输速度5.POSIX线程性能6.数据库性能(OLTP基准测试) 这个软件为什么找不到官网呢? ...

  7. MySQL 常用工具sysbench/fio/tpcc等测试

    为什么要压力测试采购新设备,评估新设备性能开发新项目,评估数据库容量新系统上线前,预估/模拟数据库负载更换数据库版本,评估性能变化 关注指标  CPU %wait,%user,%sys 内存 只内存读 ...

  8. 性能测试工具 wrk 安装与使用

    介绍 今天给大家介绍一款开源的性能测试工具 wrk,简单易用,没有Load Runner那么复杂,他和 apache benchmark(ab)同属于性能测试工具,但是比 ab 功能更加强大,并且可以 ...

  9. 云存储性能测试工具--COSBench安装

    COSBench安装 Cosbench是Intel的开源云存储性能测试软件,COSBench目前已经广泛使用与云存储测试,并作为云存储的基准测试工具使用 1 环境 1.1 操作系统 COSBench可 ...

随机推荐

  1. 九度oj 题目1465:最简真分数

    题目描述: 给出n个正整数,任取两个数分别作为分子和分母组成最简真分数,编程求共有几个这样的组合. 输入: 输入有多组,每组包含n(n<=600)和n个不同的整数,整数大于1且小于等于1000. ...

  2. python相关——如何安装pip

    今天在新的一台电脑上安装了pip.流程有点忘记了,在这里再次记录下来. 本教程基于python3.4,并且需要连接互联网,总共需要两步. 1.要安装pip,首先要安装setuptools,链接:htt ...

  3. iOS启动动画效果实现

    原理 在window上加一个UIImageView它的图片和启动图的图片一样,然后再调整动画 运行展示 demo百度云连接:http://pan.baidu.com/s/1c0QcYu0 more:网 ...

  4. iOS学习笔记25-录音和网络流媒体

    .录音 AVFoundation框架还有一个AVAudioRecorder类专门处理录音操作,它同样支持多种音频格式. 先来了解下AVAudioRecorder的常用属性: @property (re ...

  5. Java-约瑟夫问题(Josephus Problem)

    题目: 据说着名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特后,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人到,于是决定了一个自杀方 ...

  6. XSD(XML Schema Definition)学习笔记

    今天学习了XSD相关的知识,为了以后查找的方便,写一些笔记. 一.什么是XSD? 1.XSD全称:XML Schema Definition.XML Schema 的作用是定义 XML 文档的合法构建 ...

  7. LeetCode OJ--Binary Tree Postorder Traversal

    http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ 树的后序遍历,可以使用递归,也可以使用栈,下面是栈的实现代码 #inc ...

  8. AC日记——Propagating tree Codeforces 383c

    C. Propagating tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. AC日记——Housewife Wind poj 2763

    Language: Default Housewife Wind Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 10525 ...

  10. WKWebView与js交互中产生的内存泄漏

    最近开发中突然发现富文本帖子详情内存没有释放掉,找了好久问题都没找到,终于今天发现了问题,先上一点代码片段 WKWebViewConfiguration *configuration = [[WKWe ...