fio 磁盘性能测试工具

1、fio 简单介绍
fio 磁盘性能测试工具,磁盘IO是检查磁盘性能的重要指标,可以按照负载情况分成顺序读写、随机读写两大类

fio最初是用来节省为特定负载写专门测试程序,或是进行性能测试,或是找到和重现bug的时间。写这么一个测试应用是非常浪费时间的。因此需要一个工具来模拟给定的io负载,而不用重复的写一个又一个的特定的测试程序。但是test负载很难定义。因为可能会产生很多进程或线程,他们每一个都用他们自己的方式产生io。fio需要足够灵活得来模拟这些case

2、磁盘读写原理与顺序/随机读写说明以及区别
许多小伙伴不太明白顺序读写和随机读写的意思和区别(比如我,查阅了不少资料做了以下简单的描述)

(1)磁盘读写原理
信息存储在硬盘里,打开也看不见里面有任何东西只有些盘片。如果把盘片放大,会看见盘片表面凹凸不平,凸起的地方被磁化,凹的地方是没有被磁化;凸起的地方代表数字1(磁化为1),凹的地方代表数字0。因此硬盘可以以二进制来存储表示文字、图片等信息。

(2)顺序读写和随机读写
顺序读写:指的是本次 I/O 给出的初始扇区地址和上一次 I/O 的结束扇区地址是完全连续或者相隔不多的。反之,如果相差很大,则算作一次随机 I/O。
随机读写:随机I/O可能是因为磁盘碎片导致磁盘空间不连续,或者当前block空间小于文件大小导致的。

SSD固态盘主要看的就是随机读写性能-(由控制单元和固态存储单元(DRAM或FLASH芯片)组成,存储单元负责存储数据,控制单元负责读取、写入数据。由于固态硬盘没有普通硬盘的机械结构,也不存在机械硬盘的寻道问题)
SAS机械硬盘主要看的是顺序读写性能-(数据是存储的扇区的,读写是依靠磁头的摆动寻址的。顺序读写主要时间花费在了传输时间,随机读写需要多次寻道和旋转延迟。)

(3)顺序读写与随机读写区别
顺序读写:文件指针只能从头移动到尾。
随机读写:文件指针可以随意移动,根据需要。

连续读写比随机读写效率高
因为在做连续读写的时候,磁头几乎不用换道或者换道的时间很短;
而对于随机读写,如果这个读写很多的话,会导致磁头不停地换道,造成效率的降低。

3、参数说明(更多参数详见“fio --help”)

-filename=/dev/sdb1       测试文件名称,通常选择需要测试的盘的data目录。 只能是分区,不能是目录,会破坏数据
-direct=1                 测试过程绕过机器自带的buffer。使测试结果更真实。
-rw=randrw                测试随机写和读的I/O
-rw=rw/readwrite          测试顺序读写的I/O
-rw=read                  顺序读
-rw=write                 顺序写
-rw=randread              随机读
-rw=randwrite             随机写
-iodepth=1                队列深度,只有使用libaio时才有意义,这是一个可以影响IOPS的参数,通常情况下为1。
-ioengine=psync/libaio    io引擎使用pync方式
-bs=4k                    单次io的块文件大小为4k (单次IO越小的时候,单次IO所耗费的时间也越少,相应的IOPS也就越大)
-size=2G                  测试文件大小为2g,以每次4k的io进行测试,此大小不能超过filename的大小,否则会报错。
-numjobs=10               测试线程为10.
-runtime=10               测试时间为10秒,如果不写则一直将2g文件分4k每次写完为止。
-lockmem=1g               只使用1g内存进行测试。
-rwmixwrite=30            在混合读写的模式下,写占30% 
-group_reporting          关于显示结果的,汇总每个进程的信息。
-name=name                直接测试读会在测试设备写入name.*文件
-output=rw.txt            将输出内容写入文件

4、测试范例 (视情况自行选择参数并更改)
(1)顺序读

[root@centos7 test]# fio -fimename=/dev/sdc1 -direct=1 -rw=read -iodepth=1 -ioengine=psync -bs=4k -size=2G -numjobs=1 -runtime=10 -group_reporting -name=name
name: (g=0): rw=read, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
fio-2.1.10
Starting 1 process
name: Laying out IO file(s) (1 file(s) / 2048MB)
Jobs: 1 (f=1): [R] [100.0% done] [53528KB/0KB/0KB /s] [13.4K/0/0 iops] [eta 00m:00s]
name: (groupid=0, jobs=1): err= 0: pid=15754: Sun May  9 00:04:40 2021
  read : io=608940KB, bw=60888KB/s, iops=15221, runt= 10001msec
    clat (usec): min=42, max=634, avg=64.26, stdev=13.58
     lat (usec): min=42, max=635, avg=64.40, stdev=13.58
    clat percentiles (usec):
     |  1.00th=[   47],  5.00th=[   50], 10.00th=[   51], 20.00th=[   52],
     | 30.00th=[   53], 40.00th=[   56], 50.00th=[   66], 60.00th=[   69],
     | 70.00th=[   72], 80.00th=[   74], 90.00th=[   77], 95.00th=[   81],
     | 99.00th=[  107], 99.50th=[  124], 99.90th=[  171], 99.95th=[  195],
     | 99.99th=[  266]
    bw (KB  /s): min=51072, max=74128, per=100.00%, avg=61282.95, stdev=8940.17
    lat (usec) : 50=3.15%, 100=95.56%, 250=1.28%, 500=0.01%, 750=0.01%
  cpu          : usr=0.07%, sys=75.35%, ctx=140335, majf=0, minf=28
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=152235/w=0/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=608940KB, aggrb=60887KB/s, minb=60887KB/s, maxb=60887KB/s, mint=10001msec, maxt=10001msec

Disk stats (read/write):
  sdc: ios=149199/2, merge=0/1, ticks=7981/0, in_queue=7978, util=80.90%

(2)顺序写

[root@centos7 test]# fio -fimename=/dev/sdc1 -direct=1 -rw=write -iodepth=1 -ioengine=psync -bs=4k -size=2G -numjobs=1 -runtime=10 -group_reporting -name=name
name: (g=0): rw=write, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
fio-2.1.10
Starting 1 process
Jobs: 1 (f=1): [W] [100.0% done] [0KB/48488KB/0KB /s] [0/12.2K/0 iops] [eta 00m:00s]
name: (groupid=0, jobs=1): err= 0: pid=15893: Sun May  9 00:07:27 2021
  write: io=527800KB, bw=52775KB/s, iops=13193, runt= 10001msec
    clat (usec): min=53, max=751, avg=74.34, stdev=16.13
     lat (usec): min=53, max=751, avg=74.52, stdev=16.14
    clat percentiles (usec):
     |  1.00th=[   57],  5.00th=[   58], 10.00th=[   59], 20.00th=[   60],
     | 30.00th=[   62], 40.00th=[   64], 50.00th=[   74], 60.00th=[   80],
     | 70.00th=[   83], 80.00th=[   87], 90.00th=[   90], 95.00th=[   94],
     | 99.00th=[  123], 99.50th=[  141], 99.90th=[  187], 99.95th=[  213],
     | 99.99th=[  422]
    bw (KB  /s): min=42824, max=62568, per=100.00%, avg=52800.00, stdev=6626.28
    lat (usec) : 100=97.08%, 250=2.89%, 500=0.02%, 750=0.01%, 1000=0.01%
  cpu          : usr=0.05%, sys=85.36%, ctx=80042, majf=0, minf=29
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=0/w=131950/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
  WRITE: io=527800KB, aggrb=52774KB/s, minb=52774KB/s, maxb=52774KB/s, mint=10001msec, maxt=10001msec

Disk stats (read/write):
  sdc: ios=0/130571, merge=0/1, ticks=0/8390, in_queue=8388, util=83.89%

(3)随机读

[root@centos7 test]# fio -fimename=/dev/sdc1 -direct=1 -rw=randread -iodepth=1 -ioengine=psync -bs=4k -size=2G -numjobs=1 -runtime=10 -group_reporting -name=name 
name: (g=0): rw=randread, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
fio-2.1.10
Starting 1 process
Jobs: 1 (f=1): [r] [100.0% done] [53036KB/0KB/0KB /s] [13.3K/0/0 iops] [eta 00m:00s]
name: (groupid=0, jobs=1): err= 0: pid=15974: Sun May  9 00:09:00 2021
  read : io=550584KB, bw=55053KB/s, iops=13763, runt= 10001msec
    clat (usec): min=45, max=2140, avg=71.00, stdev=17.94
     lat (usec): min=45, max=2141, avg=71.13, stdev=17.95
    clat percentiles (usec):
     |  1.00th=[   48],  5.00th=[   51], 10.00th=[   52], 20.00th=[   56],
     | 30.00th=[   67], 40.00th=[   70], 50.00th=[   73], 60.00th=[   74],
     | 70.00th=[   77], 80.00th=[   79], 90.00th=[   83], 95.00th=[   89],
     | 99.00th=[  110], 99.50th=[  131], 99.90th=[  181], 99.95th=[  213],
     | 99.99th=[  812]
    bw (KB  /s): min=46928, max=69160, per=99.99%, avg=55045.47, stdev=6973.14
    lat (usec) : 50=2.19%, 100=96.14%, 250=1.64%, 500=0.02%, 750=0.01%
    lat (usec) : 1000=0.01%
    lat (msec) : 2=0.01%, 4=0.01%
  cpu          : usr=0.09%, sys=78.34%, ctx=121541, majf=0, minf=28
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=137646/w=0/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=550584KB, aggrb=55052KB/s, minb=55052KB/s, maxb=55052KB/s, mint=10001msec, maxt=10001msec

Disk stats (read/write):
  sdc: ios=136380/2, merge=0/1, ticks=7707/0, in_queue=7708, util=77.09%

(4)随机写

[root@centos7 test]# fio -fimename=/dev/sdc1 -direct=1 -rw=randwrite -iodepth=1 -ioengine=psync -bs=4k -size=2G -numjobs=1 -runtime=10 -group_reporting -name=name
name: (g=0): rw=randwrite, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
fio-2.1.10
Starting 1 process
Jobs: 1 (f=1): [w] [100.0% done] [0KB/56419KB/0KB /s] [0/14.2K/0 iops] [eta 00m:00s]
name: (groupid=0, jobs=1): err= 0: pid=16046: Sun May  9 00:10:27 2021
  write: io=568740KB, bw=56868KB/s, iops=14217, runt= 10001msec
    clat (usec): min=54, max=896, avg=68.65, stdev=13.78
     lat (usec): min=54, max=897, avg=68.85, stdev=13.78
    clat percentiles (usec):
     |  1.00th=[   59],  5.00th=[   60], 10.00th=[   61], 20.00th=[   62],
     | 30.00th=[   63], 40.00th=[   64], 50.00th=[   65], 60.00th=[   67],
     | 70.00th=[   69], 80.00th=[   73], 90.00th=[   78], 95.00th=[   85],
     | 99.00th=[  113], 99.50th=[  129], 99.90th=[  223], 99.95th=[  290],
     | 99.99th=[  450]
    bw (KB  /s): min=54344, max=59800, per=100.00%, avg=56980.63, stdev=1192.52
    lat (usec) : 100=97.66%, 250=2.27%, 500=0.06%, 750=0.01%, 1000=0.01%
  cpu          : usr=0.08%, sys=91.91%, ctx=41937, majf=0, minf=27
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=0/w=142185/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
  WRITE: io=568740KB, aggrb=56868KB/s, minb=56868KB/s, maxb=56868KB/s, mint=10001msec, maxt=10001msec

Disk stats (read/write):
  sdc: ios=0/141304, merge=0/1, ticks=0/9746, in_queue=9744, util=97.26%

(5)混合顺序读写

[root@centos7 test]# fio -fimename=/dev/sdc1 -direct=1 -rw=rw -iodepth=1 -ioengine=psync -bs=4k -size=2G -numjobs=1 -runtime=10 -group_reporting -name=name
name: (g=0): rw=rw, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
fio-2.1.10
Starting 1 process
Jobs: 1 (f=1): [M] [100.0% done] [23032KB/23336KB/0KB /s] [5758/5834/0 iops] [eta 00m:00s]
name: (groupid=0, jobs=1): err= 0: pid=16102: Sun May  9 00:11:33 2021
  read : io=300452KB, bw=30042KB/s, iops=7510, runt= 10001msec
    clat (usec): min=41, max=741, avg=60.08, stdev=15.11
     lat (usec): min=41, max=744, avg=60.22, stdev=15.11
    clat percentiles (usec):
     |  1.00th=[   46],  5.00th=[   49], 10.00th=[   50], 20.00th=[   51],
     | 30.00th=[   51], 40.00th=[   52], 50.00th=[   53], 60.00th=[   55],
     | 70.00th=[   64], 80.00th=[   73], 90.00th=[   77], 95.00th=[   81],
     | 99.00th=[  102], 99.50th=[  122], 99.90th=[  177], 99.95th=[  211],
     | 99.99th=[  442]
    bw (KB  /s): min=22960, max=34376, per=100.00%, avg=30410.95, stdev=4527.95
  write: io=300316KB, bw=30029KB/s, iops=7507, runt= 10001msec
    clat (usec): min=53, max=994, avg=70.09, stdev=16.20
     lat (usec): min=53, max=994, avg=70.29, stdev=16.21
    clat percentiles (usec):
     |  1.00th=[   57],  5.00th=[   58], 10.00th=[   59], 20.00th=[   59],
     | 30.00th=[   60], 40.00th=[   61], 50.00th=[   63], 60.00th=[   66],
     | 70.00th=[   76], 80.00th=[   85], 90.00th=[   89], 95.00th=[   93],
     | 99.00th=[  113], 99.50th=[  135], 99.90th=[  185], 99.95th=[  223],
     | 99.99th=[  434]
    bw (KB  /s): min=23336, max=34048, per=100.00%, avg=30375.16, stdev=4390.51
    lat (usec) : 50=2.54%, 100=95.58%, 250=1.85%, 500=0.03%, 750=0.01%
    lat (usec) : 1000=0.01%
  cpu          : usr=0.11%, sys=81.47%, ctx=103856, majf=0, minf=29
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=75113/w=75079/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=300452KB, aggrb=30042KB/s, minb=30042KB/s, maxb=30042KB/s, mint=10001msec, maxt=10001msec
  WRITE: io=300316KB, aggrb=30028KB/s, minb=30028KB/s, maxb=30028KB/s, mint=10001msec, maxt=10001msec

Disk stats (read/write):
  sdc: ios=74842/74787, merge=0/1, ticks=4097/4760, in_queue=8855, util=88.22%

(6)混合随机读写

[root@centos7 test]# fio -fimename=/dev/sdc1 -direct=1 -rw=randrw -iodepth=1 -ioengine=psync -bs=4k -size=2G -numjobs=1 -runtime=10 -group_reporting -name=name
name: (g=0): rw=randrw, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
fio-2.1.10
Starting 1 process
Jobs: 1 (f=1): [m] [100.0% done] [23160KB/23648KB/0KB /s] [5790/5912/0 iops] [eta 00m:00s]
name: (groupid=0, jobs=1): err= 0: pid=16210: Sun May  9 00:13:45 2021
  read : io=290024KB, bw=29000KB/s, iops=7249, runt= 10001msec
    clat (usec): min=44, max=771, avg=62.03, stdev=14.93
     lat (usec): min=44, max=771, avg=62.16, stdev=14.93
    clat percentiles (usec):
     |  1.00th=[   48],  5.00th=[   50], 10.00th=[   51], 20.00th=[   52],
     | 30.00th=[   53], 40.00th=[   55], 50.00th=[   57], 60.00th=[   60],
     | 70.00th=[   66], 80.00th=[   73], 90.00th=[   78], 95.00th=[   84],
     | 99.00th=[  102], 99.50th=[  118], 99.90th=[  179], 99.95th=[  221],
     | 99.99th=[  470]
    bw (KB  /s): min=23384, max=32232, per=100.00%, avg=29312.00, stdev=3044.28
  write: io=289732KB, bw=28970KB/s, iops=7242, runt= 10001msec
    clat (usec): min=54, max=771, avg=72.58, stdev=14.81
     lat (usec): min=54, max=771, avg=72.78, stdev=14.82
    clat percentiles (usec):
     |  1.00th=[   59],  5.00th=[   60], 10.00th=[   61], 20.00th=[   62],
     | 30.00th=[   63], 40.00th=[   65], 50.00th=[   67], 60.00th=[   71],
     | 70.00th=[   78], 80.00th=[   85], 90.00th=[   90], 95.00th=[   96],
     | 99.00th=[  114], 99.50th=[  131], 99.90th=[  187], 99.95th=[  225],
     | 99.99th=[  298]
    bw (KB  /s): min=23704, max=32056, per=100.00%, avg=29257.26, stdev=2921.99
    lat (usec) : 50=1.26%, 100=96.35%, 250=2.35%, 500=0.03%, 750=0.01%
    lat (usec) : 1000=0.01%
  cpu          : usr=0.17%, sys=85.70%, ctx=81379, majf=0, minf=27
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=72506/w=72433/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=290024KB, aggrb=28999KB/s, minb=28999KB/s, maxb=28999KB/s, mint=10001msec, maxt=10001msec
  WRITE: io=289732KB, aggrb=28970KB/s, minb=28970KB/s, maxb=28970KB/s, mint=10001msec, maxt=10001msec

Disk stats (read/write):
  sdc: ios=72006/71942, merge=0/1, ticks=4119/4861, in_queue=8976, util=89.73%

5、输出结果解释说明
IOPS (英文:Input/Output Operations Per Second),即每秒进行读写(I/O)操作的次数,多用于数据库、存储等场合,衡量随机访问的性能。
主要查看iops

iops :磁盘的每秒读写次数,这个是随机读写考察的重点  
bw   :磁盘的吞吐量,这个是顺序读写考察的重点,类似于下载速度  
avg  :每个IO请求的平均相应时间
io   :总的输入输出量 
runt :总运行时间
msec :毫秒
usec :微秒
lat (msec):延迟(毫秒)

随机关注IOPS 因为随机读写的话,每次IO操作的寻址时间和旋转延时都不能忽略不计,而这两个时间的存在也就限制了IOPS的大小
而顺序读写关注bw 可以忽略不计寻址时间和旋转延时,主要花费在数据传输的时间上。

注意:尽量避免对有数据的磁盘或者分区做测试,谨慎操作,可能理解不够透彻的话参数使用错误会破坏已存在的数据

posted @ 2021-05-09 00:38  -小-白-  阅读(1773)  评论(0编辑  收藏  举报