sysbench基础测试工具安装、测试、结果分析

sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。
它主要包括以下几种方式的测试:
1、cpu性能
2、磁盘io性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、数据库性能(OLTP基准测试)
目前sysbench主要支持 MySQL,pgsql,oracle 这3种数据库。

一、sysbench安装

首先,在 http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgz
下载源码包。下载解压后进入安装。

[root@localhost src]# tar zxvf sysbench-0.4.12-1.1.tgz
[root@localhost src]# cd sysbench-0.4.12-1.1
[root@localhost sysbench-0.4.12-1.1]# ls
autogen.sh configure.ac install-sh missing README-WIN.txt
ChangeLog COPYING m4 mkinstalldirs sysbench
config doc Makefile.am README TODO
解压后发现,并没有配置文件configure

这里需要直接运行sysbench提供的脚本autogen.sh,运行脚本autogen.sh之前,需要通过yum安装环境

[root@localhost sysbench-0.4.12-1.1]# yum install m4 autoconf automake libtool
[root@localhost sysbench-0.4.12-1.1]# ./autogen.sh
生成文件配置文件之后,进入配置阶段,如果你的mysql是标准安装的话,可以直接运行,进行安装。

[root@localhost sysbench-0.4.12-1.1]# ./configure
[root@localhost sysbench-0.4.12-1.1]# make && make install
如果不是mysql不是标准安装的话,需要在配置文件中指定

./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib --with-mysql
其中参数:–with-mysql-includes的地址是mysql.h所在的目录,可以通过find / -name mysql.h进行查找

–with-mysql-libs的地址是libmysqlclient.so所在的目录,可以通过find / -name libmysqlclient.so进行查找

配置完成之后就可以直接make && make install。

安装过程中,错误总结:

错误提示1:

[root@localhost sysbench-0.4.12-1.1]# ./autogen.sh
automake 1.10.x (aclocal) wasn't found, exiting
通过yum安装automake

[root@localhost sysbench-0.4.12-1.1]# yum -y install automake
错误提示2:

[root@localhost sysbench-0.4.12-1.1]# ./autogen.sh
libtoolize 1.4+ wasn't found, exiting
通过yun安装libtool即可

[root@localhost sysbench-0.4.12-1.1]# yum -y install libtool
在运行sysbench的时候,遇到:error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

这说明sysbench无法找到mysql的库文件,这很可能是环境变量LD_LIBRARY_PATH没有设置,设置后即可解决该问题:
执行bash代码:export LD_LIBRARY_PATH=/usr/local/mysql/lib 可以临时的修改环境变量,终端断开之后,就会丢失 也可以在/etc/profile中添加export LD_LIBRARY_PATH=/usr/local/mysql/lib,永久的修改,这样修改需要重启机器就会永久生效。

安装完成之后,开始做基准测试。

二、sysbench使用

sysbench常用参数详解:

[root@localhost src]# sysbench
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]#最大执行时间,默认是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]#每个线程的堆栈大小,默认是64K
--tx-rate=N target transaction rate (tps) [0]#尝试像数据库发送的事务数tps
--report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]#表示N秒输出一次测试进度报告,0表示关闭测试进度报告输出,仅输出最终的报告结果,默认值为0。
--report-checkpoints=[LIST,...]dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
--test=STRING test to run #测试的项目
--debug=[on|off] print more debugging info [off]#debug模式输出,默认值为off。
--validate=[on|off] perform validation checks where possible [off]#在可能的情况下执行验证检查,默认为off。
--help=[on|off] print help and exit#输出help信息,默认为off。
--version=[on|off] print version and exit [off]#输出版本信息,默认为off。
--rand-init=[on|off] initialize random number generator [off]#初始化迭代器
--rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]

表示随机类型的模式,共有4种模式:uniform(固定),gaussian(高斯)�,special(特定),pareto(帕雷特),默认值为: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]
--rand-pareto-h=N parameter h for pareto distibution [0.2]
sysbench基准测试cpu,先查看帮助文档

[root@localhost db]# sysbench --test=cpu help
sysbench 0.5: multi-threaded system evaluation benchmark

cpu options:
--cpu-max-prime=N upper limit for primes generator [10000]#素数生成上限,默认是10000
sysbench对CPU的性能测试就是通过素数相加的测试。

[root@localhost db]# sysbench --num-threads=10 --max-requests=1000 --test=cpu --cpu-max-prime=20000 run #10个线程,执行1000个请求,每个请求加到20000
执行结果:

[root@localhost db]# sysbench --num-threads=10 --max-requests=1000 --test=cpu --cpu-max-prime=20000 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
Primer numbers limit: 20000 #素数生成上限
Threads started!

General statistics:
total time: 3.9331s #总耗时
total number of events: 1000 #事务总数
total time taken by event execution: 39.1176s #事件执行所花费的总时间
response time: #响应时间
min: 16.69ms #最小
avg: 39.12ms #平均
max: 76.07ms #最大
approx. 95 percentile: 51.44ms #95%以上的响应时间

Threads fairness:
events (avg/stddev): 100.0000/0.00
execution time (avg/stddev): 3.9118/0.01
cpu性能测试:计算范围内素数相加时间越短越好

sysbench基准测试文件io,先查看帮助文档

[root@localhost src]# sysbench --test=fileio help #查看帮助
sysbench 0.5: multi-threaded system evaluation benchmark #多线程系统评测基准
fileio options:
--file-num=N number of files to create [128] #创建的文件数目,默认是128
--file-block-size=N block size to use in all IO operations [16384]#测试文件块的大小,默认是16384bite
--file-total-size=SIZE total size of files to create [2G]#创建的文件的总大小,默认是2G
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}#读写模式
seqwr, 顺序写 seqrewr, 顺序读写 seqrd, 顺序读 rndrd, 随机读 rndwr, 随机写 rndrw,随机读写
--file-io-mode=STRING file operations mode {sync,async,mmap} [sync]# 文件操作模式,同步,异步
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []#使用额外的标志来打开文件,默认为空
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]#执行fsync的频率,0表示不使用fsync,默认是100
fsync:同步内存中的数据到硬盘
--file-fsync-all=[on|off] do fsync() after each write operation [off]#每执行完一个操作就执行一次fsync,默认关闭
--file-fsync-end=[on|off] do fsync() at the end of test [on]#在测试结束的时候才执行 fsync
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]#使用哪种方法来同步,fsync或者fdatasync
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]#如果可以合并最多的io请求数,0不合并,默认是0
--file-rw-ratio=N reads/writes ratio for combined test [1.5]#测试时候的读写比例默认是1.5
文件io的测试步骤是:准备测试文件,运行测试文件,删除测试文件

通过sysbench生成测试文件prepare:

[root@localhost sysbench_test]# sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=10G --file-test-mode=rndrw prepare
运行run

[root@localhost sysbench_test]# sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=10G --file-test-mode=rndrw run
删除测试文件

[root@localhost sysbench_test]# sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=10G --file-test-mode=rndrw cleanup
结果分析

[root@localhost sysbench_test]# sysbench --num-threads=12 --max-requests=10000 --test=fileio --file-total-size=10G --file-test-mode=rndrw run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 12 #线程数
Random number generator seed is 0 and will be ignored
Extra file open flags: 0
128 files, 80Mb each
10Gb total file size #文件的总大小
Block size 16Kb
Number of IO requests: 10000
Read/Write ratio for combined random IO test: 1.50 #io读写比例
Periodic FSYNC enabled, calling fsync() each 100 requests. #每100个请求执行fsync()
Calling fsync() at the end of test, Enabled. #测试完成的时候执行一次fsync()
Using synchronous I/O mode
Doing random r/w test

Threads started!

Operations performed:
5999 reads,
4001 writes, 12800 Other = 22800 Total
Read 93.734Mb
Written 62.516Mb

Total transferred
156.25Mb (288.61Mb/sec)#吞吐量
18471.19 Requests/sec executed#每秒请求数

General statistics:
total time: 0.5414s#时间
total number of events: 10000#时间数量
total time taken by event execution: 3.9134s#执行时间的时间
response time:
min: 0.00ms#最短
avg: 0.39ms#平均
max: 29.75ms#最长
approx. 95 percentile: 1.68ms #95%以上事件响应事件
Threads fairness:
events (avg/stddev): 833.3333/70.29
execution time (avg/stddev): 0.3261/0.03
io性能指标有:每秒钟请求数、吞吐量、95%以上事件响应时间。不同场景下io tps越大越好

sysbench基准测试oltp,0.5版本之后oltp的参数没找到,在网上找了一份参数详解过来

--oltp-test-mode=STRING 测试类型:simple(简单select测试),complex(事务测试),nontrx(非事务测试),sp(存储过程) ;默认complex
--oltp-reconnect-mode=STRING 连接类型:session(每个线程到测试结束不重新连接),transaction(执行每个事务重新连接),query(每一个查询重新连接),random(随机);默认 [session]
--oltp-sp-name=STRING 指定执行测试的存储过程名
--oltp-read-only=[on|off] 仅执行select测试,默认关闭
--oltp-avoid-deadlocks=[on|off] 更新过程中忽略死锁,默认[off]
--oltp-skip-trx=[on|off] 语句以bigin/commit开始结尾,默认[off]
--oltp-range-size=N 范围查询的范围大小,默认 [100],例如begin 100 and 200
--oltp-point-selects=N 单个事务中select查询的数量,默认 [10]
--oltp-use-in-statement=N 每个查询中主键查找(in 10个值)的数量,默认 [0]
--oltp-simple-ranges=N 单个事务中执行范围查询的数量(SELECT c FROM sbtest WHERE id BETWEEN N AND M),默认[1]
--oltp-sum-ranges=N 单个事务中执行范围sum查询的数量,默认 [1]
--oltp-order-ranges=N 单个事务中执行范围order by查询的数量,默认[1]
--oltp-distinct-ranges=N 单个事务中执行范围distinct查询的数量,默认[1]
--oltp-index-updates=N 单个事务中执行索引更新的操作的数量,默认[1]
--oltp-non-index-updates=N 单个事务中执行非索引更新操作的数量,默认[1]
--oltp-nontrx-mode=STRING 指定单独非事务测试类型进行测试,默认select {select, update_key, update_nokey, insert, delete} [select]
--oltp-auto-inc=[on|off] id列默认自增,默认[on]
--oltp-connect-delay=N 指定每一次重新连接延时的时长,默认1秒 [10000]
--oltp-user-delay-min=N minimum time in microseconds to sleep after each request [0]
--oltp-user-delay-max=N maximum time in microseconds to sleep after each request [0]
--oltp-table-name=STRING 指定测试的表名,默认[sbtest]
--oltp-table-size=N 指定表的记录大小,默认[10000]
--oltp-dist-type=STRING 随机数分布状态。uniform(均匀分布)、gauss(高斯分布)、special(特殊分布),默认 [special]
--oltp-dist-iter=N number of iterations used for numbers generation [12]
--oltp-dist-pct=N 启用百分比特殊分布,默认 [1]
--oltp-dist-res=N special 百分比[75]
--oltp-point-select-mysql-handler=[on|off] Use MySQL HANDLER for point select [off]
--oltp-point-select-all-cols=[on|off] select查询测试时select所有列,默认[off]
--oltp-secondary=[on|off] 索引不是主键索引而是二级索引,默认[off]
--oltp-num-partitions=N 指定表分区的数量,默认 [0]
--oltp-num-tables=N 指定测试表的数量,默认[1]
General database options:
--db-driver=STRING 指定测试数据库类型,默认mysql
--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]

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 []
在0.5版本的mysql测试的时候,用到oltp.lua脚本,在解压的安装包中可以找到

[root@localhost db]# pwd
/usr/local/src/sysbench-0.4.12-1.1/sysbench/tests/db
[root@localhost db]# ls
common.lua insert.lua Makefile.am oltp.lua parallel_prepare.lua select_random_points.lua update_index.lua
delete.lua Makefile Makefile.in oltp_simple.lua select.lua select_random_ranges.lua update_non_index.lua
操作步骤:准备数据,运行测试,删除数据

[root@localhost db]# sysbench --test=./oltp.lua --oltp-table-size=2000000 --mysql-host=localhost --mysql-user=root --mysql-password=111111 prepare
[root@localhost db]# sysbench --test=./oltp.lua --oltp-table-size=2000000 --mysql-host=localhost --mysql-user=root --mysql-password=111111 run
[root@localhost db]# sysbench --test=./oltp.lua --oltp-table-size=2000000 --mysql-host=localhost --mysql-user=root --mysql-password=111111 cleanup
结果分析:

Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored

Threads started!

OLTP test statistics:
queries performed:
read: 140000 #读总数
write: 40000 #写总数
other: 20000 #其他总数(除select insert delete update之外的,比如commit)
total: 200000 #全部总数
transactions: 10000 (137.75 per sec.) #总事务数(每秒事务数)
deadlocks: 0 (0.00 per sec.)#发生死锁总数
read/write requests: 180000 (2479.53 per sec.)#读写总数(每秒读此书)
other operations: 20000 (275.50 per sec.)#其他操作次数(每秒其他操作次数)

General statistics:
total time: 72.5943s #总耗时间
total number of events: 10000 #总事务数
total time taken by event execution: 72.5352s #所有事务耗时相加(不考虑并行因素)
response time:#响应时间
min: 3.16ms #最短
avg: 7.25ms#平均
max: 1103.70ms#最长
approx. 95 percentile: 13.28ms#95%的响应时间

Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 72.5352/0.00
oltp测试结果需要参考的数据有:
response time avg: 平均响应时间。(后面的95%的大小可以通过–percentile=98的方式去更改)
transactions: 精确的说是这一项后面的TPS 。但如果使用了-oltp-skip-trx=on,这项事务数恒为0,需要用total number of events 去除以总时间,得到tps(其实还可以分为读tps和写tps)
read/write requests: 用它除以总时间,得到吞吐量QPS

sysbench基本测试内存

内存分配测试,主要是针对不同的块大小进行内存的连续读写或者随机读写测试

内存测试参数详解:

[root@localhost db]# sysbench --test=memory help
sysbench 0.5: multi-threaded system evaluation benchmark

memory options:
--memory-block-size=SIZE size of memory block for test [1K]#内存块大小,默认是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] #测试模式,随机读还是顺序
运行脚本

sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=seq run #顺序读 8k
sysbench --num-threads=12 --max-requests=10000 --test=memory --memory-block-size=8K --memory-total-size=100G --memory-access-mode=rnd run #随机读 8k
内存:以不同块大小传输一定数量的数据吞吐量大小越大越好

三、衡量结果标准:
cpu性能测试:找范围内最大素数时间越短越好
线程调度:线程并发执行,循环响应信号量花费的时间越少越好
互斥锁:并发线程同时申请互斥锁循环一定次数花费的时间越少越好
内存:以不同块大小传输一定数量的数据吞吐量大小越大越好
IO:不同场景下IO TPS越大越好
文章首发网址:http://www.17codes.com/archives/58?from=jianshu

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 156,907评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,546评论 1 289
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,705评论 0 238
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,624评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,940评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,371评论 1 210
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,672评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,396评论 0 195
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,069评论 1 238
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,350评论 2 242
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,876评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,243评论 2 251
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,847评论 3 231
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,004评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,755评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,378评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,266评论 2 259

推荐阅读更多精彩内容

  • 一、Sysbench介绍 SysBench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统...
    张伟科阅读 9,042评论 0 5
  • MySQL基准测试 原因 测试评估出当前系统的运行情况,建立性能基准线; 模拟更高负载,找出扩展性瓶颈; 规划未来...
    一剑光寒十九洲阅读 1,002评论 0 0
  • IP架构 sysbench部署服务器:172.17.100.107 压测服务器:172.17.100.100 My...
    飞翔的Tallgeese阅读 9,135评论 0 3
  • 前言 作为一名后台开发,对数据库进行基准测试,以掌握数据库的性能情况是非常必要的。本文介绍了MySQL基准测试的基...
    hekang01阅读 975评论 0 1
  • 基准测试不是压力测试,是每带有业务逻辑的测试。就是直击通过各种语句,压测服务器。 sysbench下载地址 htt...
    君子愁阅读 691评论 0 0