磁盘IO测试工具之fio的介绍

发表于:2021-5-11 09:25

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:吃火锅国家二级运动员    来源:博客园

#
fio
分享:
  目前主流的第三方IO测试工具有fio、iometer和Orion,这三种工具各有千秋。
  · fio:Linux系统下使用比较方便;
  · iometer:window系统下使用比较方便;
  · Orion:oracle的IO测试软件,可在没有安装oracle数据库的情况下模拟oracle数据库场景的读写。
  一、fio安装
  1、wiki地址
http://fio.readthedocs.io/en/latest/fio_doc.html#
  2、源码下载
https://git.kernel.org/pub/scm/linux/kernel/git/axboe/fio.git
  http://brick.kernel.dk/snaps/
  https://github.com/axboe/fio.git
  要先安装libaio-devel, centos;
  $ yum install libaio-devel
  $ ./configure
  $ make
  $ make install
  若要启动gfio,需安装gtk2,configure时加上--enable-gfio;
  $ yum install libaio-devel
  $ yum install gtk2
  $ yum install gtk2-devel
  $ ./configure --enable-gfio
  $ make
  $ make install
  3、参数
  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                每个进程生成文件的数量
  I/O engine 引擎
  ioengine=str
   
  有以下几种常用模式,官方有几十种包括给hdfs,rdma和ceph特用的:
  一般就是用psync,异步时用libaio,此时direct设置为1,且可用iodepth
   
  sync
  Basic read(2) or write(2) I/O. lseek(2) is used to position the I/O location. See fsync and fdatasync for syncing write I/Os.
   
  psync
  Basic pread(2) or pwrite(2) I/O. Default on all supported operating systems except for Windows.
   
  vsync
  Basic readv(2) or writev(2) I/O. Will emulate queuing by coalescing adjacent I/Os into a single submission.
   
  pvsync
  Basic preadv(2) or pwritev(2) I/O.
   
  pvsync2
  Basic preadv2(2) or pwritev2(2) I/O.
   
  libaio
  Linux native asynchronous I/O. Note that Linux may only support queued behavior with non-buffered I/O (set direct=1 or buffered=0). This engine defines engine specific options.
   
  posixaio
  POSIX asynchronous I/O using aio_read(3) and aio_write(3).
   
  solarisaio
  Solaris native asynchronous I/O.
   
  windowsaio
  Windows native asynchronous I/O. Default on Windows.
   
  mmap
  File is memory mapped with mmap(2) and data copied to/from using memcpy(3).
  4、测试
  测试场景1:
  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
  测试场景2:从cephfs同步数据至华为云的sfs上速度极慢3M/s。
  $ cd /mnt/cephfs
  $ sudo   fio -ioengine=libaio \
      -bs=4k \
      -direct=1 \
      -thread \
      -rw=randread \
      -size=10G \
      -filename=4k-test \
      -name="4k-test" \
      -iodepth=8 \
      -runtime=60
  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=磁盘利用率
  5、fio可以使用脚本也可以使用命令行
  脚本:
  [mytest]
  filename=/mnt/beegfs/fioTest
  ioengine=psync
  direct=0
  thread
  rw=randread
  bs=4k
  size=1g
  numjobs=2
  runtime=10
  group_reporting
  命令行:
  fio -name=mytest -filename=/mnt/beegfs/fioTest -direct=0 -thread -rw=randread -ioengine=psync -bs=4k -size=1M -numjobs=2 -runtime=10 -group_reporting
  注:
  -filename指定测试文件名,即这里要测试beegfs文件系统下的fioTest文件,<br>-direct=0不使用O_DIECT方式,
  -thread创建线程为POSIX线程,<br>-rw=randread I/O类型为随机读,使用psync(则使用pread函数)引擎,<br>-bs=4k块大小为4k,
  总共读1g,-numjobs=2开启2个线读, <br>-runtime=10运行10s结束,<br>-group_reporting结果把多线程汇总输出<code class="hljs"><br></code>
  二、Linux系统中查看IO命令iostat详解
  iostat -xd 3
  Linux 3.8.13-16.2.1.el6uek.x86_64 (rac01-node01)     05/27/2017     _x86_64_    (40 CPU)
  Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
  sda               0.05     0.75    2.50    0.50    76.59    69.83    48.96     0.00    1.17   0.47   0.14
  scd0              0.00     0.00    0.02    0.00     0.11     0.00     5.25     0.00   21.37  20.94   0.05
  dm-0              0.00     0.00    2.40    1.24    75.88    69.83    40.00     0.01    1.38   0.38   0.14
  dm-1              0.00     0.00    0.02    0.00     0.14     0.00     8.00     0.00    0.65   0.39   0.00
  sdc               0.00     0.00    0.01    0.00     0.11     0.00    10.20     0.00    0.28   0.28   0.00
  sdb               0.00     0.00    0.01    0.00     0.11     0.00    10.20     0.00    0.15   0.15   0.00
  sdd               0.00     0.00    0.01    0.00     0.11     0.00    10.20     0.00    0.25   0.25   0.00
  sde               0.00     0.00    0.01    0.00     0.11     0.00    10.20     0.00    0.14   0.14   0.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%,因为磁盘的并发能力,所以磁盘使用未必就到了瓶颈)。

      本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号