














对于 7200 转机械硬盘的随机 4 KB 读为例:
理论最小平均延迟 ≈ 8 + 4.17 + 0.03 = 12.2 ms,以上从理论上计算出来磁盘IO延迟的时间,以7200转的机械磁盘为例,大概在12毫秒左右,这么算出来最大随机IOPS大概在100左右。
以上因素决定了最小的IO延迟事件,但是IO延迟时间同时也收到其他因素的影响,磁盘队列深度或者长度就是一个非常关键的因素。
机械磁盘(单个盘面下)读写数据靠磁头的移动实现,也即无法真正的并行执行多个读写请求,队列深度超过2之后,IO的请求就需要排队来执行,因此延迟会明显增大。
结论先行:对于HDD盘,IO延迟只是一个结果,并不是原因,导致IO延迟的根本因素是IO队列的深度,机械磁盘每次只能处理一个IO请求,如果队列过深,IO延迟会指数级增加
HDD 的特性:不怕忙,怕排队,意味着IO延迟将随着队列深度的增加而剧烈增加。这里分别用1,4,8,16,32队列深度做队列深度和IO延迟的性能测试
.\diskspd.exe -o1 -b4k -r -w30 -d120 -Sh -D -L -c10G C:\targetfile\IO.dat
.\diskspd.exe -o4 -b4k -r -w30 -d120 -Sh -D -L -c10G C:\targetfile\IO.dat
.\diskspd.exe -o8 -b4k -r -w30 -d120 -Sh -D -L -c10G C:\targetfile\IO.dat
.\diskspd.exe -o16 -b4k -r -w30 -d120 -Sh -D -L -c10G C:\targetfile\IO.dat
.\diskspd.exe -o32 -b4k -r -w30 -d120 -Sh -D -L -c10G C:\targetfile\IO.dat

从上图可以发现,紫色折线为队列深度,红色为IO读延迟(类似于指数级增加),有着非常明显的规律:
1,在队列深入为1的时候,IO延迟,基本上符合理论上计算出来的结果12毫秒左右
2,在队列深入为4的时候,IO延迟明显增加,超过了25毫秒
3,在队列深度为8的时候,IO延迟明显增加,超过了50毫秒
4,在队列深度为16的时候,IO延迟明显增加,短暂报表,会接近或者超过100毫秒(压测后半程队列深度突然下降,不解?)
5,在队列深度为32的时候,IO延迟明显增加,持续报表,会接近或者超过200毫秒(压测后半程队列深度突然下降,不解?)
6,单纯的看IOPS没有意义,IOPS可以随着队列深度的增加而增加(但是也有上限),但是随着队列深度的增加,IO延迟也会剧增。
如下是一个7500转HDD,在遇到某些负载的时候的延迟情况,可达数十万毫秒,某些情况下更高(大表,多个非聚集索引的重索引场景,批量删除操作,即便是SSD,队列也能干爆,只是HDD问题更为明显)

也就是说IO延迟只是一个结果,并不是原因,导致IO延迟的根本因素是IO队列的深度,机械磁盘每次只能处理一个IO请求,如果队列过深,IO延迟会成比例增加
prometheus监控信息,由于Prometheus是30秒收集一次统计信息,而perfmon是每秒一次,这个图看起来比较粗略,但与Windows的perfmon得到的结果基本上一致:
IO Utilization,
Average queue size,
Time Spent doing I/Os
这几个指标,其实是一个指标的不同表现形式,实际上都类似于队列深度

如果是做数据库,测试其IOPS的时候,队列深度最好设置为1,因为增加队列深度,也即增加-o参数的值,最终的IOPS测试结果可能会得到增加,但在大部分请求伴随着高延迟的代价下得到的结果,这样子是没有实际意义的。
其实不难理解,就好比955工作模式轻松挣1W,跟每天007工作模式,累得生不如死挣1.2W,后者多2K块钱是没有意义的,这是一个道理。
如下是7500转HDD盘队列深度为1,随机读写各半的测试结果,其IOPS数值为148左右。
D:\Tools\DiskSpd\amd64>.\diskspd.exe -o1 -b4k -r -w50 -d300 -Sh -D -L -c10G c:\targetfile\IO.dat
Command Line: .\diskspd.exe -o1 -b4k -r -w50 -d300 -Sh -D -L -c10G c:\targetfile\IO.dat
Input parameters:
timespan: 1
-------------
duration: 300s
warm up time: 5s
cool down time: 0s
measuring latency
gathering IOPS at intervals of 1000ms
random seed: 0
path: 'c:\targetfile\IO.dat'
think time: 0ms
burst size: 0
software cache disabled
hardware write cache disabled, writethrough on
performing mix test (read/write ratio: 50/50)
block size: 4KiB
using random I/O (alignment: 4KiB)
number of outstanding I/O operations per thread: 1
threads per file: 1
IO priority: normal
System information:
computer name: ******
start time: 2026/05/15 01:10:56 UTC
Results for timespan 1:
*******************************************************************************
actual test time: 300.02s
thread count: 1
proc count: 4
CPU | Usage | User | Kernel | Idle
-------------------------------------------
0| 4.02%| 1.45%| 2.57%| 95.98%
1| 4.55%| 2.69%| 1.86%| 95.45%
2| 6.46%| 4.30%| 2.17%| 93.54%
3| 9.48%| 7.58%| 1.90%| 90.52%
-------------------------------------------
avg.| 6.13%| 4.00%| 2.12%| 93.87%
Total IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 182816768 | 44633 | 0.58 | 148.77 | 6.720 | 36.66 | 24.647 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 182816768 | 44633 | 0.58 | 148.77 | 6.720 | 36.66 | 24.647
Read IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 91561984 | 22354 | 0.29 | 74.51 | 11.458 | 18.56 | 25.687 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 91561984 | 22354 | 0.29 | 74.51 | 11.458 | 18.56 | 25.687
Write IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 91254784 | 22279 | 0.29 | 74.26 | 1.967 | 19.95 | 22.579 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 91254784 | 22279 | 0.29 | 74.26 | 1.967 | 19.95 | 22.579
total:
%-ile | Read (ms) | Write (ms) | Total (ms)
----------------------------------------------
min | 0.231 | 0.184 | 0.184
25th | 5.861 | 0.348 | 0.384
50th | 8.620 | 0.384 | 3.014
75th | 11.932 | 0.651 | 8.706
90th | 18.151 | 1.081 | 14.315
95th | 20.455 | 2.152 | 18.381
99th | 33.069 | 4.512 | 28.535
3-nines | 455.087 | 428.028 | 439.342
4-nines | 512.954 | 488.276 | 496.637
5-nines | 520.943 | 522.605 | 522.605
6-nines | 520.943 | 522.605 | 522.605
7-nines | 520.943 | 522.605 | 522.605
8-nines | 520.943 | 522.605 | 522.605
9-nines | 520.943 | 522.605 | 522.605
max | 520.943 | 522.605 | 522.605
D:\Tools\DiskSpd\amd64>
如下是一个RAID5的HDD阵列的IOPS结果,随机读写各半的测试,其结果在350左右
E:\DiskSpd\amd64>.\diskspd.exe -o1 -b4k -r -w50 -d120 -Sh -D -L -c10G e:\targetfile\IO.dat
Command Line: .\diskspd.exe -o1 -b4k -r -w50 -d120 -Sh -D -L -c10G e:\targetfile\IO.dat
Input parameters:
timespan: 1
-------------
duration: 120s
warm up time: 5s
cool down time: 0s
measuring latency
gathering IOPS at intervals of 1000ms
random seed: 0
path: 'e:\targetfile\IO.dat'
think time: 0ms
burst size: 0
software cache disabled
hardware write cache disabled, writethrough on
performing mix test (read/write ratio: 50/50)
block size: 4KiB
using random I/O (alignment: 4KiB)
number of outstanding I/O operations per thread: 1
threads per file: 1
IO priority: normal
System information:
computer name: LTGNSQADB02
start time: 2026/05/20 09:22:53 UTC
Results for timespan 1:
*******************************************************************************
actual test time: 120.00s
thread count: 1
proc count: 8
CPU | Usage | User | Kernel | Idle
-------------------------------------------
0| 7.38%| 1.88%| 5.51%| 92.62%
1| 8.68%| 2.19%| 6.50%| 91.32%
2| 4.65%| 2.24%| 2.41%| 95.35%
3| 4.30%| 1.82%| 2.47%| 95.70%
4| 15.22%| 5.43%| 9.79%| 84.78%
5| 22.94%| 8.49%| 14.45%| 77.06%
6| 13.45%| 3.93%| 9.52%| 86.55%
7| 13.26%| 6.16%| 7.10%| 86.74%
-------------------------------------------
avg.| 11.24%| 4.02%| 7.22%| 88.76%
Total IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 172396544 | 42089 | 1.37 | 350.74 | 2.849 | 41.20 | 4.100 | e:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 172396544 | 42089 | 1.37 | 350.74 | 2.849 | 41.20 | 4.100
Read IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 86278144 | 21064 | 0.69 | 175.53 | 5.528 | 19.22 | 4.381 | e:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 86278144 | 21064 | 0.69 | 175.53 | 5.528 | 19.22 | 4.381
Write IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 86118400 | 21025 | 0.68 | 175.21 | 0.166 | 25.18 | 0.175 | e:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 86118400 | 21025 | 0.68 | 175.21 | 0.166 | 25.18 | 0.175
total:
%-ile | Read (ms) | Write (ms) | Total (ms)
----------------------------------------------
min | 0.111 | 0.095 | 0.095
25th | 3.023 | 0.126 | 0.147
50th | 4.762 | 0.147 | 0.425
75th | 6.461 | 0.166 | 4.767
90th | 9.905 | 0.201 | 6.827
95th | 12.456 | 0.240 | 9.914
99th | 24.725 | 0.867 | 17.671
3-nines | 43.383 | 1.390 | 37.767
4-nines | 56.941 | 4.524 | 56.284
5-nines | 60.794 | 16.828 | 60.794
6-nines | 60.794 | 16.828 | 60.794
7-nines | 60.794 | 16.828 | 60.794
8-nines | 60.794 | 16.828 | 60.794
9-nines | 60.794 | 16.828 | 60.794
max | 60.794 | 16.828 | 60.794
E:\DiskSpd\amd64>
如下是一个SATA类型的SSD的测试结果,队列深度为1的,读写对半的情况下IOPS大概在12000,可以说相对HDD盘来说,是一个飞跃的提升了
D:\Tools\DiskSpd\amd64>.\diskspd.exe -o1 -b4k -r -w50 -d120 -Sh -D -L -c10G c:\targetfile\IO.dat
WARNING: Error adjusting token privileges for SeManageVolumePrivilege (error code: 1300)
WARNING: Could not set privileges for setting valid file size; will use a slower method of preparing the file
Command Line: .\diskspd.exe -o1 -b4k -r -w50 -d120 -Sh -D -L -c10G c:\targetfile\IO.dat
Input parameters:
timespan: 1
-------------
duration: 120s
warm up time: 5s
cool down time: 0s
measuring latency
gathering IOPS at intervals of 1000ms
random seed: 0
path: 'c:\targetfile\IO.dat'
think time: 0ms
burst size: 0
software cache disabled
hardware write cache disabled, writethrough on
performing mix test (read/write ratio: 50/50)
block size: 4KiB
using random I/O (alignment: 4KiB)
number of outstanding I/O operations per thread: 1
threads per file: 1
IO priority: normal
System information:
computer name: GoldenQADBSrv01
start time: 2026/05/20 05:41:25 UTC
Results for timespan 1:
*******************************************************************************
actual test time: 120.00s
thread count: 1
proc count: 8
CPU | Usage | User | Kernel | Idle
-------------------------------------------
0| 33.76%| 2.62%| 31.15%| 66.24%
1| 7.66%| 4.54%| 3.11%| 92.34%
2| 10.31%| 7.72%| 2.59%| 89.69%
3| 11.45%| 10.00%| 1.45%| 88.55%
4| 21.54%| 18.75%| 2.79%| 78.46%
5| 4.36%| 3.84%| 0.52%| 95.64%
6| 11.11%| 8.36%| 2.75%| 88.89%
7| 10.20%| 8.36%| 1.84%| 89.80%
-------------------------------------------
avg.| 13.80%| 8.02%| 5.77%| 86.20%
Total IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 6010601472 | 1467432 | 47.77 | 12228.56 | 0.080 | 1780.33 | 0.214 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 6010601472 | 1467432 | 47.77 | 12228.56 | 0.080 | 1780.33 | 0.214
Read IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 3004678144 | 733564 | 23.88 | 6113.01 | 0.111 | 891.56 | 0.143 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 3004678144 | 733564 | 23.88 | 6113.01 | 0.111 | 891.56 | 0.143
Write IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 3005923328 | 733868 | 23.89 | 6115.55 | 0.049 | 891.98 | 0.264 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 3005923328 | 733868 | 23.89 | 6115.55 | 0.049 | 891.98 | 0.264
total:
%-ile | Read (ms) | Write (ms) | Total (ms)
----------------------------------------------
min | 0.049 | 0.036 | 0.036
25th | 0.088 | 0.040 | 0.043
50th | 0.101 | 0.043 | 0.083
75th | 0.107 | 0.045 | 0.101
90th | 0.117 | 0.050 | 0.108
95th | 0.152 | 0.056 | 0.118
99th | 0.383 | 0.075 | 0.254
3-nines | 2.471 | 2.421 | 2.449
4-nines | 4.105 | 4.047 | 4.067
5-nines | 10.860 | 5.427 | 7.009
6-nines | 34.518 | 201.040 | 34.518
7-nines | 34.518 | 201.040 | 201.040
8-nines | 34.518 | 201.040 | 201.040
9-nines | 34.518 | 201.040 | 201.040
max | 34.518 | 201.040 | 201.040
D:\Tools\DiskSpd\amd64>
如下是一个NVME类型的SSD的测试结果,队列深度为1的,读写对半的情况下IOPS大概在16000
D:\install\DiskSpd\amd64>.\diskspd.exe -o1 -b4k -r -w50 -d120 -Sh -D -L -c10G c:\targetfile\IO.dat
WARNING: Error adjusting token privileges for SeManageVolumePrivilege (error code: 1300)
WARNING: Could not set privileges for setting valid file size; will use a slower method of preparing the file
Command Line: .\diskspd.exe -o1 -b4k -r -w50 -d120 -Sh -D -L -c10G c:\targetfile\IO.dat
Input parameters:
timespan: 1
-------------
duration: 120s
warm up time: 5s
cool down time: 0s
measuring latency
gathering IOPS at intervals of 1000ms
random seed: 0
path: 'c:\targetfile\IO.dat'
think time: 0ms
burst size: 0
software cache disabled
hardware write cache disabled, writethrough on
performing mix test (read/write ratio: 50/50)
block size: 4KiB
using random I/O (alignment: 4KiB)
number of outstanding I/O operations per thread: 1
threads per file: 1
IO priority: normal
System information:
computer name: ywang
start time: 2026/05/20 06:36:44 UTC
Results for timespan 1:
*******************************************************************************
actual test time: 120.01s
thread count: 1
proc count: 28
CPU | Usage | User | Kernel | Idle
-------------------------------------------
0| 17.52%| 2.59%| 14.93%| 82.48%
1| 3.49%| 1.67%| 1.82%| 96.51%
2| 5.52%| 2.69%| 2.83%| 94.48%
3| 0.00%| 0.00%| 0.00%| 100.00%
4| 1.72%| 0.94%| 0.78%| 98.28%
5| 0.00%| 0.00%| 0.00%| 100.00%
6| 0.53%| 0.27%| 0.26%| 99.47%
7| 0.00%| 0.00%| 0.00%| 100.00%
8| 11.55%| 6.15%| 5.40%| 88.45%
9| 4.21%| 2.15%| 2.06%| 95.79%
10| 12.17%| 6.80%| 5.38%| 87.83%
11| 4.06%| 2.59%| 1.47%| 95.94%
12| 0.26%| 0.13%| 0.13%| 99.74%
13| 0.00%| 0.00%| 0.00%| 100.00%
14| 0.99%| 0.61%| 0.38%| 99.01%
15| 2.27%| 1.38%| 0.89%| 97.73%
16| 8.36%| 5.05%| 3.31%| 91.64%
17| 8.15%| 5.08%| 3.07%| 91.85%
18| 3.96%| 1.98%| 1.98%| 96.04%
19| 2.40%| 1.28%| 1.12%| 97.60%
20| 11.25%| 7.37%| 3.88%| 88.75%
21| 3.28%| 1.91%| 1.37%| 96.72%
22| 1.42%| 0.66%| 0.76%| 98.58%
23| 1.19%| 0.43%| 0.76%| 98.81%
24| 6.65%| 3.74%| 2.92%| 93.35%
25| 1.97%| 0.95%| 1.02%| 98.03%
26| 2.80%| 1.64%| 1.16%| 97.20%
27| 5.85%| 3.36%| 2.49%| 94.15%
-------------------------------------------
avg.| 4.34%| 2.19%| 2.15%| 95.66%
Total IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 7903731712 | 1929622 | 62.81 | 16078.88 | 0.062 | 1172.07 | 0.146 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 7903731712 | 1929622 | 62.81 | 16078.88 | 0.062 | 1172.07 | 0.146
Read IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 3949629440 | 964265 | 31.39 | 8034.89 | 0.110 | 597.09 | 0.193 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 3949629440 | 964265 | 31.39 | 8034.89 | 0.110 | 597.09 | 0.193
Write IO
thread | bytes | I/Os | MiB/s | I/O per s | AvgLat | IopsStdDev | LatStdDev | file
------------------------------------------------------------------------------------------------------------------
0 | 3954102272 | 965357 | 31.42 | 8043.99 | 0.014 | 580.11 | 0.022 | c:\targetfile\IO.dat (10GiB)
------------------------------------------------------------------------------------------------------------------
total: 3954102272 | 965357 | 31.42 | 8043.99 | 0.014 | 580.11 | 0.022
total:
%-ile | Read (ms) | Write (ms) | Total (ms)
----------------------------------------------
min | 0.013 | 0.012 | 0.012
25th | 0.052 | 0.013 | 0.013
50th | 0.080 | 0.013 | 0.050
75th | 0.093 | 0.014 | 0.080
90th | 0.119 | 0.015 | 0.096
95th | 0.137 | 0.017 | 0.120
99th | 1.319 | 0.031 | 1.019
3-nines | 1.558 | 0.141 | 1.505
4-nines | 2.606 | 0.863 | 1.988
5-nines | 6.854 | 1.892 | 6.244
6-nines | 9.809 | 9.708 | 9.708
7-nines | 9.809 | 9.708 | 9.809
8-nines | 9.809 | 9.708 | 9.809
9-nines | 9.809 | 9.708 | 9.809
max | 9.809 | 9.708 | 9.809
D:\install\DiskSpd\amd64>
参考这里,是传统的SATA SSD磁盘的IO此时结果(并非相相对先进的NVME SSD),可以看出,在队列深度小于16的情况下,平均响应时间的(或者说是IO延迟时间),并没有非常明显的增加。

此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。