fio磁盘性能测试

目前主流的第三方IO测试工具有fio、iometer和Orion,这三种工具各有千秋。
fio在Linux系统下使用比较方便,iometer在window系统下使用比较方便,Orion是oracle的IO测试软件,可在没有安装oracle数据库的情况下模拟oracle数据库场景的读写。
如下是在Linux系统上采用fio工具来对SAN存储进行的IO测试。

1、安装fio
在fio官网下载fio-2.1.10.tar文件,解压后./configure、make、make install之后就可以使用fio了。
yum安装

yum install fio -y

2、fio参数解释
可以使用fio -help查看每个参数,具体的参数左右可以在官网查看how to文档,如下为几个常见的参数描述

filename=/dev/emcpowerb 支持文件系统或者裸设备,-filename=/dev/sda2或-filename=/dev/sdb
direct=1                 测试过程绕过机器自带的buffer,使测试结果更真实
rw=randwread             测试随机读的I/O
rw=randwrite             测试随机写的I/O
rw=randrw                测试随机混合写和读的I/O
rw=read                  测试顺序读的I/O
rw=write                 测试顺序写的I/O
rw=rw                    测试顺序混合写和读的I/O
bs=4k                    单次io的块文件大小为4k
bsrange=512-2048         同上,提定数据块的大小范围
size=5g                  本次的测试文件大小为5g,以每次4k的io进行测试
numjobs=30               本次的测试线程为30
runtime=1000             测试时间为1000秒,如果不写则一直将5g文件分4k每次写完为止
ioengine=psync           io引擎使用pync方式,如果要使用libaio引擎,需要yum install libaio-devel包
rwmixwrite=30            在混合读写的模式下,写占30%
group_reporting          关于显示结果的,汇总每个进程的信息
此外
lockmem=1g               只使用1g内存进行测试
zero_buffers             用0初始化系统buffer
nrfiles=8                每个进程生成文件的数量

3、fio测试场景及生成报告详解

测试场景:

100%随机,100%读, 4K

fio -filename=/dev/emcpowerb -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=4k -size=1000G -numjobs=50 -runtime=180 -group_reporting -name=rand_100read_4k

100%随机,100%写, 4K

fio -filename=/dev/emcpowerb -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=psync -bs=4k -size=1000G -numjobs=50 -runtime=180 -group_reporting -name=rand_100write_4k

100%顺序,100%读 ,4K

fio -filename=/dev/emcpowerb -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=4k -size=1000G -numjobs=50 -runtime=180 -group_reporting -name=sqe_100read_4k

100%顺序,100%写 ,4K

fio -filename=/dev/emcpowerb -direct=1 -iodepth 1 -thread -rw=write -ioengine=psync -bs=4k -size=1000G -numjobs=50 -runtime=180 -group_reporting -name=sqe_100write_4k

100%随机,70%读,30%写 4K

fio -filename=/dev/emcpowerb -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=4k -size=1000G -numjobs=50 -runtime=180 -group_reporting -name=randrw_70read_4k

结果报告查看:

[root@yzfs-jenkins-230 ~]# fio -filename=/tmp/2   -thread -rw=randread -ioengine=psync -bs=4k -size=10G -numjobs=50 -runtime=60 -group_reporting -name=rand_100read_4k
rand_100read_4k: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=psync, iodepth=1
...
fio-3.7
Starting 50 threads
rand_100read_4k: Laying out IO file (1 file / 10240MiB)
Jobs: 50 (f=50): [r(50)][100.0%][r=435MiB/s,w=0KiB/s][r=111k,w=0 IOPS][eta 00m:00s]
rand_100read_4k: (groupid=0, jobs=50): err= 0: pid=12299: Tue Mar  7 23:20:51 2023
   read: IOPS=86.3k, BW=337MiB/s (354MB/s)(19.8GiB/60003msec)
    clat (nsec): min=807, max=10859k, avg=578374.78, stdev=668161.99
     lat (nsec): min=826, max=10859k, avg=578442.96, stdev=668164.66
    clat percentiles (nsec):
     |  1.00th=[   1160],  5.00th=[   1256], 10.00th=[   1320],
     | 20.00th=[   1496], 30.00th=[   1752], 40.00th=[   2160],
     | 50.00th=[ 329728], 60.00th=[ 659456], 70.00th=[ 962560],
     | 80.00th=[1253376], 90.00th=[1564672], 95.00th=[1761280],
     | 99.00th=[2408448], 99.50th=[2637824], 99.90th=[2899968],
     | 99.95th=[2998272], 99.99th=[4620288]
   bw (  KiB/s): min= 3472, max=10192, per=2.00%, avg=6901.18, stdev=1989.80, samples=5988
   iops        : min=  868, max= 2548, avg=1725.27, stdev=497.45, samples=5988
  lat (nsec)   : 1000=0.02%
  lat (usec)   : 2=37.50%, 4=7.37%, 10=2.23%, 20=0.14%, 50=0.04%
  lat (usec)   : 100=0.01%, 250=0.93%, 500=6.74%, 750=8.06%, 1000=8.23%
  lat (msec)   : 2=26.47%, 4=2.25%, 10=0.02%, 20=0.01%
  cpu          : usr=0.24%, sys=1.36%, ctx=2729837, majf=1, minf=13
  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 rwts: total=5179641,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: bw=337MiB/s (354MB/s), 337MiB/s-337MiB/s (354MB/s-354MB/s), io=19.8GiB (21.2GB), run=60003-60003msec

Disk stats (read/write):
  sda: ios=2723239/26, merge=6/1, ticks=2935501/53, in_queue=2935853, util=99.94%

io=执行了多少M的IO
bw=平均IO带宽
iops=IOPS
runt=线程运行时间
slat=提交延迟
clat=完成延迟
lat=响应时间
bw=带宽
cpu=利用率
IO depths=io队列
IO submit=单个IO提交要提交的IO数
IO complete=Like the above submit number, but for completions instead.
IO issued=The number of read/write requests issued, and how many of them were short.
IO latencies=IO完延迟的分布
io=总共执行了多少size的IO
aggrb=group总带宽
minb=最小.平均带宽.
maxb=最大平均带宽.
mint=group中线程的最短运行时间.
maxt=group中线程的最长运行时间.
ios=所有group总共执行的IO数.
merge=总共发生的IO合并数.
ticks=Number of ticks we kept the disk busy.
io_queue=花费在队列上的总共时间.
util=磁盘利用率
4、扩展之IO队列深度

在某个时刻,有N个inflight的IO请求,包括在队列中的IO请求、磁盘正在处理的IO请求。N就是队列深度。
加大硬盘队列深度就是让硬盘不断工作,减少硬盘的空闲时间。
加大队列深度 -> 提高利用率 -> 获得IOPS和MBPS峰值 ->注意响应时间在可接受的范围内,
增加队列深度的办法有很多,使用异步IO,同时发起多个IO请求,相当于队列中有多个IO请求,多线程发起同步IO请求,相当于队列中有多个IO请求。
增大应用IO大小,到达底层之后,会变成多个IO请求,相当于队列中有多个IO请求 队列深度增加了。
队列深度增加了,IO在队列的等待时间也会增加,导致IO响应时间变大,这需要权衡。

为何要对磁盘I/O进行并行处理呢?主要目的是提升应用程序的性能。这一点对于多物理磁盘组成的虚拟磁盘(或LUN)显得尤为重要。
如果一次提交一个I/O,虽然响应时间较短,但系统的吞吐量很小。
相比较而言,一次提交多个I/O既缩短了磁头移动距离(通过电梯算法),同时也能够提升IOPS。
假如一部电梯一次只能搭乘一人,那么每个人一但乘上电梯,就能快速达到目的地(响应时间),但需要耗费较长的等待时间(队列长度)。
因此一次向磁盘系统提交多个I/O能够平衡吞吐量和整体响应时间。

Linux系统查看默认队列深度:

[root@qsdb ~]# lsscsi -l
[0:0:0:0]    disk    DGC      VRAID            0533  /dev/sda 
  state=running queue_depth=30 scsi_level=5 type=0 device_blocked=0 timeout=30
[0:0:1:0]    disk    DGC      VRAID            0533  /dev/sdb 
  state=running queue_depth=30 scsi_level=5 type=0 device_blocked=0 timeout=30
[2:0:0:0]    disk    DGC      VRAID            0533  /dev/sdd 
  state=running queue_depth=30 scsi_level=5 type=0 device_blocked=0 timeout=30
[2:0:1:0]    disk    DGC      VRAID            0533  /dev/sde 
  state=running queue_depth=30 scsi_level=5 type=0 device_blocked=0 timeout=30
[4:2:0:0]    disk    IBM      ServeRAID M5210  4.27  /dev/sdc 
  state=running queue_depth=256 scsi_level=6 type=0 device_blocked=0 timeout=90
[9:0:0:0]    cd/dvd  Lenovo   SATA ODD 81Y3677 IB00  /dev/sr0 
  state=running queue_depth=1 scsi_level=6 type=5 device_blocked=0 timeout=30

使用dd命令设置bs=2M进行测试:

dd if=/dev/zero of=/dev/sdd bs=2M count=1000 oflag=direct

记录了1000+0 的读入 记录了1000+0 的写出 2097152000字节(2.1 GB)已复制,10.6663 秒,197 MB/秒

Device: rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s   avgrq-sz   avgqu-sz   await   svctm   %util
sdd      0.00     0.00   0.00  380.60  0.00    389734.40  1024.00  2.39       6.28    2.56    97.42

可以看到2MB的IO到达底层之后,会变成多个512KB的IO,平均队列长度为2.39,这个硬盘的利用率是97%,MBPS达到了197MB/s。
(为什么会变成512KB的IO,你可以去使用Google去查一下内核参数 max_sectors_kb的意义和使用方法 )也就是说增加队列深度,是可以测试出硬盘的峰值的。

posted @ 2023-03-07 23:28  老夫聊发少年狂88  阅读(835)  评论(0编辑  收藏  举报