zoukankan      html  css  js  c++  java
  • linux 磁盘IO测试工具:FIO (同时简要介绍dd工具测试)

    FIO是测试IOPS的非常好的工具,用来对硬件进行压力测试和验证。磁盘IO是检查磁盘性能的重要指标,可以按照负载情况分成照顺序读写,随机读写两大类。

    目前主流的第三方IO测试工具有fio、iometer 和 Orion,这三种工具各有千秋,在linux 下也可以使用dd 进行简单的磁盘(文件系统)测试(文末补充)。

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

    Multithreaded IO generation tool , FIO 是一个多线程io生成工具,可以生成多种IO模式,用来测试磁盘设备的性能(也包含文件系统:如针对网络文件系统 NFS 的IO测试);

    Description  : fio is an I/O tool that will spawn a number of threads or processes doing

                 : a particular type of io action as specified by the user.  fio takes a

                 : number of global parameters, each inherited by the thread unless

                 : otherwise parameters given to them overriding that setting is given.

                 : The typical use of fio is to write a job file matching the io load

                 : one wants to simulate.

    安装:

    yum install fio
    yum info fio

    项目地址:

    https://github.com/axboe/fio.git

    http://git.kernel.dk/cgit/fio/

    磁盘处理:

    fio 用于测试磁盘性能时,测试之前需要先把要测试的磁盘卸载掉,测试完后需格式化一遍再挂载上去。

    # 卸载磁盘
    umount /mnt/datadir1
    # 格式化磁盘
    mkfs.ext4 /dev/sdd
    # 挂载磁盘
    mount -t ext4 /dev/sdd /mnt/datadir1
    
    # 自动挂载,在里面添加该盘
    vim /etc/fstab

    FIO 工具常用方法:

    参数说明:
    filename=/dev/sdb1 测试文件名称,通常选择需要测试的盘的data目录。
    direct=1 测试过程绕过机器自带的buffer。使测试结果更真实。
    rw=randwrite 测试随机写的I/O
    rw=randrw 测试随机写和读的I/O
    bs=16k 单次io的块文件大小为16k
    bsrange=512-2048 同上,提定数据块的大小范围
    size=5g 本次的测试文件大小为5g,以每次4k的io进行测试。
    numjobs=30 本次的测试线程为30.
    runtime=1000 测试时间为1000秒,如果不写则一直将5g文件分4k每次写完为止。
    ioengine=psync io引擎使用pync方式
    rwmixwrite=30 在混合读写的模式下,写占30%
    group_reporting 关于显示结果的,汇总每个进程的信息。
    此外
    lockmem=1g 只使用1g内存进行测试。
    zero_buffers 用0初始化系统buffer。
    nrfiles=8 每个进程生成文件的数量。
    磁盘读写常用测试点:
    1. Read=100% Ramdon=100% rw=randread (100%随机读)
    2. Read=100% Sequence=100% rw=read (100%顺序读)
    3. Write=100% Sequence=100% rw=write100%顺序写)
    4. Write=100% Ramdon=100% rw=randwrite (100%随机写)
    5. Read=70% Sequence=100% rw=rw, rwmixread=70, rwmixwrite=3070%顺序读,30%顺序写)
    6. Read=70% Ramdon=100% rw=randrw, rwmixread=70, rwmixwrite=30
    (70%随机读,30%随机写)

    FIO 工具测试模式:

    顺序读写:

    read 顺序读

    write 顺序写

    rw,readwrite 顺序混合读写

    随机读写:

    randwrite 随机写

    randread 随机读

    randrw 随机混合读写

    测试样例:

    [root@docker mnt]# fio -filename=/dev/sda -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=16k -size=20G -numjobs=30 -runtime=1000 -group_reporting -name=yaoxu-sda

    本文章,只是资料查找中的简要摘录,详细使用说明,请参考 man fio

    测试结果:(其中加粗的输出日志,是我们关注的内容:磁盘的吞吐量bw,这个是顺序读写考察的重点;磁盘的每秒读写次数iops,这个是随机读写考察的重点)

    [root@docker sda]# fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=read -filename=/dev/sda -name="BS 4KB read test" -iodepth=16 -runtime=60
    BS 4KB read test: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=16
    fio-3.7
    Starting 1 thread
    Jobs: 1 (f=1): [R(1)][100.0%][r=89.3MiB/s,w=0KiB/s][r=22.9k,w=0 IOPS][eta 00m:00s]
    BS 4KB read test: (groupid=0, jobs=1): err= 0: pid=18557: Thu Apr 11 13:08:11 2019
       read: IOPS=22.7k, BW=88.5MiB/s (92.8MB/s)(5313MiB/60001msec)
        slat (nsec): min=901, max=168330, avg=6932.34, stdev=1348.82
        clat (usec): min=90, max=63760, avg=698.08, stdev=240.83
         lat (usec): min=97, max=63762, avg=705.17, stdev=240.81
        clat percentiles (usec):
         |  1.00th=[  619],  5.00th=[  627], 10.00th=[  627], 20.00th=[  635],
         | 30.00th=[  635], 40.00th=[  685], 50.00th=[  717], 60.00th=[  725],
         | 70.00th=[  725], 80.00th=[  725], 90.00th=[  734], 95.00th=[  816],
         | 99.00th=[ 1004], 99.50th=[ 1020], 99.90th=[ 1057], 99.95th=[ 1057],
         | 99.99th=[ 1860]
       bw (  KiB/s): min=62144, max=91552, per=100.00%, avg=90669.02, stdev=3533.77, samples=120
       iops        : min=15536, max=22888, avg=22667.27, stdev=883.44, samples=120
      lat (usec)   : 100=0.01%, 250=0.01%, 500=0.01%, 750=93.85%, 1000=5.14%
      lat (msec)   : 2=0.99%, 4=0.01%, 10=0.01%, 50=0.01%, 100=0.01%
      cpu          : usr=5.35%, sys=23.17%, ctx=1359692, majf=0, minf=17
      IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=100.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.1%, 32=0.0%, 64=0.0%, >=64=0.0%
         issued rwts: total=1360097,0,0,0 short=0,0,0,0 dropped=0,0,0,0
         latency   : target=0, window=0, percentile=100.00%, depth=16
    
    Run status group 0 (all jobs):
       READ: bw=88.5MiB/s (92.8MB/s), 88.5MiB/s-88.5MiB/s (92.8MB/s-92.8MB/s), io=5313MiB (5571MB), run=60001-60001msec
    
    Disk stats (read/write):
      sda: ios=1357472/0, merge=70/0, ticks=949141/0, in_queue=948776, util=99.88%

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

    fio 有很多测试任务配置文件,在git工程 examples 文件夹中,我们可以使用命令行参数进行直接配置,也可以直接通过配置文件配置一次测试的内容。

    更详细对fio输出说明请参考博文:Fio Output Explained 

    IO状态监控:

    进行磁盘测试的时候,我们可以使用iostat 等监控工具,查看所有磁盘当前的读写状态(fedora 系统上 sysstat-11.7.3-2.fc29.x86_64 收录了此工具)。

    监控磁盘IO命令:iostat –mx 1

    avg-cpu:  %user   %nice %system %iowait  %steal   %idle
               0.25    0.00    3.01   80.70    0.00   16.04
    
    Device            r/s     w/s     rMB/s     wMB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    sda           13417.00    0.00    209.64      0.00     0.00     0.00   0.00   0.00    2.23    0.00  29.96    16.00     0.00   0.07 100.00
    rrqms:每秒这个设备相关的读取请求有多少被Merge了(当系统调用需要读取数据的时候,VFS将请求发到各个FS,如果FS发现不同的读取请求读取的是相同Block的数据,FS会将这个请求合并Merge)
    wrqm/s:每秒这个设备相关的写入请求有多少被Merge了。
    rsec/s:The number of sectors read from the device per second.
    wsec/s:The number of sectors written to the device per second.
    rKB/s:The number of kilobytes read from the device per second.
    wKB/s:The number of kilobytes written to the device per second.
    avgrq-sz:平均请求扇区的大小,The average size (in sectors) of the requests that were issued to the device.
    avgqu-sz:是平均请求队列的长度。毫无疑问,队列长度越短越好,The average queue length of the requests that were issued to the device.   
    await:每一个IO请求的处理的平均时间(单位是微秒毫秒)。这里可以理解为IO的响应时间,一般地系统IO响应时间应该低于5ms,如果大于10ms就比较大了。
    这个时间包括了队列时间和服务时间,也就是说,一般情况下,await大于svctm,它们的差值越小,则说明队列时间越短,反之差值越大,队列时间越长,说明系统出了问题。
    svctm:表示平均每次设备I/O操作的服务时间(以毫秒为单位)。如果svctm的值与await很接近,表示几乎没有I/O等待,磁盘性能很好。
    如果await的值远高于svctm的值,则表示I/O队列等待太长,系统上运行的应用程序将变慢。
    %util: 在统计时间内所有处理IO时间,除以总共统计时间。例如,如果统计间隔1秒,该设备有0.8秒在处理IO,而0.2秒闲置,那么该设备的%util = 0.8/1 = 80%,
    所以该参数暗示了设备的繁忙程度,一般地,如果该参数是100%表示磁盘设备已经接近满负荷运行了(当然如果是多磁盘,即使%util是100%,因为磁盘的并发能力,所以磁盘使用未必就到了瓶颈)。
    View Code

    更多关于磁盘顺序io 部分,可以参考 dd 工具的使用;https://www.cnblogs.com/xuyaowen/p/dd.html 

    参考链接:

    https://www.cnblogs.com/bugutian/p/6653083.html

    https://www.linuxidc.com/Linux/2017-04/143251.htm

    https://github.com/axboe/fio

    https://blog.csdn.net/jiecxy/article/details/58197387 (有很好的fio 输出日志注释,解释了每行输出内容的含义,建议阅读。)

    https://www.cnblogs.com/raykuan/p/6914748.html

    https://blog.csdn.net/feng4656/article/details/11054595

    https://tobert.github.io/post/2014-04-17-fio-output-explained.html

    https://github.com/axboe/fio/blob/master/HOWTO

    保持更新,转载请注明出处。

  • 相关阅读:
    Linnia学习记录
    漫漫考研路
    ENS的学习记录
    KnockoutJS 3.X API 第四章 数据绑定(4) 控制流with绑定
    KnockoutJS 3.X API 第四章 数据绑定(3) 控制流if绑定和ifnot绑定
    KnockoutJS 3.X API 第四章 数据绑定(2) 控制流foreach绑定
    KnockoutJS 3.X API 第四章 数据绑定(1) 文本及样式绑定
    KnockoutJS 3.X API 第三章 计算监控属性(5) 参考手册
    KnockoutJS 3.X API 第三章 计算监控属性(4)Pure computed observables
    KnockoutJS 3.X API 第三章 计算监控属性(3) KO如何实现依赖追踪
  • 原文地址:https://www.cnblogs.com/xuyaowen/p/fio-usage.html
Copyright © 2011-2022 走看看