sysbench 0.5 基准测试
sysbench 介绍
SysBench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。它主要包括以下几种方式的测试:
- cpu性能
- 磁盘io性能
- 调度程序性能
- 内存分配及传输速度
- POSIX线程性能
- 数据库性能(OLTP基准测试)
目前sysbench主要支持 MySQL,pgsql,Oracle 这3种数据库。
sysbench 安装
默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上–with-oracle或者–with-pgsql参数,
sysbench默认安装在: /usr/local/bin/sysbench
shell> tar -zxvf sysbench-0.5.tar.gz -C /db/tool/
shell> cd /db/tool/sysbench-0.5
shell> chmod +x autogen.sh shell> ./autogen.sh
automake 1.10.x (aclocal) wasn't found, exiting
shell> yum install automake
shell> ./autogen.sh
libtoolize 1.4+ wasn't found, exiting
shell> yum install libtool shell> ./autogen.sh
./autogen.sh
./autogen.sh: running `aclocal -I m4'
./autogen.sh: running `libtoolize --copy --force'
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'.
libtoolize: copying file `config/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
./autogen.sh: running `autoheader'
./autogen.sh: running `automake -c --foreign --add-missing'
configure.ac:23: installing `config/compile'
configure.ac:11: installing `config/config.guess'
configure.ac:11: installing `config/config.sub'
configure.ac:16: installing `config/install-sh'
configure.ac:16: installing `config/missing'
sysbench/Makefile.am: installing `config/depcomp'
./autogen.sh: running `autoconf'
Libtoolized with: libtoolize (GNU libtool) 2.2.6b
Automade with: automake (GNU automake) 1.11.1
Configured with: autoconf (GNU Autoconf) 2.63 shell> ./configure --prefix=/db/sysbench --with-mysql-includes=/db/mysql/include --with-mysql-libs=/db/mysql/lib
shell> make && make install 测试安装
shell> cp /db/sysbench/bin/sysbench /usr/local/bin/ shell> sysbench --help
sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file:
No such file or directory
问题原因:sysbench无法找到mysql的库文件,可能是环境变量LD_LIBRARY_PATH没有设置,设置后即可解决该问题:
添加export LD_LIBRARY_PATH=/db/mysql/lib即可
sysbench 参数
shell> sysbench --help
Missing required command argument.
Usage:
sysbench [general-options]... --test= [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]
--tx-jitter=N target transaction variation, in microseconds [0]
--report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables
intermediate reports [0]
--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} [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] 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
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test Commands: prepare run cleanup help version See 'sysbench --test= help' for a list of options for each test.
CPU测试
sysbench CPU测试使用64位整数,测试计算素数直到某个最大值所需要的时间
shell> sysbench --test=cpu --cpu-max-prime=2000 run
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored Primer numbers limit: 2000 Threads started! Test execution summary:
total time: 2.2452s
total number of events: 10000
total time taken by event execution: 2.2347s
per-request statistics:
min: 0.20ms
avg: 0.22ms
max: 3.35ms
approx. 95 percentile: 0.27ms Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 2.2347/0.00 补充:
查看CPU信息方法
查看物理cpu个数
grep "physical id" /proc/cpuinfo | sort -u | wc -l
查看核心数量
grep "core id" /proc/cpuinfo | sort -u | wc -l
查看线程数量
grep "processor" /proc/cpuinfo | sort -u | wc -l 在sysbench的测试中,--num-threads取值为"线程数量"即可
线程(thread)测试
测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用
shell> sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 64
Random number generator seed is 0 and will be ignored Threads started! Test execution summary:
total time: 1.9581s
total number of events: 10000
total time taken by event execution: 124.8938s
per-request statistics:
min: 0.05ms
avg: 12.49ms
max: 151.15ms
approx. 95 percentile: 50.83ms Threads fairness:
events (avg/stddev): 156.2500/14.48
execution time (avg/stddev): 1.9515/0.00
文件IO性能测试
- 生成需要的测试文件,文件总大小5G,16个并发线程。执行完后会在当前目录下生成一堆小文件。
shell> sysbench --test=fileio --num-threads=16 --file-total-size=5G prepare
- 执行测试,指定随机读写模式
指定读写模式:
- seqwr 顺序写入
- seqrewr 顺序重写
- seqrd 顺序读取
- rndrd 随机读取
- rndwr 随机写入
- rndrw 混合随机读/写
shell> sysbench --test=fileio --num-threads=16 --init-rng=on --file-total-size=5G --file-test-mode=rndrw run
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored Threads started! Operations performed: 5999 reads, 4001 writes, 12800 Other = 22800 Total
Read 93.734Mb Written 62.516Mb Total transferred 156.25Mb (9.2561Mb/sec) ##吞吐量
592.39 Requests/sec executed Test execution summary:
total time: 16.8808s
total number of events: 10000
total time taken by event execution: 176.1816s
per-request statistics:
min: 0.01ms
avg: 17.62ms
max: 416.73ms
approx. 95 percentile: 104.82ms Threads fairness:
events (avg/stddev): 625.0000/62.39
execution time (avg/stddev): 11.0114/0.67
- 清除测试文件
shell> sysbench --test=fileio --num-threads=16 --file-total-size=5G cleanup
互斥锁(Mutex)测试
测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁。
shell> sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored Threads started! Test execution summary:
total time: 0.0135s
total number of events: 16
total time taken by event execution: 0.0411s
per-request statistics:
min: 0.70ms
avg: 2.57ms
max: 9.19ms
approx. 95 percentile: 9.16ms Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 0.0026/0.00
内存测试
内存测试测试了内存的连续读写性能。
shell> sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=1G run
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored Threads started! Operations performed: 131072 (381158.38 ops/sec) 1024.00 MB transferred (2977.80 MB/sec) ##吞吐量 Test execution summary:
total time: 0.3439s
total number of events: 131072
total time taken by event execution: 3.9915s
per-request statistics:
min: 0.00ms
avg: 0.03ms
max: 51.02ms
approx. 95 percentile: 0.00ms ##大约95%的时间分布 Threads fairness:
events (avg/stddev): 8192.0000/1166.77
execution time (avg/stddev): 0.2495/0.02
MySQL数据库测试
sysbench 0.5通过一系列LUA脚本来替换之前的oltp,来模拟更接近真实的基准测试环境。这些测试脚本包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua,脚本使用方式基本类似。
sysbench 0.5默认使用sbtest库,但是需要自己手工先创建好,也可以使用--mysql-db指定,其他非默认项指定选项:
- -mysql-host
- -mysql-port
- -mysql-socket
- -mysql-user
- -mysql-password
- -mysql-db
- -mysql-ssl
- prepare
生成表并插入数据,可使用parallel_prepare.lua脚本来并行准备数据。
- –db-driver 服务器类型 mysql | drizzle,默认为mysql
- –mysql-table-engine 表存数引擎
- –myisam-max-rows MyISAM表MAX_ROWS选项(用于大表)
- –oltp-table-count 生成表数量[sbtest1、sbtest2...]
- –oltp-table-size 生成表的行数
- –oltp-secondary ID列生成二级索引而不是主键
- –oltp-auto-inc 设置ID列是否自增 on | off,默认为on
shell> cd /db/tool/sysbench-0.5/sysbench
shell> sysbench --test=./tests/db/oltp.lua --mysql-table-engine=myisam --oltp-table-size=100000 --mysql-db=test
--mysql-user=root --oltp-tables-count=10 --mysql-password=oracle --mysql-socket=/tmp/mysql.sock prepare
sysbench 0.5: multi-threaded system evaluation benchmark Creating table 'sbtest1'...
Inserting 100000 records into 'sbtest1'
Creating table 'sbtest2'...
Inserting 100000 records into 'sbtest2'
Creating table 'sbtest3'...
Inserting 100000 records into 'sbtest3'
Creating table 'sbtest4'...
Inserting 100000 records into 'sbtest4'
Creating table 'sbtest5'...
Inserting 100000 records into 'sbtest5'
Creating table 'sbtest6'...
Inserting 100000 records into 'sbtest6'
Creating table 'sbtest7'...
Inserting 100000 records into 'sbtest7'
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest8'
Creating table 'sbtest9'...
Inserting 100000 records into 'sbtest9'
Creating table 'sbtest10'...
Inserting 100000 records into 'sbtest10' 也可使用parallel_prepare.lua脚本并行准备测试数据,线程数应该为运行表的倍数
shell> sysbench --test=./tests/db/parallel_prepare.lua --mysql-table-engine=myisam --oltp-table-size=100000
--num-threads=10 --mysql-db=test --mysql-user=root --oltp-tables-count=10 --mysql-password=oracle
--mysql-socket=/tmp/mysql.sock run sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 10
Random number generator seed is 0 and will be ignored Threads started! thread prepare8
Creating table 'sbtest9'...
thread prepare1
Creating table 'sbtest2'...
thread prepare0
Creating table 'sbtest1'...
thread prepare5
Creating table 'sbtest6'...
thread prepare3
Creating table 'sbtest4'...
thread prepare6
Creating table 'sbtest7'...
thread prepare9
Creating table 'sbtest10'...
thread prepare4
Creating table 'sbtest5'...
thread prepare2
Creating table 'sbtest3'...
thread prepare7
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest1'
Inserting 100000 records into 'sbtest9'
Inserting 100000 records into 'sbtest8'
Inserting 100000 records into 'sbtest6'
Inserting 100000 records into 'sbtest7'
Inserting 100000 records into 'sbtest2'
Inserting 100000 records into 'sbtest10'
Inserting 100000 records into 'sbtest4'
Inserting 100000 records into 'sbtest5'
Inserting 100000 records into 'sbtest3'
OLTP test statistics:
queries performed:
read: 0
write: 380
other: 20
total: 400
transactions: 0 (0.00 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 380 (32.82 per sec.)
other operations: 20 (1.73 per sec.) Test execution summary:
total time: 11.5785s
total number of events: 10000
total time taken by event execution: 0.1422s
per-request statistics:
min: 0.00ms
avg: 0.01ms
max: 19.55ms
approx. 95 percentile: 0.00ms
http://ww3.sinaimg.cn/bmiddle/671c4d8egw1enjimkujv2g20b40b4b29.gif
Threads fairness:
events (avg/stddev): 1000.0000/2912.74
execution time (avg/stddev): 0.0142/0.04
- run
- –oltp-tables-count
- –oltp-read-only 仅执行SELECT测试 on | off,默认为off
- –oltp-dist-type 随机数分布状态。uniform(均匀分布)、gauss(高斯分布)、special(特殊分布)
- –oltp-dist-pct 特殊分布的百分比值
- –oltp-dist-res 特殊分布的百分比
- –oltp-point-selects 单个事务中指定的selec查询个数
- –oltp-range-size 范围查询的范围大小,该值应比oltp-table-size小
- –oltp-simple-ranges 单个事务中指定的简单范围查询个数
- –oltp-sum-ranges 单个事务中指定的SUM范围查询个数
- –oltp-order-ranges 单个事务中指定的ORDER范围查询个数
- –oltp-distinct-ranges 单个事务中指定的DISTINCT范围查询个数
- –oltp-index-updates 单个事务中指定的使用索引更新的个数
- –oltp-non-index-updates 单个事务中指定的不使用索引更新的个数
shell> sysbench --test=./tests/db/oltp.lua --num_threads=10 --oltp-table-size=100000
--mysql-db=test --mysql-user=root --oltp-tables-count=10 --mysql-password=oracle run
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads: 10
Random number generator seed is 0 and will be ignored Threads started! OLTP test statistics:
queries performed:
read: 140028 -- 读总数
write: 40008 -- 写总数
other: 20004 -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
total: 200040 -- 全部总数
transactions: 10002 (234.44 per sec.) -- 总事务数(每秒事务数)
deadlocks: 0 (0.00 per sec.) -- 发生死锁总数
read/write requests: 180036 (4219.99 per sec.) -- 读写总数(每秒读写次数)
other operations: 20004 (468.89 per sec.) -- 其他操作总数(每秒其他操作次数) Test execution summary:
total time: 42.6626s -- 总耗时
total number of events: 10002 -- 共发生多少事务数
total time taken by event execution: 426.3020s -- 所有事务耗时相加(不考虑并行因素)
per-request statistics:
min: 5.36ms -- 最小耗时
avg: 42.62ms -- 平均耗时
max: 183.44ms -- 最长耗时
approx. 95 percentile: 59.81ms -- 超过99%平均耗时 Threads fairness:
events (avg/stddev): 1000.2000/23.87
execution time (avg/stddev): 42.6302/0.01
- clearnup
shell> sysbench --test=./tests/db/oltp.lua --oltp-table-size=100000 --mysql-db=test --mysql-user=root
--oltp-tables-count=10 --mysql-password=oracle cleanup
sysbench 0.5: multi-threaded system evaluation benchmark Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
Dropping table 'sbtest6'...
Dropping table 'sbtest7'...
Dropping table 'sbtest8'...
Dropping table 'sbtest9'...
Dropping table 'sbtest10'...
注意:sysbench的测试只是基准测试,并不能代表实际企业环境下的性能指标。
sysbench 0.5 基准测试的更多相关文章
- sysbench 0.5使用手册
注意:本文刚开始只介绍了sysbench 0.5之前的版本,在了解了sysbench 0.5之后进行了补充,大部分测试和参数都是一样的,只是sysbench 0.5 在测试数据库方面更加全面丰富. 关 ...
- sysbench 0.5 oltp测试笔记
sysbench 0.5相比0.4版本的主要变化是,oltp测试结合了lua脚本,不需要修改源码,通过自定义lua脚本就可以实现不同业务类型的测试.同时0.5相比0.4需要消耗更多的cpu资源. 1. ...
- 使用sysbench 0.5 对mysql 进行性能、压力测试
sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.目前sysbench代码托管在launchpad上,项目地址:https://launc ...
- IBM Power PC安装sysbench 执行mysql基准测试 --- sysbench安装
第一步:下载Sysbench http://dev.mysql.com/downloads/benchmarks.html 第二步:解压sysbench 第三步:执行安装步骤 1. ./autogen ...
- sysbench 0.4.12安装
前提:mysql已安装完成,请参考http://www.cnblogs.com/lizhi221/p/6813907.html 安装依赖环境包: yum install -y bzr yum in ...
- MySQL基准测试工具--sysbench
我们需要知道的是sysbench并不是一个压力测试工具,是一个基准测试工具.linux自带的版本比较低,我们需要自己安装sysbench. [root@test2 ~]# sysbench --ver ...
- mysql基准测试与sysbench工具
一.基准测试简介 1.什么是基准测试 数据库的基准测试是对数据库的性能指标进行定量的.可复现的.可对比的测试. 基准测试与压力测试 基准测试可以理解为针对系统的一种压力测试.但基准测试不关心业务逻辑 ...
- sysbench基准测试工具
一.简介SysBench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.当前功能允许测试的系统参数有:file I/O performance (文件I ...
- MySQL基准测试和sysbench工具
参考https://www.cnblogs.com/kismetv/archive/2017/09/30/7615738.html 一.基准测试的作用 sysbench是一个开源的.模块化的.跨平台的 ...
随机推荐
- PHP:第四章——PHP数组array_intersect计算数组交集
<pre> <?php //array_intersect计算数组交集 header("Content-Type:text/html;charset=utf-8" ...
- node.js express 4.x 安装指南 (找了很久呀,痛苦之路)
问题出现这,版本的问题,还有express4.0以上的版本启动node app.js指令的变更,蛋疼.参考这个
- .net面试题精选
1.面向对象的三个特征?面向对象的五个基本设计原则? 2.接口与抽象类的区别? 3.谈谈设计模式? 4.线程与进程的区别?开发多线程程序应该考虑哪些问题? 5.简述 .NET中的Task? 6.简述. ...
- bzoj1625
题解: 简单dp 要一维 代码: #include<bits/stdc++.h> using namespace std; ; int n,m,a[N],b[N],f[N]; int ma ...
- 软工作业No.8 第六周 Alpha阶段项目复审
小组的名字和链接 优点 缺点,bug报告 (至少140字) 最终名次 (无并列) 未来的将来的明天在那里等你 http://www.cnblogs.com/macrae/p/9940387.html ...
- L1-051 打折
去商场淘打折商品时,计算打折以后的价钱是件颇费脑子的事情.例如原价 ¥988,标明打 7 折,则折扣价应该是 ¥988 x 70% = ¥691.60.本题就请你写个程序替客户计算折扣价. 输入格式: ...
- MyEclipse WebSphere开发教程:安装和更新WebSphere 6.1, JAX-WS, EJB 3.0(一)
你开学,我放价!MyEclipse线上狂欢继续!火热开启中>> [MyEclipse最新版下载] MyEclipse支持Java EE技术(如JAX-WS和EJB 3.0),它们以功能包的 ...
- foreach的使用原理简单解析
数组可以foreach遍历,这个是在jdk1.5之前就可以的,我也不太清楚是怎么做到的. 后面的List,Set等的foreach都是实现Iterable接口,基于iterator()对象实现的.Fo ...
- 对小波变换中DWT和CWT的理解
转载自 http://blog.sina.com.cn/s/blog_633750d90100hbco.html 连续小波变换的概念.操作.及时间尺度图的显示 最近很多网友问到关于连续小波变换的诸多问 ...
- CodeForces - 325E:The Red Button (哈密尔顿 转 欧拉回路)
Piegirl found the red button. You have one last chance to change the inevitable end. The circuit und ...