fio
可以模拟多种负载场景(随机/顺序读写、多线程等):
安装:
sudo apt install fio # Debian/Ubuntu
顺序读写测试:
fio --name=seqread --rw=read --direct=1 --bs=1M --size=1G --numjobs=1 --runtime=60 --group_reporting
fio --name=seqwrite --rw=write --direct=1 --bs=1M --size=1G --numjobs=1 --runtime=60 --group_reporting
-
--direct=1
:绕过缓存。 -
--bs
:块大小(模拟实际场景)。 -
--size
:测试文件大小。 -
--numjobs
:并发任务数。
随机读写测试:
fio --name=randread --rw=randread --direct=1 --bs=4k --size=1G --numjobs=1 --runtime=60 --group_reporting
fio --name=randwrite --rw=randwrite --direct=1 --bs=4k --size=1G --numjobs=1 --runtime=60 --group_reporting
-
--direct=1
:绕过缓存。 -
--bs
:块大小(模拟实际场景)。 -
--size
:测试文件大小。 -
--numjobs
:并发任务数。
固态硬盘测试
顺序读写测试
1. 顺序读取测试(seqread)
leonjin@leonjin-ROG-STRIX-G35CA-G35CA:~/project/tmp$ fio --name=seqread --rw=read --direct=1 --bs=1M --size=1G --numjobs=1 --runtime=60 --group_reporting
seqread: (g=0): rw=read, bs=(R) 1024KiB-1024KiB, (W) 1024KiB-1024KiB, (T) 1024KiB-1024KiB, ioengine=psync, iodepth=1
fio-3.1
Starting 1 process
seqread: Laying out IO file (1 file / 1024MiB)
seqread: (groupid=0, jobs=1): err= 0: pid=12045: Fri Jun 20 16:12:17 2025
read: IOPS=3413, BW=3413MiB/s (3579MB/s)(1024MiB/300msec)
clat (usec): min=240, max=833, avg=291.91, stdev=40.92
lat (usec): min=240, max=834, avg=291.95, stdev=40.96
clat percentiles (usec):
| 1.00th=[ 243], 5.00th=[ 249], 10.00th=[ 251], 20.00th=[ 262],
| 30.00th=[ 265], 40.00th=[ 269], 50.00th=[ 273], 60.00th=[ 297],
| 70.00th=[ 318], 80.00th=[ 334], 90.00th=[ 338], 95.00th=[ 355],
| 99.00th=[ 379], 99.50th=[ 424], 99.90th=[ 445], 99.95th=[ 832],
| 99.99th=[ 832]
lat (usec) : 250=6.74%, 500=93.16%, 1000=0.10%
cpu : usr=0.67%, sys=14.05%, ctx=1025, majf=0, minf=266
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 rwt: total=1024,0,0, short=0,0,0, dropped=0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
READ: bw=3413MiB/s (3579MB/s), 3413MiB/s-3413MiB/s (3579MB/s-3579MB/s), io=1024MiB (1074MB), run=300-300msec
Disk stats (read/write):
nvme0n1: ios=2697/0, merge=0/0, ticks=614/0, in_queue=0, util=72.83%
关键指标
-
IOPS:
3413
(每秒 3413 次 1MB 读取操作)。 -
带宽 (BW):
3413MiB/s (3579MB/s)
,约 3.5GB/s,符合高端 NVMe SSD 性能。 -
延迟 (clat):
-
平均
291.91µs
,99% 请求在379µs
内完成。 -
延迟分布:93% 请求在
500µs
内,极少数(0.1%)达到833µs
。
-
-
磁盘利用率:
util=72.83%
,未完全饱和。
结论
顺序读取性能极佳,可能是 PCIe 3.0/4.0 NVMe SSD(如三星 970 EVO Plus 或西数 SN750)。
2. 顺序写入测试(seqwrite)
leonjin@leonjin-ROG-STRIX-G35CA-G35CA:~/project/tmp$ fio --name=seqwrite --rw=write --direct=1 --bs=1M --size=1G --numjobs=1 --runtime=60 --group_reporting
seqwrite: (g=0): rw=write, bs=(R) 1024KiB-1024KiB, (W) 1024KiB-1024KiB, (T) 1024KiB-1024KiB, ioengine=psync, iodepth=1
fio-3.1
Starting 1 process
seqwrite: Laying out IO file (1 file / 1024MiB)
seqwrite: (groupid=0, jobs=1): err= 0: pid=12082: Fri Jun 20 16:12:46 2025
write: IOPS=2039, BW=2040MiB/s (2139MB/s)(1024MiB/502msec)
clat (usec): min=231, max=8759, avg=424.72, stdev=286.78
lat (usec): min=253, max=8789, avg=488.98, stdev=285.01
clat percentiles (usec):
| 1.00th=[ 265], 5.00th=[ 293], 10.00th=[ 297], 20.00th=[ 318],
| 30.00th=[ 355], 40.00th=[ 375], 50.00th=[ 400], 60.00th=[ 420],
| 70.00th=[ 453], 80.00th=[ 490], 90.00th=[ 545], 95.00th=[ 611],
| 99.00th=[ 799], 99.50th=[ 914], 99.90th=[ 1991], 99.95th=[ 8717],
| 99.99th=[ 8717]
bw ( MiB/s): min= 2044, max= 2044, per=100.00%, avg=2044.00, stdev= 0.00, samples=1
iops : min= 2044, max= 2044, avg=2044.00, stdev= 0.00, samples=1
lat (usec) : 250=0.78%, 500=81.25%, 750=16.50%, 1000=1.07%
lat (msec) : 2=0.29%, 10=0.10%
cpu : usr=13.57%, sys=12.77%, ctx=1025, 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 rwt: total=0,1024,0, short=0,0,0, dropped=0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
WRITE: bw=2040MiB/s (2139MB/s), 2040MiB/s-2040MiB/s (2139MB/s-2139MB/s), io=1024MiB (1074MB), run=502-502msec
Disk stats (read/write):
nvme0n1: ios=0/2454, merge=0/1, ticks=0/800, in_queue=24, util=80.32%
关键指标
-
IOPS:
2039
(每秒 2039 次 1MB 写入操作)。 -
带宽:
2040MiB/s (2139MB/s)
,约 2.1GB/s。 -
延迟:
-
平均
424.72µs
,99% 请求在799µs
内完成。 -
存在少数高延迟(最高
8.8ms
,可能是写入缓存或垃圾回收导致)。
-
-
磁盘利用率:
util=80.32%
,接近满载。
结论
写入速度约为读取的 60%,但仍属高端 SSD 水平,延迟略高是正常现象。
随机读写测试
1. 随机读取测试(randread,4KB 块)
leonjin@leonjin-ROG-STRIX-G35CA-G35CA:~/project/tmp$ fio --name=randread --rw=randread --direct=1 --bs=4k --size=1G --numjobs=1 --runtime=60 --group_reporting
randread: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=psync, iodepth=1
fio-3.1
Starting 1 process
randread: Laying out IO file (1 file / 1024MiB)
Jobs: 1 (f=1): [r(1)][100.0%][r=63.4MiB/s,w=0KiB/s][r=16.2k,w=0 IOPS][eta 00m:00s]
randread: (groupid=0, jobs=1): err= 0: pid=12158: Fri Jun 20 16:15:27 2025
read: IOPS=15.7k, BW=61.3MiB/s (64.2MB/s)(1024MiB/16714msec)
clat (usec): min=8, max=825, avg=63.36, stdev= 9.22
lat (usec): min=8, max=825, avg=63.40, stdev= 9.23
clat percentiles (usec):
| 1.00th=[ 47], 5.00th=[ 57], 10.00th=[ 58], 20.00th=[ 59],
| 30.00th=[ 59], 40.00th=[ 59], 50.00th=[ 60], 60.00th=[ 64],
| 70.00th=[ 70], 80.00th=[ 72], 90.00th=[ 72], 95.00th=[ 77],
| 99.00th=[ 80], 99.50th=[ 80], 99.90th=[ 93], 99.95th=[ 111],
| 99.99th=[ 182]
bw ( KiB/s): min=58312, max=67648, per=99.83%, avg=62631.45, stdev=2175.66, samples=33
iops : min=14578, max=16912, avg=15657.85, stdev=543.92, samples=33
lat (usec) : 10=0.01%, 20=0.70%, 50=0.84%, 100=98.39%, 250=0.06%
lat (usec) : 500=0.01%, 750=0.01%, 1000=0.01%
cpu : usr=0.95%, sys=4.58%, ctx=262146, majf=0, minf=9
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 rwt: total=262144,0,0, short=0,0,0, dropped=0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
READ: bw=61.3MiB/s (64.2MB/s), 61.3MiB/s-61.3MiB/s (64.2MB/s-64.2MB/s), io=1024MiB (1074MB), run=16714-16714msec
Disk stats (read/write):
nvme0n1: ios=258385/10, merge=0/14, ticks=15798/40, in_queue=32, util=99.48%
关键指标
-
IOPS:
15.7k
(每秒 15,700 次 4KB 随机读取)。 -
带宽:
61.3MiB/s (64.2MB/s)
,因块大小较小,带宽较低。 -
延迟:
-
平均
63.36µs
,99% 请求在80µs
内完成(极低)。
-
-
磁盘利用率:
util=99.48%
,完全饱和。
结论
随机读取性能优秀,适合高并发小文件场景(如数据库)。
对比顺序读取,随机读带宽下降是正常现象(因寻址开销)。
2. 随机写入测试(randwrite,4KB 块)
leonjin@leonjin-ROG-STRIX-G35CA-G35CA:~/project/tmp$ fio --name=randwrite --rw=randwrite --direct=1 --bs=4k --size=1G --numjobs=1 --runtime=60 --group_reporting
randwrite: (g=0): rw=randwrite, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=psync, iodepth=1
fio-3.1
Starting 1 process
randwrite: Laying out IO file (1 file / 1024MiB)
Jobs: 1 (f=1): [w(1)][100.0%][r=0KiB/s,w=225MiB/s][r=0,w=57.7k IOPS][eta 00m:00s]
randwrite: (groupid=0, jobs=1): err= 0: pid=12230: Fri Jun 20 16:15:44 2025
write: IOPS=58.4k, BW=228MiB/s (239MB/s)(1024MiB/4485msec)
clat (usec): min=11, max=23150, avg=16.65, stdev=57.22
lat (usec): min=11, max=23150, avg=16.72, stdev=57.22
clat percentiles (nsec):
| 1.00th=[12096], 5.00th=[12992], 10.00th=[15040], 20.00th=[15808],
| 30.00th=[16320], 40.00th=[16512], 50.00th=[16768], 60.00th=[16768],
| 70.00th=[17024], 80.00th=[17024], 90.00th=[17280], 95.00th=[17536],
| 99.00th=[23424], 99.50th=[27520], 99.90th=[35584], 99.95th=[41728],
| 99.99th=[74240]
bw ( KiB/s): min=217216, max=262624, per=99.34%, avg=232245.00, stdev=13169.03, samples=8
iops : min=54304, max=65656, avg=58061.25, stdev=3292.26, samples=8
lat (usec) : 20=98.66%, 50=1.32%, 100=0.01%, 250=0.01%, 500=0.01%
lat (usec) : 750=0.01%
lat (msec) : 2=0.01%, 4=0.01%, 20=0.01%, 50=0.01%
cpu : usr=5.64%, sys=43.40%, ctx=262152, majf=0, minf=9
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 rwt: total=0,262144,0, short=0,0,0, dropped=0,0,0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
WRITE: bw=228MiB/s (239MB/s), 228MiB/s-228MiB/s (239MB/s-239MB/s), io=1024MiB (1074MB), run=4485-4485msec
Disk stats (read/write):
nvme0n1: ios=0/256525, merge=0/686, ticks=0/2488, in_queue=52, util=97.93%
关键指标
-
IOPS:
58.4k
(每秒 58,400 次 4KB 随机写入)。 -
带宽:
228MiB/s (239MB/s)
。 -
延迟:
-
平均
16.65µs
,99% 请求在23.4µs
内完成(极低)。 -
存在少数异常高延迟(最高
23ms
,可能是写入放大或后台操作)。
-
-
磁盘利用率:
util=97.93%
,完全饱和。
结论
随机写入性能极强(IOPS 高达 58k),远超普通 SSD(通常 10k-30k),可能是 高端 NVMe SSD(如三星 980 Pro) 或启用了 SLC 缓存。