fio 测试硬盘 IO 性能
计算学徒
编辑于 2024年05月03日 09:50
收录于文集
共91篇

代码块
JavaScript
自动换行
复制代码
# 安装 fio
$ sudo apt install fio

# 进入测试目录(临时目录)
$ cd /tmp

# 顺序读性能测试
sudo fio --rw=read --name=seq_read --size=1G --bs=1M --direct=1

# 顺序写性能
sudo fio --rw=write --name=seq_write --size=1G --bs=1M --direct=1

# 随机 4k 读性能
sudo fio --rw=randread --name=rand_read --size=1G --bs=4k --direct=1

# 随机 4k 写性能
sudo fio --rw=randwrite --name=rand_write --size=1G --bs=4k --direct=1
复制成功

解释一下命令中的参数含义:

--rw: IO 操作类型, 常用的参数值有 read(顺序读)、write(顺序写)、randread(随机读)、randwrite(随机写)等;

--name: 测试名称。测试过程中会在测试目录中生成一个相同名称的临时数据文件,测试完后需要手动删除;

--size: IO 操作的数据量(也是临时数据文件的大小);

--bs: IO 操作的块大小(block size);

--direct: 值为 1 时表示禁用 IO 缓存;

当然还有其他可以使用的参数,例如:

--ioengine: IO 操作引擎。默认值为 psync,常用值 libaio;

--iodepth: IO 队列深度。默认值为1,常用值 64;

fio 命令还有非常多的参数,进一步的了解请参考官方文档:https://fio.readthedocs.io/en/latest/index.html

fio 命令运行完之后会输出详细的测试结果,例如:

代码块
Shell
自动换行
复制代码
rand_write: (g=0): rw=randwrite, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=psync, iodepth=1
fio-3.28
Starting 1 process
rand_write: Laying out IO file (1 file / 1024MiB)
Jobs: 1 (f=1): [w(1)][100.0%][w=222MiB/s][w=56.9k IOPS][eta 00m:00s]
rand_write: (groupid=0, jobs=1): err= 0: pid=390184: Wed Apr 24 14:49:57 2024
  write: IOPS=55.7k, BW=218MiB/s (228MB/s)(1024MiB/4703msec); 0 zone resets
    clat (usec): min=14, max=7988, avg=17.46, stdev=16.00
     lat (usec): min=14, max=7989, avg=17.52, stdev=16.01
    clat percentiles (nsec):
     |  1.00th=[15808],  5.00th=[16320], 10.00th=[16512], 20.00th=[16768],
     | 30.00th=[16768], 40.00th=[16768], 50.00th=[17024], 60.00th=[17280],
     | 70.00th=[17280], 80.00th=[17536], 90.00th=[17792], 95.00th=[18304],
     | 99.00th=[31360], 99.50th=[35584], 99.90th=[41216], 99.95th=[45312],
     | 99.99th=[63232]
   bw (  KiB/s): min=214472, max=229400, per=99.93%, avg=222805.33, stdev=5395.91, samples=9
   iops        : min=53618, max=57350, avg=55701.33, stdev=1348.98, samples=9
  lat (usec)   : 20=97.01%, 50=2.97%, 100=0.02%, 250=0.01%, 750=0.01%
  lat (msec)   : 2=0.01%, 10=0.01%
  cpu          : usr=4.27%, sys=51.02%, ctx=262150, majf=0, minf=12
  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=0,262144,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):
  WRITE: bw=218MiB/s (228MB/s), 218MiB/s-218MiB/s (228MB/s-228MB/s), io=1024MiB (1074MB), run=4703-4703msec

Disk stats (read/write):
  nvme0n1: ios=0/258460, merge=0/710, ticks=0/2150, in_queue=2151, util=98.08%
复制成功

比较重要的内容是关于 IOPS 和 BW 指标的测试结果:

代码块
Shell
自动换行
复制代码
IOPS=55.7k, BW=218MiB/s
复制成功

(完)