如何在Linux中使用Fio测量磁盘性能

时间:2020-03-05 15:28:55  来源:igfitidea点击:

Fio是一个免费的开源工具,可用于基准测试和硬件验证。
它支持许多I/O引擎,包括libaio,sync,nmap,syslet,网络,slice等。
它还支持Linux,OpenBSD,OpenSolaris,HP-UX,Android和Windows等许多发行版,可以在文件和块设备上使用。

在本教程中,我们将学习如何在Linux中安装Fio,还将通过一些示例来学习如何使用Fio。

安装Fio

其中我们将在所有主要的Linux发行版中安装Fio,例如CentOS 7,Ubuntu 16.04和Debian 9.

在Ubuntu 16.04上安装Fio

默认情况下,Fio在Ubuntu默认存储库中可用,因此我们可以通过运行以下命令轻松安装它:

sudo apt-get install fio -y

在CentOS 7上安装Fio

默认情况下,Fio在CentOS默认存储库中不可用。
因此,我们需要将EPEL存储库安装到系统中。
我们可以通过运行以下命令来安装它:

sudo yum install epel-release -y

一旦安装了EPEL存储库,就可以通过运行以下命令来安装Fio:

sudo yum install fio -y

在Debian 9上安装Fio

默认情况下,Fio在Debian存储库中可用,我们可以通过运行以下命令来安装它:

sudo apt-get install fio -y

与Fio合作

现在,Fio已安装在系统上。
现在该看看如何将Fio与示例一起使用。

示例1:随机写测试

让我们从运行以下命令开始。
此命令将写入总共2GB的文件[4个作业x 512 MB = 2GB]一次运行4个进程:

sudo fio --name=randwrite --ioengine=libaio --iodepth=1 --rw=randwrite --bs=4k --direct=0 --size=512M --numjobs=4 --runtime=240 --group_reporting

我们应该看到以下输出:

randwrite: (g=0): rw=randwrite, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=1
fio-2.1.3
Starting 4 processes
randwrite: Laying out IO file(s) (1 file(s)/512MB)
randwrite: Laying out IO file(s) (1 file(s)/512MB)
randwrite: Laying out IO file(s) (1 file(s)/512MB)
randwrite: Laying out IO file(s) (1 file(s)/512MB)
Jobs: 1 (f=1): [__w_] [-.-% done] [0KB/27032KB/0KB /s] [0/6758/0 iops] [eta 00m:00s] 
randwrite: (groupid=0, jobs=4): err= 0: pid=28810: Tue May 25 20:28:20 2016
  write: io=2048.0MB, bw=297722KB/s, iops=74430, runt=  7044msec
    slat (usec): min=9, max=47469, avg=38.13, stdev=488.37
    clat (usec): min=1, max=10595, avg= 2.26, stdev=30.99
     lat (usec): min=11, max=47478, avg=40.74, stdev=489.66
    clat percentiles (usec):
     |  1.00th=[    1],  5.00th=[    2], 10.00th=[    2], 20.00th=[    2],
     | 30.00th=[    2], 40.00th=[    2], 50.00th=[    2], 60.00th=[    2],
     | 70.00th=[    2], 80.00th=[    2], 90.00th=[    2], 95.00th=[    2],
     | 99.00th=[    3], 99.50th=[    4], 99.90th=[   16], 99.95th=[   61],
     | 99.99th=[  454]
    bw (KB  /s): min=10626, max=244432, per=32.42%, avg=96530.07, stdev=85594.86
    lat (usec) : 2=4.28%, 4=95.15%, 10=0.44%, 20=0.03%, 50=0.03%
    lat (usec) : 100=0.04%, 250=0.01%, 500=0.01%, 750=0.01%, 1000=0.01%
    lat (msec) : 2=0.01%, 4=0.01%, 10=0.01%, 20=0.01%
  cpu          : usr=11.91%, sys=27.58%, ctx=4646, majf=0, minf=104
  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=524288/d=0, short=r=0/w=0/d=0
Run status group 0 (all jobs):
  WRITE: io=2048.0MB, aggrb=297721KB/s, minb=297721KB/s, maxb=297721KB/s, mint=7044msec, maxt=7044msec
Disk stats (read/write):
  sda: ios=129/2495, merge=0/1599, ticks=11520/91476, in_queue=143340, util=78.35%

示例2:随机读取测试

以下命令将读取总共2GB的文件,一次运行4个进程。

sudo fio --name=randread --ioengine=libaio --iodepth=16 --rw=randread --bs=4k --direct=0 --size=512M --numjobs=4 --runtime=240 --group_reporting

我们应该看到以下结果:

randread: (g=0): rw=randread, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=16
...
randread: (g=0): rw=randread, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=16
fio-2.1.3
Starting 4 processes
randread: Laying out IO file(s) (1 file(s)/512MB)
randread: Laying out IO file(s) (1 file(s)/512MB)
randread: Laying out IO file(s) (1 file(s)/512MB)
randread: Laying out IO file(s) (1 file(s)/512MB)
Jobs: 4 (f=4): [rrrr] [100.0% done] [467KB/0KB/0KB /s] [116/0/0 iops] [eta 00m:00s]
randread: (groupid=0, jobs=4): err= 0: pid=14521: Tue May 25 22:01:24 2016
  read : io=117912KB, bw=503032B/s, iops=122, runt=240028msec
    slat (usec): min=93, max=1178.5K, avg=32554.59, stdev=45398.62
    clat (usec): min=12, max=2611.2K, avg=487669.64, stdev=288615.07
     lat (msec): min=49, max=2667, avg=520.23, stdev=303.69
    clat percentiles (msec):
     |  1.00th=[  167],  5.00th=[  217], 10.00th=[  247], 20.00th=[  289],
     | 30.00th=[  330], 40.00th=[  367], 50.00th=[  404], 60.00th=[  445],
     | 70.00th=[  502], 80.00th=[  603], 90.00th=[  898], 95.00th=[ 1057],
     | 99.00th=[ 1614], 99.50th=[ 1811], 99.90th=[ 2245], 99.95th=[ 2376],
     | 99.99th=[ 2573]
    bw (KB  /s): min=    4, max=  318, per=25.59%, avg=125.65, stdev=59.18
    lat (usec) : 20=0.01%
    lat (msec) : 50=0.01%, 100=0.02%, 250=10.45%, 500=59.10%, 750=15.73%
    lat (msec) : 1000=8.21%, 2000=6.23%, >=2000=0.25%
  cpu          : usr=0.05%, sys=0.17%, ctx=29816, majf=0, minf=165
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=99.8%, 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    : total=r=29478/w=0/d=0, short=r=0/w=0/d=0
Run status group 0 (all jobs):
   READ: io=117912KB, aggrb=491KB/s, minb=491KB/s, maxb=491KB/s, mint=240028msec, maxt=240028msec
Disk stats (read/write):
  sda: ios=29552/2717, merge=0/2735, ticks=969368/97672, in_queue=1067872, util=100.00%

示例3:读写性能测试

以下命令将测量USB随身碟(/dev/sdc1)的随机读取/写入性能:

sudo fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read_write.fio --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75

我们应该看到以下测试结果:

test: (g=0): rw=randrw, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=64
fio-2.1.3
Starting 1 process
Jobs: 1 (f=1): [m] [98.0% done] [191KB/95KB/0KB /s] [47/23/0 iops] [eta 00m:03s]
test: (groupid=0, jobs=1): err= 0: pid=24800: Tue May 25 22:10:38 2016
  read : io=15512KB, bw=107237B/s, iops=26, runt=148123msec
  write: io=4968.0KB, bw=34344B/s, iops=8, runt=148123msec
  cpu          : usr=0.08%, sys=0.18%, ctx=5080, majf=0, minf=24
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.2%, 16=0.3%, 32=0.6%, >=64=98.8%
     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.1%, >=64=0.0%
     issued    : total=r=3878/w=1242/d=0, short=r=0/w=0/d=0
Run status group 0 (all jobs):
   READ: io=15512KB, aggrb=104KB/s, minb=104KB/s, maxb=104KB/s, mint=148123msec, maxt=148123msec
  WRITE: io=4968KB, aggrb=33KB/s, minb=33KB/s, maxb=33KB/s, mint=148123msec, maxt=148123msec
Disk stats (read/write):
  sdc: ios=3506/1203, merge=372/28, ticks=7386380/1400600, in_queue=8796700, util=100.00%

上面的命令将在USB随身碟中写入20MB数据,并针对每个写入比率(rwmixread = 75)使用3次读取执行4KB读取和写入。

Fio是一个非常有用的工具,可以提供有关磁盘速度和延迟状态的信息。
现在,我们可以使用Fio轻松测试磁盘的性能。