M1-010Medium指标口径 · Metric definitions

为什么延迟指标要用 p95/p99 而不是平均值?

Why should latency be reported at p95/p99 rather than as a mean?
💡 考场高分一句话答案:

延迟分布是重尾的,均值被少数极慢请求主导且不代表任何真实用户的体验;分位数直接对应“有多少比例的用户受罪”。

Latency is heavy-tailed: the mean is dominated by a few very slow requests and represents nobody's experience, while quantiles state directly what fraction of users suffer.

📌 核心考察要点 (Key Points)

  • 均值的问题:少数 10 秒的请求可以把均值从 200ms 拉到 400ms,而 99% 的用户毫无感知
  • 分位数的含义:p95 = 95% 的请求快于此值,直接对应用户体感
  • 组合陷阱:不能对分位数求平均(p95 的平均 ≠ 全局 p95),必须回到原始分布重算
  • 决策用法:SLO 通常写成“p95 < 300ms”,而不是“均值 < 300ms”
  • The mean problem: a handful of 10-second requests can move the mean from 200ms to 400ms while 99% of users notice nothing
  • Quantile meaning: p95 means 95% of requests are faster than this, which maps onto felt experience
  • Aggregation trap: quantiles cannot be averaged (the mean of p95s is not the global p95); recompute from the raw distribution
  • Decision use: SLOs are written as 'p95 < 300ms', not 'mean < 300ms'

📐 第一性原理与数理推导机理

若延迟 $T$ 服从重尾分布(如对数正态 $\ln T\sim N(\mu,\sigma^2)$),则 $\mathbb{E}[T]=e^{\mu+\sigma^2/2}$ 对 $\sigma$ 极度敏感,而 $\text{p95}=e^{\mu+1.645\sigma}$ 只线性依赖于 $\sigma$。这就是为什么均值在尾部变厚时会剧烈波动,而分位数稳定。

⚖️ 业务权衡与取舍 (Trade-offs & Calibration)

在 A/B 中,延迟指标还有一个陷阱:延迟本身会影响样本构成(慢到用户直接退出,这些会话不进分母),造成幸存者偏差,使“延迟改善”看起来比实际小。处理方式是固定分母(按请求而非按完成会话)并监控超时率。

⚠️ 常见高频面试陷阱与避坑指南

  • 对分位数做跨维度平均,得到无意义的数字
  • 只看 p50,忽略尾部恶化(尾部才是投诉来源)

🔍 大厂面试官连环追问 (Follow-ups)

  • 如何在 A/B 中正确比较两个分位数?(提示:bootstrap / 分位数回归)
  • 延迟改善 100ms 值多少钱?怎么估?

嫌字多看太累?进入苏格拉底式对话推演实验室

零打字负担,以大厂考官真实困境切入,通过点选直觉选项暴露思维盲区,手把手推导 Why。

💬 开启对话式破冰 ➔
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔