由于blog各种垃圾评论太多,而且本人审核评论周期较长,所以懒得管理评论了,就把评论功能关闭,有问题可以直接qq骚扰我

Sysbench 测试磁盘性能

运维工具 西门飞冰 14568℃

简介

硬盘作为电脑的一个主要部件,不仅肩负着记录一切数据信息的重要职责,而且它的性能对整个系统的性能有直接影响。由于磁存储介质的发展较一日千里的半导体技术落后,所以硬盘在整机系统中很多时候充当着一个 瓶颈 的角色。如果把一台整机比喻成一只水桶的话,硬盘就好比水桶中最低一侧的桶壁,水桶是否可以装更多的水就由这一侧桶壁的高度决定。由此,我们可见硬盘对整机系统性能的影响有多大。

既然明白了硬盘性能在整机系统中担当的重要角色,了解如何测试硬盘的性能相信是不少电脑用户所关心的问题。在测试硬盘之前,我们首先要了解一下影响硬盘性能的有关参数,只有这样我们才能在测试中做到有的放矢,更好地分析和利用测试结果,这也有助于我们提高在计算机上所允许的应用的性能。

磁盘性能测试所要关注的参数主要有以下几个:

  1. 数据吞吐量(Throughput),指单位时间内可以成功传输的数据数量。对于大量顺序读写的应用,如 VOD(Video On Demand),则更关注吞吐量指标。连续数据的传输速度又是实际应用中磁盘性能的主要体现,反映了硬盘的数据交换能力,所以硬盘的数据吞吐量是硬盘测试的一个重要数据
  2. IOPS 即每秒的输入输出量(或读写次数),是衡量磁盘性能的主要指标之一。IOPS 是指单位时间内系统能处理的 I/O 请求数量,一般以每秒处理的 I/O 请求数量为单位,I/O 请求通常为读或写数据操作请求。随机读写频繁的应用,如 OLTP(OnlineTransaction Processing),IOPS 是关键衡量指标。
  3. 硬盘还有一个指标就是响应延时。响应延时实际上是由转速、缓存、单碟容量等等性能综合决定的一个参数,体现在用户的角度,就是一个总体的性能指标。目前主流硬盘的响应延时差别都不大,一般在9ms左右。

Sysbench介绍

sysbench:是一款开源的多线程性能测试工具,可以执行 CPU/内存/线程/IO/数据库等方面的性能测试。本文将指导各位如何安装和配置性能测试工具sysbench来进行磁盘性能测试。

Sysbench安装

编译安装

1、 从git下载软件到本地

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

2、编译安装sysbench

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

注意:若不添加额外参数 –without-mysql ,则会提示需要安装 mysql 相关库。

Yum安装

yum -y install sysbench

使用sysbench对磁盘进行性能测试

1、 准备IO测试文件:执行如下命令,生成16个文件,用于本次测试。

sysbench --test=fileio --file-num=16 --file-total-size=2G prepare

参数含义:
–test=fileio  测试的名称叫做 fileio
–file-num=16 文件的数量是 16 个
–file-total-size=2G 文件的总体大小是 2GB
说明:每个测试文件的大小是 130MB,总计花费 32 秒。
查看测试文件:

$ ll
总用量 2097156
drwxr-xr-x 13 root root      4096 8月  24 15:50 sysbench
-rw-------  1 root root 134217728 8月  24 15:57 test_file.0
-rw-------  1 root root 134217728 8月  24 15:57 test_file.1
-rw-------  1 root root 134217728 8月  24 15:58 test_file.10
-rw-------  1 root root 134217728 8月  24 15:58 test_file.11
-rw-------  1 root root 134217728 8月  24 15:58 test_file.12
-rw-------  1 root root 134217728 8月  24 15:58 test_file.13
-rw-------  1 root root 134217728 8月  24 15:58 test_file.14
-rw-------  1 root root 134217728 8月  24 15:58 test_file.15
-rw-------  1 root root 134217728 8月  24 15:57 test_file.2
-rw-------  1 root root 134217728 8月  24 15:57 test_file.3
-rw-------  1 root root 134217728 8月  24 15:57 test_file.4
-rw-------  1 root root 134217728 8月  24 15:57 test_file.5
-rw-------  1 root root 134217728 8月  24 15:57 test_file.6
-rw-------  1 root root 134217728 8月  24 15:58 test_file.7
-rw-------  1 root root 134217728 8月  24 15:58 test_file.8
-rw-------  1 root root 134217728 8月  24 15:58 test_file.9

2、测试多线程下小IO的随机只读性能

$ sysbench --test=fileio --file-num=16 --file-total-size=2G --file-test-mode=rndrd  --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.6 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time


Extra file open flags: 3
16 files, 128MiB each
2GiB total file size
Block size 16KiB
Number of IO requests: 0
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
Initializing worker threads...

Threads started!


File operations:
    reads/s:                      1487.34
    writes/s:                     0.00
    fsyncs/s:                     0.00

Throughput:
    read, MiB/s:                  23.24
    written, MiB/s:               0.00

General statistics:
    total time:                          10.0002s
    total number of events:              14877

Latency (ms):
         min:                                  0.15
         avg:                                  0.67
         max:                                168.34
         95th percentile:                      0.84
         sum:                               9978.66

Threads fairness:
    events (avg/stddev):           14877.0000/0.00
    execution time (avg/stddev):   9.9787/0.00

参数含义:
–test=fileio 测试的名称叫做 fileio
–file-num=16  文件的数量是 16 个
–file-total-size=2G  文件的总体大小是 2GB
–file-test-mode=rndrd  测试模式是随机读取
–file-extra-flags=direct  使用额外的标志来打开文件{sync,dsync,direct}
–file-fsync-freq=0  执行 fsync() 的频率
–file-block-size=16384 测试时文件块的大小位 16384 (16K)

测试结果:
随机读取的数据吞吐量:23.24 MB/s
随机读的IOPS: 1487.34
平均延迟:0.67毫秒

3、测试多线程下小IO的随机写入性能

$ sysbench --test=fileio --file-num=16 --file-total-size=2G --file-test-mode=rndwr --max-time=180  --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.6 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time


Extra file open flags: 3
16 files, 128MiB each
2GiB total file size
Block size 16KiB
Number of IO requests: 0
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 write test
Initializing worker threads...

Threads started!


File operations:
    reads/s:                      0.00
    writes/s:                     1536.37
    fsyncs/s:                     0.00

Throughput:
    read, MiB/s:                  0.00
    written, MiB/s:               24.01

General statistics:
    total time:                          180.0041s
    total number of events:              276556

Latency (ms):
         min:                                  0.22
         avg:                                  0.65
         max:                                279.43
         95th percentile:                      1.01
         sum:                             179649.14

Threads fairness:
    events (avg/stddev):           276556.0000/0.00
    execution time (avg/stddev):   179.6491/0.00

参数含义:
–file-test-mode=rndwr  测试模式是随机写

测试结果:
随机写入的数据吞吐量:24.01 MB/s
随机写的IOPS: 1536.37
平均延迟:0.65毫秒

4、测试多线程下小IO的随机读写性能

$ sysbench --test=fileio --file-num=16 --file-total-size=2G --file-test-mode=rndrw --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.6 (using system LuaJIT 2.0.4)

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time


Extra file open flags: 3
16 files, 128MiB each
2GiB total file size
Block size 16KiB
Number of IO requests: 0
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 r/w test
Initializing worker threads...

Threads started!


File operations:
    reads/s:                      1516.94
    writes/s:                     1011.33
    fsyncs/s:                     0.00

Throughput:
    read, MiB/s:                  23.70
    written, MiB/s:               15.80

General statistics:
    total time:                          10.0073s
    total number of events:              25307

Latency (ms):
         min:                                  0.12
         avg:                                  0.39
         max:                                 66.01
         95th percentile:                      0.77
         sum:                               9981.29

Threads fairness:
    events (avg/stddev):           25307.0000/0.00
    execution time (avg/stddev):   9.9813/0.00

参数含义:
–file-test-mode=rndrw    测试模式是随机读写
随机读取的数据吞吐量:23.70 MB/s
随机写入的数据吞吐量:15.80 MB/s
随机读IOPS:1516.94
随机写IOPS:1011.33
平均延迟:0.39毫秒

至此,完成本次对磁盘的全部性能测试。

附录:

Sysbench 的文件测试模式,seqwr 顺序写,seqrew r顺序读写,seqrd 顺序读,rndrd 随机读,rndwr 随机写,rndrw 随机读写。

–file-rw-ratio=4 读写比例调整,为4表示读写比例4:1

 

 

 

转载请注明:西门飞冰的博客 » Sysbench 测试磁盘性能

喜欢 (1)or分享 (0)