sysbench基准测试

文件I/O(fileio)基准测试可以测试系统在不同I/O负载下的性能。这对于比较不同的硬盘驱动器、不同的RAID卡、不同的RAID模式,都很有帮助。可以根据测试结果来调整I/O子系统。文件I/O基准测试模拟了很多InnoDB的I/O特性。测试的第一步是准备(prepare)阶段,生成测试用到的数据文件,生成的数据文件至少要比内存大。如果文件中的数据能完全放入内存中,则操作系统缓存大部分的数据,导致测试结果无法体现I/O密集型的工作负载。

安装sysbench

下载解压

1
2
3
wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0.zip"
unzip sysbench-1.0.zip
cd sysbench-1.0

安装依赖

1
yum install automake libtool –y

安装

1
2
3
4
5
6
./autogen.sh
./configure
#这里换成机器中mysql路径下的include
export LD_LIBRARY_PATH=/usr/local/mysql/include
make
make install

有可能有的同学找不到include目录,不要慌,看看下面:

1
yum install mysql-devel

/usr/include/mysql就是include目录了。

内建测试: fileio测试

准备测试集

1
sysbench --test=fileio --file-total-size=150G prepare

--test=fileio表示测试类型为内建的fileio测试

--test-total-size=150G表示准备测试数据集为150G大小

prepare命令准备测试数据集

查看帮助文档

1
sysbench --test=fileio help

fileio options: //可用的选项

–file-num=N number of files to create [128] //文件数量

–file-block-size=N block size to use in all IO operations [16384] //文件块大小设定

–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,mmap} [sync] //io模式,“同步”、“异步”

–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()方法调用频率

–file-fsync-all=[on|off] do fsync() after each write operation [off] //每一次写操作都进行fsync()同步,默认为off

–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]

–file-merged-requests=N merge at most this number of IO requests if possible (0 - don’t merge) [0]

–file-rw-ratio=N reads/writes ratio for combined
test [1.5] //读写比率设定

有一个重要的测试选项:–file-test-mode=STRING。其可用的选项为:

seqwr:顺序写

seqrewr:顺序重写

seqrd:顺序读

rndrd:随机读取

rndwr:随机写入

rndrw:混合随机读/写

混合随机读写测试

1
sysbench --test=fileio --file-test-mode=rndrw --file-total-size=150G --file-rw-ratio=2 run

选项解释:

–test-fileio:测试类型为IO测试

–file-total-size=5G:测试文件总大小为5G

–file-test-mode=rndrw:文件IO测试模式为随机混合读写方式

–file-rw-ratio=2:读写次数比率为2

分析打印结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
sysbench 1.0:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1 //测试线程数
Initializing random number generator from current time

//测试属性设定,可以通过选项控制
Extra file open flags: 0
128 files, 40MiB each
5GiB total file size
Block size 16KiB
Number of IO requests: 10000
Read/Write ratio for combined random IO test: 2.00
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...

Threads started!

//测试过程中文件操作情况
File operations:
reads/s: 95.45 //每秒钟读请求数
writes/s: 47.72 //每秒钟写请求数
fsyncs/s: 183.25 //没表中同步次数

//吞吐率
Throughput:
read, MiB/s: 1.49 //读,1.49MB每秒
written, MiB/s: 0.75 //写,0.75MB每秒

//统计数据
General statistics:
total time: 69.8488s //测试总时长
total number of events: 10000   //事件数量
total time taken by event execution: 39.6674s  //事件执行事件
response time: //事件响应事件统计
min: 0.02ms //最短
avg: 3.97ms //平均
max: 27.70ms //最长
approx. 95 percentile: 11.77ms //95%以上事件响应时长

Threads fairness: //线程公平性统计信息
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 39.6674/0.00

与文件IO性能评价密切相关的指标有:每秒钟请求数、吞吐量、95%以上事件响应时间。

清除测试数据集

1
sysbench --test=fileio --file-total-size=150G cleanup
Fiveplus wechat
扫一扫上方二维码,关注微信公众号:阿五编程
如果这篇文章对你有所帮助,请点击下方的打赏按钮。