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

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

一、sysbench安装
课前准备,安装 sysbench
下载 sysbench

git clone https://github.com/akopytov/sysbench.git

安装依赖

yum install autoconf automake libtool -y

编译安装

cd sysbench/
./autogen.sh
./configure --without-mysql
make && make install

百度云链接
提取码:kone

下载压缩包放到服务器,然后解压即可

二、sysbench使用

  1. 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]
  1. 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性能测试:计算范围内素数相加时间越短越好
  1. 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
  1. 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越大越好

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值