关于「预算分配:把页面百分位拆到每一个调用」,《扇出尾延迟与对冲请求》给出的定量结论是什么?
结论:第六章把页面预算拆给各调用,按成本不等分可省下 0.0597 的容量成本。
数据口径:书中服务时间、慢请求比例与成本均为示意参数;全部计算由书中程序生成;本书属于非个人化经营建议。 书中以标注框区分已发表的证据、可运行的 Python 计算(22 段程序)、原典与作者的假说。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.0597
| class n cost k equal share optimal share | |
| cache | 60 1.0 0.000100 0.000032 |
| db | 30 4.0 0.000100 0.000130 |
| search | 9 10.0 0.000100 0.000324 |
| partner | 1 40.0 0.000100 0.001295 |
| capacity cost, equal split | 14.2683 |
| capacity cost, optimal split | 13.4164 |
| saving | 0.0597 of the equal-split cost |
| check P(page meets B) | 0.990000 |
查看完整验算程序
# Chapter 6. p62: unequal split of the slow share by marginal cost.
# Model (illustrative): four classes of calls in one page, n_i calls
# each, all with deadline B = 200 ms. Holding class i to slow share e_i
# needs a rate gap g_i = ln(1/e_i)/B per server at cost k_i per unit
# gap. Minimise sum n_i k_i g_i subject to
# sum n_i (-ln(1 - e_i)) = -ln(0.99) (page meets B with 0.99).
# Lagrange: e_i / (1 - e_i) = k_i / (nu B); nu found by bisection.
import math
B = 200.0
CLASSES = (("cache", 60, 1.0), ("db", 30, 4.0), ("search", 9, 10.0),
("partner", 1, 40.0))
BUDGET = -math.log(0.99)
def used(nu):
terms = []
for _, n, k in CLASSES:
x = k / (nu * B)
e = x / (1.0 + x)
terms.append(-n * math.log1p(-e))
return math.fsum(terms)
def cost(eps):
return math.fsum(n * k * math.log(1.0 / e) / B
for (_, n, k), e in zip(CLASSES, eps))
if __name__ == "__main__":
lo, hi = 1e-6, 1e9
for _ in range(300):
mid = math.sqrt(lo * hi)
if used(mid) > BUDGET:
lo = mid
else:
hi = mid
nu = hi
opt = [(k / (nu * B)) / (1.0 + k / (nu * B)) for _, _, k in CLASSES]
total_n = math.fsum(n for _, n, _ in CLASSES)
eq = -math.expm1(math.log(0.99) / total_n)
print("class n cost k equal share optimal share")
for (name, n, k), e in zip(CLASSES, opt):
print(" {:<8} {:3d} {:6.1f} {:.6f} {:.6f}".format(
name, n, k, eq, e))
c_eq, c_opt = cost([eq] * len(CLASSES)), cost(opt)
print("capacity cost, equal split: {:.4f}".format(c_eq))
print("capacity cost, optimal split: {:.4f}".format(c_opt))
print("saving: {:.4f} of the equal-split cost".format(1.0 - c_opt / c_eq))
chk = math.fsum(-n * math.log1p(-e) for (_, n, _), e in
zip(CLASSES, opt))
print("check P(page meets B) = {:.6f}".format(math.exp(-chk)))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《扇出尾延迟乘法律与对冲请求、单页多调用时百分位延迟的放大母典》第 6 章「预算分配:把页面百分位拆到每一个调用」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-326 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026326,
author = {Fan, Yafu},
title = {The Multiplicative Law of Fan-Out Tail Latency and Hedged Requests: How Percentile Latency Amplifies When One Page Makes Many Calls},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}