fio使用

介绍

目前主流的第三方IO测试工具有fio、iometer和Orion,这三种工具各有千秋。

fio在Linux系统下使用比较方便,iometer在window系统下使用比较方便,Orion是oracle的IO测试软件,可在没有安装oracle数据库的情况下模拟oracle数据库场景的读写。

如下是在Linux系统上采用fio工具来对SAN存储进行的IO测试。

安装

编译安装

1)下载Fio源码。

wget https://github.com/axboe/fio/archive/fio-2.1.10.tar.gz

2)解压Fio源码。

tar -zxvf fio-2.1.10.tar.gz

3)编译并安装Fio。

cd fio-fio-2.1.10

make

make install

4)检查安装的Fio版本号。

fio --version

5)回显信息如下,则Fio安装成功。

fio-2.1.10

4.测试已完成编译的软件

以读带宽为例,测试Fio是否可以正常使用。

执行以下命令:

fio --filename=/tmp/test_read -direct=1 -rw=read -bs=1m -size=1G -numjobs=4 -runtime=10 -group_reporting -name=mytest

回显信息如下,若能正常显示磁盘读速率,则表示Fio可正常使用。

mytest: (g=0): rw=read, bs=1M-1M/1M-1M/1M-1M, ioengine=sync, iodepth=1

...

fio-2.1.10

Starting 4 processes

mytest: Laying out IO file(s) (1 file(s) / 1024MB)

Jobs: 4 (f=4): [RRRR] [100.0% done] [150.0MB/0KB/0KB /s] [150/0/0 iops] [eta 00m:00s]

mytest: (groupid=0, jobs=4): err= 0: pid=20659: Sat Jul  6 18:00:27 2019

  read : io=1587.0MB, bw=153195KB/s, iops=149, runt= 10608msec

    clat (msec): min=1, max=869, avg=26.72, stdev=133.87

     lat (msec): min=1, max=869, avg=26.72, stdev=133.87

    clat percentiles (msec):

     |  1.00th=[    3],  5.00th=[    3], 10.00th=[    3], 20.00th=[    4],

     | 30.00th=[    4], 40.00th=[    4], 50.00th=[    5], 60.00th=[    5],

     | 70.00th=[    5], 80.00th=[    6], 90.00th=[    7], 95.00th=[    8],

     | 99.00th=[  848], 99.50th=[  857], 99.90th=[  865], 99.95th=[  873],

     | 99.99th=[  873]

    bw (KB  /s): min=36283, max=40487, per=25.04%, avg=38354.52, stdev=879.60

    lat (msec) : 2=0.57%, 4=47.20%, 10=48.20%, 20=1.13%, 50=0.13%

    lat (msec) : 500=0.25%, 1000=2.52%

  cpu          : usr=0.05%, sys=0.15%, ctx=1599, majf=0, minf=84

  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=1587/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=1587.0MB, aggrb=153194KB/s, minb=153194KB/s, maxb=153194KB/s, mint=10608msec, maxt=10608msec

Disk stats (read/write):

  vda: ios=1602/4, merge=31/7, ticks=42550/0, in_queue=12010, util=34.53%

yum安装

yum install fio

参数解释

精简版

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                每个进程生成文件的数量

全 

-direct=1              /*定义是否使用direct IO,可选值如下:值为0,表示使用buffered IO;值为1,表示使用 direct IO,测试过程绕过机器自带的buffer。使测 
                         试结果更真实。*/

-iodepth=64            /*定义测试时的IO队列深度,默认为1。此处定义的队列深度是指每个线程的队列深度, 如果有多个线程测试,意味着每个线程都是此处定义的队列深
                         度。fio总的IO并发数 =iodepth * numjobs*/

-rw=randwrite          /*定义测试时的读写策略,可选值如下:随机读:randread,随机写:randwrite,顺序读: read,顺序写:write,混合随机读写:randrw

-bs=4k		       /*定义IO的块大小(block size),单位是k、K、m和M等,默认IO块大小为4 KB*/

-size=100M             /*定义测试IO操作的数据量,若未指定runtime这类参数,fio会将指定大小的数据量全部 读/写完成,然后才停止测试。该参数的值,可以是带单位
                         的数字,比如size=10G,表示读/写的数据量为10GB;也可是百分数,比如size=20%,表示读/写的数据量占该设备总文件的20%的空间。建议测试
                         数据量为内存两倍大,尽量避免缓存影响。*/

-numjobs=1	       /*每个job(任务)开1个线程,这里用了几,后面每个用-name指定的任务就开几个线程测试。所以最终线程数=任务数(几个name=jobx)* 							 numjobs。 */

-runtime	       /*定义测试时间。如果未配置,则持续将size指定的文件大小,以每次bs值为分块大小读/ 写完。*/

-group_reporting       /*定义测试结果显示模式,group_reporting 表示汇总每个进程的统计信息,而非以不同 job汇总展示信息。*/

-filename=/dev/sdb1    /*测试文件名称,通常选择需要测试的盘的data目录。*/

-ioengine=libaio       /*libaio指的是异步模式,如果是同步就要用sync。
			vsync - 使用 readv / writev,主要是会将相邻的 I/O 进行合并 
			psync - 对应的 pread / pwrite,增量同步,一般sync是全量的
			pvsync / pvsync2 - 对应的 preadv / pwritev,以及 preadv2 / p writev2
			定义fio如何下发IO请求,通常有同步IO和异步IO:同步IO一次只能发出一个IO请求, 等待内核完成后才返回。这样对于单个线程IO队列深度总是小						 于1,但是可以透过多个线程并发执行来解决。通常会用16~32个线程同时工作把IO队列深度塞满。异步IO则通常使用libaio这样的方式一次提交一批						  IO 请求,然后等待一批的完成,减少交互的次数,会更有效率*/

-thread		       /*使用pthread_create创建线程,另一种是fork创建进程。进程的开销比线程要大,一般都采用thread测试。*/

–numjobs=1	       /*定义测试的并发线程数*/


-filename	       /*定义测试文件(设备)的名称。此处选择文件,则代表测试文件系统的性能,例如:- filename=/opt/fiotest/fiotest.txt;此处选择设备名						  称,则代表测试裸盘的性能,例:-filename=/dev/vdb1。如果在已经分区、并创建文件系统,且已写入数据的磁盘上进行性能测试,请注意
		        filename选择指定文件,以避免覆盖文件系统和原有数据。*/

-size=100M	       /*定义测试IO操作的数据量,若未指定runtime这类参数,fio会将指定大小的数据量全部 读/写完成,然后才停止测试。该参数的值,可以是带单位						 的数字,比如size=10G,表示读/写的数据量为10GB;也可是百分数,比如size=20%,表示读/写的数据量占该设备总文件的20%的空间。建议测试						  数据量为内存两倍大,尽量避免缓存影响。*/

-name=job1	       /*定义测试任务名称。*/

–output TestResult.log /*日志输出到TestResult.log。*/

-rwmixwrite=30      /*在混合读写的模式下,写占30% */

-lockmem=1g       /*只使用1g内存进行测试。 */

-zero_buffers       /*用0初始化系统buffer。*/

-nrfiles=8        /*每个进程生成文件的数量。*/

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@rac01-node02]# fio -filename=/dev/sdc4 -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_local
randrw_70read_4k_local: (g=0): rw=randrw, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
...
fio-2.1.10
Starting 50 threads
Jobs: 21 (f=21): [____m____m_m___m____mmm__mmm__mm_m_mmm_m__m__m_m_m] [3.4% done] [7004KB/2768KB/0KB /s] [1751/692/0 iops] [eta 01h:27m:00s]
randrw_70read_4k_local: (groupid=0, jobs=50): err= 0: pid=13710: Wed May 31 10:23:31 2017
  read : io=1394.2MB, bw=7926.4KB/s, iops=1981, runt=180113msec
    clat (usec): min=39, max=567873, avg=24323.79, stdev=25645.98
     lat (usec): min=39, max=567874, avg=24324.23, stdev=25645.98
    clat percentiles (msec):
     |  1.00th=[    3],  5.00th=[    5], 10.00th=[    6], 20.00th=[    7],
     | 30.00th=[    9], 40.00th=[   12], 50.00th=[   16], 60.00th=[   21],
     | 70.00th=[   27], 80.00th=[   38], 90.00th=[   56], 95.00th=[   75],
     | 99.00th=[  124], 99.50th=[  147], 99.90th=[  208], 99.95th=[  235],
     | 99.99th=[  314]
    bw (KB  /s): min=   15, max=  537, per=2.00%, avg=158.68, stdev=38.08
  write: io=615280KB, bw=3416.8KB/s, iops=854, runt=180113msec
    clat (usec): min=167, max=162537, avg=2054.79, stdev=7665.24
     lat (usec): min=167, max=162537, avg=2055.38, stdev=7665.23
    clat percentiles (usec):
     |  1.00th=[  201],  5.00th=[  227], 10.00th=[  249], 20.00th=[  378],
     | 30.00th=[  548], 40.00th=[  692], 50.00th=[  844], 60.00th=[  996],
     | 70.00th=[ 1160], 80.00th=[ 1304], 90.00th=[ 1720], 95.00th=[ 3856],
     | 99.00th=[40192], 99.50th=[58624], 99.90th=[98816], 99.95th=[123392],
     | 99.99th=[148480]
    bw (KB  /s): min=    6, max=  251, per=2.00%, avg=68.16, stdev=29.18
    lat (usec) : 50=0.01%, 100=0.03%, 250=3.15%, 500=5.00%, 750=5.09%
    lat (usec) : 1000=4.87%
    lat (msec) : 2=9.64%, 4=4.06%, 10=21.42%, 20=18.08%, 50=19.91%
    lat (msec) : 100=7.24%, 250=1.47%, 500=0.03%, 750=0.01%
  cpu          : usr=0.07%, sys=0.21%, ctx=522490, majf=0, minf=7
  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=356911/w=153820/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=1394.2MB, aggrb=7926KB/s, minb=7926KB/s, maxb=7926KB/s, mint=180113msec, maxt=180113msec
  WRITE: io=615280KB, aggrb=3416KB/s, minb=3416KB/s, maxb=3416KB/s, mint=180113msec, maxt=180113msec

Disk stats (read/write):
  sdc: ios=356874/153927, merge=0/10, ticks=8668598/310288, in_queue=8978582, util=99.99%

解析

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=磁盘利用率

 

 测试及结果说明2

磁盘读写常用测试点

1. Read=100% Ramdon=100% rw=randread (100%随机读)

2. Read=100% Sequence=100% rw=read (100%顺序读)

3. Write=100% Sequence=100% rw=write (100%顺序写)

4. Write=100% Ramdon=100% rw=randwrite (100%随机写)

5. Read=70% Sequence=100% rw=rw, rwmixread=70, rwmixwrite=30(70%顺序读,30%顺序写)

6. Read=70% Ramdon=100% rw=randrw, rwmixread=70, rwmixwrite=30(70%随机读,30%随机写)

4k随机读写,70%读+30%写,30个并发

[root@tydb010 data2]# fio -direct=1 -iodepth=1 -thread -rw=randrw -rwmixread=70 -ioengine=libaio -bs=4k -size=4G -numjobs=30 -runtime=60 -group_reporting -filename=/data2/1.txt -name=Write_BandWidth_Test
Write_BandWidth_Test: (g=0): rw=randrw, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=1
...
fio-3.14
Starting 30 threads
Write_BandWidth_Test: Laying out IO file (1 file / 4096MiB)
Jobs: 30 (f=30): [m(30)][100.0%][r=24.2MiB/s,w=10.5MiB/s][r=6206,w=2692 IOPS][eta 00m:00s]
Write_BandWidth_Test: (groupid=0, jobs=30): err= 0: pid=11155: Mon Jun 13 16:38:40 2022
  read: IOPS=6381, BW=24.9MiB/s (26.1MB/s)(1496MiB/60008msec)
    slat (usec): min=39, max=647909, avg=379.86, stdev=9733.94
    clat (nsec): min=604, max=379829k, avg=3132927.68, stdev=8833769.30
     lat (usec): min=68, max=647913, avg=3526.35, stdev=13178.41
    clat percentiles (nsec):
     |  1.00th=[     1608],  5.00th=[     1928], 10.00th=[     2512],
     | 20.00th=[    37632], 30.00th=[    50432], 40.00th=[  2113536],
     | 50.00th=[  2375680], 60.00th=[  2605056], 70.00th=[  2867200],
     | 80.00th=[  3391488], 90.00th=[  5668864], 95.00th=[  8224768],
     | 99.00th=[ 21364736], 99.50th=[ 38010880], 99.90th=[147849216],
     | 99.95th=[183500800], 99.99th=[265289728]
   bw (  KiB/s): min= 4291, max=38895, per=99.42%, avg=25377.61, stdev=182.49, samples=3585
   iops        : min= 1067, max= 9711, avg=6339.06, stdev=45.63, samples=3585
  write: IOPS=2738, BW=10.7MiB/s (11.2MB/s)(642MiB/60008msec)
    slat (usec): min=47, max=647261, avg=461.69, stdev=10445.88
    clat (nsec): min=659, max=411384k, avg=2215531.55, stdev=8180669.00
     lat (usec): min=75, max=647264, avg=2695.71, stdev=13337.17
    clat percentiles (nsec):
     |  1.00th=[     1656],  5.00th=[     1944], 10.00th=[     2416],
     | 20.00th=[     3152], 30.00th=[    33536], 40.00th=[    37632],
     | 50.00th=[    50432], 60.00th=[  2539520], 70.00th=[  2834432],
     | 80.00th=[  3194880], 90.00th=[  4112384], 95.00th=[  5799936],
     | 99.00th=[ 12255232], 99.50th=[ 20578304], 99.90th=[147849216],
     | 99.95th=[183500800], 99.99th=[258998272]
   bw (  KiB/s): min= 2005, max=18017, per=99.41%, avg=10889.09, stdev=86.89, samples=3585
   iops        : min=  494, max= 4495, avg=2715.49, stdev=21.73, samples=3585
  lat (nsec)   : 750=0.01%, 1000=0.01%
  lat (usec)   : 2=5.71%, 4=13.53%, 10=0.09%, 20=0.03%, 50=16.59%
  lat (usec)   : 100=1.31%, 250=0.02%, 500=0.09%, 750=0.07%, 1000=0.12%
  lat (msec)   : 2=4.10%, 4=43.46%, 10=11.89%, 20=2.03%, 50=0.58%
  lat (msec)   : 100=0.16%, 250=0.20%, 500=0.01%
  cpu          : usr=0.21%, sys=3.11%, ctx=344789, majf=0, minf=37
  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=382937,164339,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=24.9MiB/s (26.1MB/s), 24.9MiB/s-24.9MiB/s (26.1MB/s-26.1MB/s), io=1496MiB (1569MB), run=60008-60008msec
  WRITE: bw=10.7MiB/s (11.2MB/s), 10.7MiB/s-10.7MiB/s (11.2MB/s-11.2MB/s), io=642MiB (673MB), run=60008-60008msec

Disk stats (read/write):
  sdc: ios=382060/163979, merge=0/12, ticks=41077/19349, in_queue=60391, util=98.77%

缩写解释

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=磁盘利用率

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骑猪去兜风z1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值