# 延迟（工程）

工程学中的延迟，是指一个动作从发起到其首个可观测效果之间的一段时间延迟，例如从发出请求到收到响应开头之间的时间。在通信或计算系统中，一条消息的总延迟通常可分解为传播时延、传输时延与排队时延<sup>[1](https://www.cse.iitb.ac.in/~sri/cs716/cs716-lec6-2011.pdf)</sup>。延迟如何测量、如何设界，以及如何与其他目标权衡，在网络、服务运营、实时计算和控制工程中各不相同。

| 关键事实 | 细节 |
|---|---|
| 组成 | 延迟 = 传播 + 传输 + 排队<sup>[1](https://www.cse.iitb.ac.in/~sri/cs716/cs716-lec6-2011.pdf)</sup> |
| 标准度量 | RFC 7679 以秒定义 Type-P-One-way-Delay；若数据包未在丢包阈值 Tmax 内到达，该值无定义（非正式地视为无穷大）<sup>[2](https://www.rfc-editor.org/info/rfc7679/)</sup> |
| 不对称性 | 成对单向测量可能显示一个方向 30 ms、反向 120 ms，而往返测量只会报出一个 150 ms 的平均值<sup>[3](https://www.rfc-editor.org/rfc/rfc3432.html)</sup> |
| 尾部与平均值 | 一个平均延迟 100 ms、每秒 1000 次请求的 Web 服务，仍可能有 1% 的请求耗时 5 秒<sup>[4](https://sre.google/sre-book/monitoring-distributed-systems/?hl=hr)</sup> |
| 可达的尾部 | 在四核系统上调优过的 Memcached 在 80% 利用率下达到中位 11 µs、第 99.9 百分位 32 µs；同样利用率下，朴素的单核部署中位为 100 µs、尾部为 5 ms<sup>[5](https://research.google/pubs/tales-of-the-tail-hardware-os-and-application-level-sources-of-tail-latency/)</sup> |
| 实时约束 | 给定截止期 D 与服务时间 S，最大允许中断延迟满足 L_max + S = D<sup>[6](https://live.ocw.mit.edu/courses/6-004-computation-structures-spring-2017/pages/c18/c18s1/)</sup> |
| 控制影响 | 反馈回路中的时延 e^(−sT) 会引入相位滞后，使系统稳定性下降<sup>[7](https://pdf.lib.vntu.edu.ua/books/2021/Dorf_Modern_control_systems_2017_1106.pdf)</sup> |

## 网络延迟及其测量

在分组网络中，延迟或以单向方式测量，或以往返时间（RTT）测量。IETF 的 IP 性能指标（IPPM）框架定义了单向时延指标 Type-P-One-way-Delay：源在线上时刻 T 发出数据包的第一个比特，该指标即目的端收到最后一个比特所经过的 dT，以秒计；若数据包未在丢包阈值等待时间 Tmax 内到达，则时延无定义<sup>[2](https://www.rfc-editor.org/info/rfc7679/)</sup>。单向测量要求两台主机时钟同步，任何同步误差都会直接计入测量误差<sup>[2](https://www.rfc-editor.org/info/rfc7679/)</sup>。

**方向为何重要。** 往返测量完全避开时钟同步问题，实施也容易，但它把两个方向压缩成一个数字。RFC 3432 给出了一个实例：成对单向测量可能显示源到目的方向平均 30 ms、反方向 120 ms，而往返测量只会报出 150 ms 的平均值；若不掌握这种不对称，某个对单向 100 ms 以上延迟敏感的应用所遭遇的问题就可能被漏掉<sup>[3](https://www.rfc-editor.org/rfc/rfc3432.html)</sup>。分析往返测量结果时，必须把非对称路由与排队考虑在内<sup>[3](https://www.rfc-editor.org/rfc/rfc3432.html)</sup>。

高于可达到的最低值的延迟本身即具有诊断意义。路径上的最小单向延迟表示仅由传播与传输造成的延迟，而高于该最小值的数值则表示路径中存在拥塞<sup>[2](https://www.rfc-editor.org/info/rfc7679/)</sup>。中间测量点也可用于定位问题：在观测点两侧分别测量部分路径 RTT，借助 TCP 握手时序与 TCP 时间戳，可以判断异常延迟位于服务器与测量点之间，还是测量点与客户端之间——这是任何一端单独都无法提供的信息<sup>[8](https://www.rfc-editor.org/rfc/rfc8517.html)</sup>。

## 延迟分布与尾部

单一平均值难以描述延迟，因为响应时间构成一条带长尾的分布。Google 的站点可靠性工程（SRE）实践——由本杰明·特雷诺·斯洛斯（Benjamin Treynor Sloss）与迈克·达林（Mike Dahlin）阐述，后者是 Google 的杰出工程师，曾任得克萨斯大学奥斯汀分校计算机科学教授——指出，看似可接受的平均值可能掩盖一长串极大离群值构成的尾部，并建议针对第 95 与第 99 百分位延迟设定目标，而非只看平均值<sup>[9](https://storage.googleapis.com/gweb-research2023-media/pubtools/4392.pdf)</sup>。

差距的幅度可能很大。在 SRE 书的示例中，一个平均延迟 100 ms、每秒 1000 次请求的 Web 服务，仍可能有 1% 的请求耗时 5 秒；当用户的页面依赖若干个这样的后端时，一个后端的第 99 百分位就可能变成前端的中位响应时间<sup>[4](https://sre.google/sre-book/monitoring-distributed-systems/?hl=hr)</sup>。只监控平均值，即使尾部延迟发生显著变化，一整天下来也看不出任何变动<sup>[4](https://sre.google/sre-book/monitoring-distributed-systems/?hl=hr)</sup>。第 99 或第 99.9 这样的高阶百分位显示可信的最坏情况，第 50 百分位（中位数）显示典型情况，而排队效应会在高负载下加剧尾部行为<sup>[10](https://sre.google/sre-book/service-level-objectives/?hl=ko)</sup>。关于用户行为的研究表明，大多数人宁愿使用稍慢但稳定的系统，也不愿使用响应时间大幅波动的系统，这正是某些 SRE 团队只盯高阶百分位的原因<sup>[10](https://sre.google/sre-book/service-level-objectives/?hl=ko)</sup>。

**尾部延迟的成因。** 对高吞吐服务器的研究找出了比排队模型预测更差的尾部延迟的成因，包括后台进程的干扰、糟糕的调度或受限的并发模型造成的请求重排序、次优的中断路由、CPU 节能机制以及 NUMA 效应<sup>[5](https://research.google/pubs/tales-of-the-tail-hardware-os-and-application-level-sources-of-tail-latency/)</sup>。系统性地消除这些因素后，[Memcached](https://www.edgepedia.org/zh/memcached) 在四核、80% 利用率下达到中位 11 µs、第 99.9 百分位 32 µs，而同样利用率下朴素的单核部署为 100 µs 和 5 ms<sup>[5](https://research.google/pubs/tales-of-the-tail-hardware-os-and-application-level-sources-of-tail-latency/)</sup>。在数据中心规模上，杰弗里·迪恩（Jeffrey Dean）与路易斯·安德烈·巴罗佐（Luiz André Barroso）的《规模化下的尾部》（Tail at Scale）一文主张，在中等规模系统中无足轻重的偶发高延迟时段，在大规模下可能主导性能；大型在线服务应当容忍尾部，以可预测性较差的部件组合出可预测地响应良好的整体<sup>[11](https://research.google/pubs/the-tail-at-scale/)</sup>。该文以“响应时间在 100 毫秒以内的系统比更慢的系统让用户感觉更流畅”为基准<sup>[11](https://research.google/pubs/the-tail-at-scale/)</sup>。

## 服务等级目标中的延迟

延迟是服务等级目标（SLO）——服务所承诺的可靠性目标——中的标准指标之一。基于窗口的延迟 SLO 定义一段时间内的“合格”判据；一例是“在 28 天滚动窗口内，至少 99% 的一分钟窗口里，第 95 百分位延迟指标低于 100 ms”，其中一个合格时段即一分钟内 95% 的请求延迟低于 100 ms<sup>[12](https://docs.cloud.google.com/stackdriver/docs/solutions/slo-monitoring/sli-metrics/lb-metrics)</sup>。由于单一的基于请求的 SLO 无法同时刻画典型性能与最慢请求，还需配一个针对尾部的 SLO，例如滚动一小时内 99.9% 的请求在 1000 ms 内完成<sup>[12](https://docs.cloud.google.com/stackdriver/docs/solutions/slo-monitoring/sli-metrics/lb-metrics)</sup>。

Google 的 SRE 团队把延迟 SLI 表示为“低于某阈值的请求所占百分比”，例如“延迟 < 3000 ms 的请求占比”，目标为 99%，而不是用毫秒表示的百分位值；这样所有 SLO 都采用同一单位与取值范围，而且在大型数据集上统计低于阈值的请求比精确计算百分位更容易<sup>[13](https://cloud.google.com/blog/products/gcp/building-good-slos-cre-life-lessons/?m=1)</sup>。

## 实时系统

在实时计算中，延迟是正确性要求，而非性能指标。一种性能度量是中断延迟，即从请求运行某段代码到该代码实际开始执行之间的时间；若该请求的服务关联截止期 D，服务耗时为 S，则最大允许延迟满足 L_max + S = D<sup>[6](https://live.ocw.mit.edu/courses/6-004-computation-structures-spring-2017/pages/c18/c18s1/)</sup>。必须保证实际延迟低于最大允许值的系统，称为具有硬实时约束<sup>[6](https://live.ocw.mit.edu/courses/6-004-computation-structures-spring-2017/pages/c18/c18s1/)</sup>。调度选择直接塑造最坏情况延迟：在先来先服务下，每个设备的处理程序都可能被其他所有设备拖延；而按优先级排序，则每个设备的最坏情况延迟以更高优先级设备的服务时间之和加上当前正运行的处理程序的服务时间为界<sup>[6](https://live.ocw.mit.edu/courses/6-004-computation-structures-spring-2017/pages/c18/c18s1/)</sup>。

## 控制工程

在反馈控制中，回路中的延迟是稳定性隐患。反馈系统中的纯时间延迟 e^(−sT) 会引入额外相位滞后，导致系统稳定性下降<sup>[7](https://pdf.lib.vntu.edu.ua/books/2021/Dorf_Modern_control_systems_2017_1106.pdf)</sup>。延迟裕度量化一个稳定回路能容忍多少延迟：它是在增益穿越频率处把相位裕度换算成时间；在小反馈延迟下稳定的闭环系统，在延迟大时一般会失稳<sup>[14](https://www.researchgate.net/publication/3032822_On_the_Achievable_Delay_Margin_Using_LTI_Control_for_Unstable_Plants)</sup>。在动力系统的延迟反馈控制中，作用在控制力上的额外控制回路延迟会显著限制该方法的成效，这一效应可追溯到分频点的偏移<sup>[15](https://journals.aps.org/pre/abstract/10.1103/PhysRevE.59.2826)</sup>。

## 工程上降低延迟

降低延迟是一项带有可量化权衡的设计活动。在数据中心传输中，Swift 拥塞控制算法借助网卡硬件时间戳与端到端延迟目标，在接近 100% 负载下维持每服务器 100 Gbps 吞吐的同时，为短 RPC 实现 50 µs 的尾部延迟<sup>[16](https://research.google/pubs/swift-delay-is-simple-and-effective-for-congestion-control-in-the-datacenter/)</sup>；更早的基于 RTT 的 TIMELY 设计在保持接近线速吞吐的同时，把第 99 百分位尾部延迟降至原来的九分之一<sup>[17](https://research.google/pubs/timely-rtt-based-congestion-control-for-the-datacenter/)</sup>。在调度方面，Heracles 反馈控制器把尽力而为型任务与延迟关键型服务混布，同时管理 CPU、内存与网络隔离，展示出 90% 的平均服务器利用率而无延迟违约<sup>[18](https://research.google/pubs/improving-resource-efficiency-at-scale-with-heracles/)</sup>。这些结果反映了一个普遍发现：吞吐、能耗与尾部延迟彼此权衡<sup>[5](https://research.google/pubs/tales-of-the-tail-hardware-os-and-application-level-sources-of-tail-latency/)</sup>。

## References

1. [CS 716 lecture notes, IIT Bombay: latency as propagation + transmit + queue](https://www.cse.iitb.ac.in/~sri/cs716/cs716-lec6-2011.pdf)
2. [RFC 7679: A One-Way Delay Metric for IP Performance Metrics (IPPM)](https://www.rfc-editor.org/info/rfc7679/)
3. [RFC 3432: Network performance measurement with periodic streams](https://www.rfc-editor.org/rfc/rfc3432.html)
4. [Site Reliability Engineering, Chapter 6: Monitoring Distributed Systems, "Worrying About Your Tail"](https://sre.google/sre-book/monitoring-distributed-systems/?hl=hr)
5. [Li, Sharma, Ports, Gribble (2014). Tales of the Tail: Hardware, OS, and Application-level Sources of Tail Latency, ACM SoCC](https://research.google/pubs/tales-of-the-tail-hardware-os-and-application-level-sources-of-tail-latency/)
6. [MIT 6.004 Computation Structures, Section 18.1: real-time systems and interrupt latency](https://live.ocw.mit.edu/courses/6-004-computation-structures-spring-2017/pages/c18/c18s1/)
7. [Dorf & Bishop, Modern Control Systems (2017), Section 9.7: stability of control systems with time delays](https://pdf.lib.vntu.edu.ua/books/2021/Dorf_Modern_control_systems_2017_1106.pdf)
8. [RFC 8517: A Transport-Independent Bind/Unbind TCP Measurement Procedure](https://www.rfc-editor.org/rfc/rfc8517.html)
9. [Sloss & Dahlin. Service Level Objectives chapter summary, ACM Queue / SRE book](https://storage.googleapis.com/gweb-research2023-media/pubtools/4392.pdf)
10. [Site Reliability Engineering, Chapter 4: Service Level Objectives](https://sre.google/sre-book/service-level-objectives/?hl=ko)
11. [Dean & Barroso (2013). The Tail at Scale, Communications of the ACM](https://research.google/pubs/the-tail-at-scale/)
12. [Google Cloud Observability: Using Cloud Load Balancing metrics for SLO monitoring](https://docs.cloud.google.com/stackdriver/docs/solutions/slo-monitoring/sli-metrics/lb-metrics)
13. [Google Cloud Blog: How we build good SLOs at Google](https://cloud.google.com/blog/products/gcp/building-good-slos-cre-life-lessons/?m=1)
14. [On the Achievable Delay Margin Using LTI Control for Unstable Plants, IEEE Transactions on Automatic Control](https://www.researchgate.net/publication/3032822_On_the_Achievable_Delay_Margin_Using_LTI_Control_for_Unstable_Plants)
15. [Influence of control loop latency on time-delayed feedback control, Physical Review E](https://journals.aps.org/pre/abstract/10.1103/PhysRevE.59.2826)
16. [Swift: Delay is Simple and Effective for Congestion Control in the Datacenter, SIGCOMM 2020, Google Research](https://research.google/pubs/swift-delay-is-simple-and-effective-for-congestion-control-in-the-datacenter/)
17. [Mittal et al. (2015). TIMELY: RTT-based Congestion Control for the Datacenter, SIGCOMM](https://research.google/pubs/timely-rtt-based-congestion-control-for-the-datacenter/)
18. [Lo et al. (2016). Improving Resource Efficiency at Scale with Heracles, ACM TOCS](https://research.google/pubs/improving-resource-efficiency-at-scale-with-heracles/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 工程与制造 › 工程方法与系统工程

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/latency-engineering

English original: https://www.edgepedia.org/latency-engineering
