sysbench的安装与使用(with MySQL)
sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。
项目主页: http://sysbench.sourceforge.net/
安装文档http://sysbench.sourceforge.net/docs/#install
但是好像这两天打不开,在这儿提供一个0.4.12版的下载:sysbench-0.4.12.tar.gz
一.安装三步骤:
1.configure
./configure --prefix=/u01/sysbench/ --with-mysql-includes=/usr/include/mysql/ --with-mysql-libs=/usr/lib/mysql/ --with-mysql
其中标红的地方为mysql的2个路径,我在这个地方偷懒用的直接是yum install的方式安装的,所以路径为默认的这个。如果是自定义的,比如/u01/mysql之类的,那么路径就改成相应的就可以了。
2.make
这一步会根据上一步生成的makefile来进行make,但之前的configure里面,生成makefile的时候,是用的32位的包,所以需要ln一下,使用64位的包:
ln -s /usr/lib64/mysql/* /usr/lib/mysql/,再执行autogen.sh,再执行make
3.make install
二.使用
首先,看看sysbench支持哪些功能参数:
[root@monsrv bin]# sysbench --hlp Unknown option: --hlp. Usage: sysbench [general-options]... --test=<test-name> [test-options]... command General options: --num-threads=N number of threads to use [] --max-requests=N limit ] --max-] --forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off] --thread-stack-size=SIZE size of stack per thread [32K] --init-rng=[on|off] initialize random number generator [off] --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 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 oltp - OLTP test Commands: prepare run cleanup help version See 'sysbench --test=<name> help' for a list of options for each test.
从帮助可以看出,sysbench的测试主要包括以下几个方面:
(1)磁盘io性能
(2)cpu性能
(3)内存分配及传输速度
(4)线程性能
(5)mutex性能
(6)OLTP基准测试
2.1 测试fileio命令帮助:
[root@monsrv bin]# sysbench --test=fileio help
sysbench : multi-threaded system evaluation benchmark
fileio options:
--]
--]
--file-total-size=SIZE total size of files to create [2G]
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
--file-io-mode=STRING file operations mode {sync,async,fastmmap,slowmmap} [sync]
--]
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
-- - don't use fsync()) [100]
--file-fsync-all=[on|off] do fsync() after each write operation [off]
--file-fsync-end=[on|off] do fsync() at the end of test [on]
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
-- - don't merge) [0]
--file-rw-ratio=N reads/writes ratio for combined test [1.5]
参数详解:
--file-num=N 代表生成测试文件的数量,默认为128。
--file-block-size=N 测试时所使用文件块的大小,如果想磁盘针对innodb存储引擎进行测试,可以将其设置为16384,即innodb存储引擎页的大小。默认为16384。
--file-total-size=SIZE 创建测试文件的总大小,默认为2G大小。
--file-test-mode=STRING 文件测试模式,包含:seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)。
--file-io-mode=STRING 文件操作的模式,sync(同步),async(异步),fastmmap(快速mmap),slowmmap(慢速mmap),默认为sync同步模式。
--file-async-backlog=N 对应每个线程队列的异步操作数,默认为128。
--file-extra-flags=STRING 打开文件时的选项,这是与API相关的参数。
--file-fsync-freq=N 执行fsync()函数的频率。fsync主要是同步磁盘文件,因为可能有系统和磁盘缓冲的关系。 0代表不使用fsync函数。默认值为100。
--file-fsync-all=[on|off] 每执行完一次写操作,就执行一次fsync。默认为off。
--file-fsync-end=[on|off] 在测试结束时执行fsync函数。默认为on。
--file-fsync-mode=STRING文件同步函数的选择,同样是和API相关的参数,由于多个操作系统对于fdatasync支持不同,因此不建议使用fdatasync。默认为fsync。
--file-merged-requests=N 大多情况下,合并可能的IO的请求数,默认为0。
--file-rw-ratio=N 测试时的读写比例,默认时为1.5,即可3:2。
示例:
生成16个总共2G的文件,进行读写io测试
准备工作:
[root@monsrv bin]# sysbench --test=fileio -- --file-total-size=2G prepare sysbench : multi-threaded system evaluation benchmark files, 131072Kb each, 2048Mb total Creating files for the test...
[root@monsrv bin]# ls -lrth
total 2.1G
-rwxr-xr-x 1 root root 293K Oct 15 16:20 sysbench
-rw------- 1 root root 128M Oct 15 17:38 test_file.0
-rw------- 1 root root 128M Oct 15 17:38 test_file.1
-rw------- 1 root root 128M Oct 15 17:38 test_file.2
-rw------- 1 root root 128M Oct 15 17:39 test_file.3
-rw------- 1 root root 128M Oct 15 17:39 test_file.4
-rw------- 1 root root 128M Oct 15 17:39 test_file.5
-rw------- 1 root root 128M Oct 15 17:39 test_file.6
-rw------- 1 root root 128M Oct 15 17:39 test_file.7
-rw------- 1 root root 128M Oct 15 17:39 test_file.8
-rw------- 1 root root 128M Oct 15 17:39 test_file.9
-rw------- 1 root root 128M Oct 15 17:39 test_file.10
-rw------- 1 root root 128M Oct 15 17:40 test_file.11
-rw------- 1 root root 128M Oct 15 17:40 test_file.12
-rw------- 1 root root 128M Oct 15 17:40 test_file.13
-rw------- 1 root root 128M Oct 15 17:40 test_file.14
-rw------- 1 root root 128M Oct 15 17:40 test_file.15
开始测试:
[root@monsrv bin]# sysbench --test=fileio -- --max-requests= --num-threads= --init-rng=on -- -- -- run
sysbench : multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads:
Initializing random number generator from timer.
Extra
files, 128Mb each
2Gb total file size
Block size 16Kb
Number of random requests
Read/Write ratio for combined random IO test: 1.50
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random read test
Threads started!
Time limit exceeded, exiting...
( times)
Done.
Operations performed: Read, Write, Other = Total
Read .7971Gb Written 0b Total transferred .7971Gb (.288Mb/sec)
1746.43 Requests/sec executed
Test execution summary:
total .0138s
total number of events:
total time taken by event execution: 2879.5979
per-request statistics:
min: .26ms
avg: .16ms
max: .24ms
approx. percentile: .96ms
Threads fairness:
events (avg/stddev): 19648.8750/138.91
execution time (avg/stddev): 179.9749/0.00
[root@monsrv bin]# sysbench --test=fileio -- --max-requests= --num-threads= --init-rng=on -- -- -- run
sysbench : multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads:
Initializing random number generator from timer.
Extra
files, 128Mb each
2Gb total file size
Block size 16Kb
Number of random requests
Read/Write ratio for combined random IO test: 1.50
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random read test
Threads started!
Time limit exceeded, exiting...
( times)
Done.
Operations performed: Read, Write, Other = Total
Read .7867Gb Written 0b Total transferred .7867Gb (.229Mb/sec)
1742.62 Requests/sec executed
Test execution summary:
total .0182s
total number of events:
total time taken by event execution: 2879.6401
per-request statistics:
min: .25ms
avg: .18ms
max: .35ms
approx. percentile: .06ms
Threads fairness:
events (avg/stddev): 19606.5000/85.96
execution time (avg/stddev): 179.9775/0.00
测试结果主要看标黄色的那一段。为了稳定,测了2次,看起来差不多。
测试完成后,需要把测试文件给删掉。
[root@monsrv bin]# sysbench --test=fileio -- --file-total-size=2G cleanup sysbench : multi-threaded system evaluation benchmark Removing test files... [root@monsrv bin]# ls -lrth total 300K -rwxr-xr-x root root 293K Oct : sysbench
2.2 测试cpu命令帮助:
[root@monsrv bin]# sysbench --test=cpu help sysbench : multi-threaded system evaluation benchmark cpu options: --cpu-max-prime=N upper limit ]
参数详解:
--cpu-max-prime=N 用来选项指定最大的素数,具体参数可以根据CPU的性能来设置,默认为10000
2.3 测试memory命令帮助:
[root@monsrv bin]# sysbench --test=memory help
sysbench : multi-threaded system evaluation benchmark
memory options:
--memory-block-size=SIZE size of memory block for test [1K]
--memory-total-size=SIZE total size of data to transfer [100G]
--memory-scope=STRING memory access scope {global,local} [global]
--memory-hugetlb=[on|off] allocate memory from HugeTLB pool [off]
--memory-oper=STRING type of memory operations {read, write, none} [write]
--memory-access-mode=STRING memory access mode {seq,rnd} [seq]
参数详解:
--memory-block-size=SIZE 测试内存块的大小,默认为1K
--memory-total-size=SIZE 数据传输的总大小,默认为100G
--memory-scope=STRING 内存访问的范围,包括全局和本地范围,默认为global
--memory-hugetlb=[on|off] 是否从HugeTLB池分配内存的开关,默认为off
--memory-oper=STRING 内存操作的类型,包括read, write, none,默认为write
--memory-access-mode=STRING 内存访问模式,包括seq,rnd两种模式,默认为seq
2.4 测试threads命令帮助:
[root@monsrv bin]# sysbench --test=threads help sysbench : multi-threaded system evaluation benchmark threads options: --thread-yields=N number of yields to ] --thread-locks=N number of locks per thread []
参数详解:
--thread-yields=N 指定每个请求的压力,默认为1000
--thread-locks=N 指定每个线程的锁数量,默认为8
2.5 测试mutex命令帮助:
[root@monsrv bin]# sysbench --test=mutex help sysbench : multi-threaded system evaluation benchmark mutex options: --mutex-num=N total size of mutex array [] --mutex-locks=N number of mutex locks to ] --mutex-loops=N number of empty loops to ]
参数详解:
--mutex-num=N 数组互斥的总大小。默认是4096
--mutex-locks=N 每个线程互斥锁的数量。默认是50000
--mutex-loops=N 内部互斥锁的空循环数量。默认是10000
2.6 测试oltp命令帮助:
[root@monsrv bin]# sysbench --test=oltp help
sysbench : multi-threaded system evaluation benchmark
oltp options:
--oltp-test-mode=STRING test type to use {simple,complex,nontrx,sp} [complex]
--oltp-reconnect-mode=STRING reconnect mode {session,transaction,query,random} [session]
--oltp-sp-name=STRING name of store procedure to call in SP test mode []
--oltp-read-only=[on|off] generate only 'read' queries (do not modify database) [off]
--oltp-skip-trx=[on|off] skip BEGIN/COMMIT statements [off]
--oltp-range-size=N range size ]
--oltp-point-selects=N number of point selects []
--oltp-simple-ranges=N number of simple ranges []
--oltp-]
--oltp-order-ranges=N number of ordered ranges []
--oltp-distinct-ranges=N number of distinct ranges []
--oltp-index-updates=N number of index update []
--oltp-non-index-updates=N number of non-index updates []
--oltp-nontrx-mode=STRING mode for non-transactional test {select, update_key, update_nokey, insert, delete} [select]
--oltp-auto-inc=[on|off] whether AUTO_INCREMENT (or equivalent) should be used on id column [on]
--oltp-connect-delay=N ]
--oltp-user-delay-min=N minimum ]
--oltp-user-delay-max=N maximum ]
--oltp-table-name=STRING name of test table [sbtest]
--oltp-table-size=N number of records ]
--oltp-dist-type=STRING random numbers distribution {uniform,gaussian,special} [special]
--oltp-dist-iter=N number of iterations used ]
--oltp-dist-pct=N percentage of values to be treated as ]
--oltp-dist-res=N percentage of ]
General database options:
--db-driver=STRING specifies database driver to use ('help' to get list of available drivers)
--db-ps-mode=STRING prepared statements usage mode {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 []
--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 ]
--mysql-create-options=STRING additional options passed to CREATE TABLE []
参数详解:
--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
示例:
首先准备sbest测试表,因为脚本默认不会建库,那么需要先在MySQL中吧库建好,当然也可以用参数--mysql-db指定数据库。
[root@monsrv ~]# sysbench --test=oltp --num-threads= --max-requests= --oltp-test-mode=complex --db-driver=mysql --mysql-db=sbtest --mysql-host= --mysql-user=root --mysql-password=aostarit --oltp-nontrx-mode=select --db-ps-mode=disable prepare sysbench : multi-threaded system evaluation benchmark Creating table 'sbtest'... Creating records in table 'sbtest'...
接着就是测试了。我在这儿设置了80000个请求,也就是说这个测试需要做完80000个request才会停止,可以适当的调整。
[root@monsrv ~]# sysbench --test=oltp --num-threads= --max-requests= --oltp-test-mode=complex --db-driver=mysql --mysql-db=sbtest --mysql-host= --mysql-user=root --mysql-password=aostarit --oltp-nontrx-mode=select --db-ps-mode=disable run
sysbench : multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads:
Doing OLTP test.
Running mixed OLTP test
Using Special distribution ( iterations, pct of values are returned pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests
Threads started!
Done.
OLTP test statistics:
queries performed:
read:
other:
total:
transactions: (42.98 per sec.)
deadlocks: (0.00 per sec.)
read/ (816.54 per sec.)
other operations: (85.95 per sec.)
Test execution summary:
total .5174s
total number of events:
total time taken by event execution: 1860.8692
per-request statistics:
min: .08ms
avg: .26ms
max: .62ms
approx. percentile: .32ms
Threads fairness:
events (avg/stddev): 80000.0000/0.00
execution time (avg/stddev): 1860.8692/0.00
[root@monsrv ~]#
最后就是清除
sysbench的安装与使用(with MySQL)的更多相关文章
- sysbench 环境安装,压测mysql
源码路径:https://github.com/akopytov/sysbench 版本linux 6.8sysbench 0.5mysql 5.6.29 1.安装pip略 2.pip 安装bzr p ...
- MySQL性能测试工具sysbench的安装和使用
sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL.Oracle和PostgreSQL.当前 ...
- 安装特定版本 sysbench 以及安装时指定特定的mysql客户端
step1: 下载安装源码 https://github.com/akopytov/sysbench (git clone https://github.com/akopytov/sysbench.g ...
- CentOS6.6系统源代码安装mysql5.5.28教程(附源码包下载地址)+sysbench的安装
mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档(※ 非常重要) http://dev.mysql.com/ ...
- sysbench工具安装使用
一.sysbench简介 Sysbench是一款开源的.跨平台的.模块化的.多线程的性能测试工具,通过高负载地运行在数据库上,可以执行CPU.内存.线程.IO.数据库等方面的性能测试.用于评估操作系统 ...
- sysbench的安装和做性能测试
sysbench的安装和做性能测试 http://imysql.cn/node/312 sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况. ...
- sysbench的安装详解
sysbench是一个压力测试工具.可以用它来测试cpu.mem.disk.thread.mysql.postgr.oracle:然而作为一个mysql dba 我当然是用它来压测mysql啦! 一. ...
- 【转帖】sysbench的安装和做性能测试
iMySQL | 老叶茶馆 sysbench的安装和做性能测试 http://imysql.cn/node/312 我仿照这个学的 但是 需要用更新的版本才可以. By yejr on 14 六月 ...
- Linux 性能测试工具 sysbench 的安装与简单使用
文章目录 Linux 性能测试工具 sysbench 的安装与简单使用 一 背景 二 实验环境 2.1 操作系统 2.2 其他配 ...
- MySql免安装版安装配置,附MySQL服务无法启动解决方案
文首提要: 我下载的MySQL版本是:mysql-5.7.17-winx64.zip Archive版:系统:Windows7 64位. 一.解压文件 下载好My ...
随机推荐
- WCF错误:由于目标计算机积极拒绝,无法连接
今天学习WCF时用C#重写测试例子时,发生错误:由于目标计算机积极拒绝,无法连接.找了N久,网上也没有找到实际的解决方法.查看netstat -an发现当自承载宿主运行时,没有侦听配置的端口.开始总以 ...
- MapReduce实现手机上网日志分析(排序)
一.背景 1.1 流程 实现排序,分组拍上一篇通过Partitioner实现了. 实现接口,自动产生接口方法,写属性,产生getter和setter,序列化和反序列化属性,写比较方法,重写toStri ...
- Unity 小问题
Cannot cast from source type to destination 我用Object 转 int 会出现这个错误提示 例如 : object p; int pp = (int)p; ...
- UVa 11987 Almost Union-Find(支持删除操作的并查集)
传送门 Description I hope you know the beautiful Union-Find structure. In this problem, you’re to imple ...
- sqlserver text/ntext 字段读取
sqlserver ntext 字段在读取时返回值 net.sourceforge.jtds.jdbc.ClobImpl@555bc78f 需要在连接数据库的URL后边加上";useLOBs ...
- 面试题目——《CC150》递归与动态规划
面试题9.1:有个小孩正在上楼梯,楼梯有n个台阶,小孩一次可以上1阶.2阶或者3阶.实现一个方法,计算小孩有多少种上楼梯的方式. 思路:第4个数是前三个数之和 注意:能不能使用递归,能不能建立一个很大 ...
- 让Web页面中的编辑器支持黏贴或直接拖拽来添加图片
基本原理是将剪贴板中的图片二进制数据转为Base64编码 代码: <html> <head> </head> <body> <script src ...
- HashMap Hasptable的区别
HashTable的应用非常广泛,HashMap是新框架中用来代替HashTable的类,也就是说建议使用HashMap,不要使用HashTable.可能你觉得HashTable很好用,为什么不用呢? ...
- [Unity] Shader(着色器)输入输出和语义
在Unity5.x后, 已经支持了基于物理的光照模型,也就是常说的次时代引擎所必须具备的功能. 如果在Properties使用2D,CG里要用sampler2D,代表使用的是2维纹理 如果在Prope ...
- NOIP2012同余方程
描述 求关于 x的同余方程 ax ≡ 1(mod b) 的最小正整数解. 输入格式 输入文件 mod.in输入只有一行,包含两个正整数a,b,用一个空格隔开. 输出格式 输出文件 为 modmod ...