关于「可用性马尔可夫链:修复时间如何吃掉全年预算」,《单机零停机热迁与十秒止血》给出的定量结论是什么?
结论:第三章用可用性马尔可夫链说明,五个 9 的预算摊到每次坏版本只有 12.1 秒,扩展收缩式把全年停机从 2431.9 分钟压到 155.9 分钟。
数据口径:书中只讲通用的数学模型,例子用虚构的 app-blue、app-green 与 db;参数为示意,全部计算由书中程序生成,程序不连接任何服务器;本书是非个人化的经营与工程参考,生产变更须按运维协议人工放行。 书中以标注框区分已发表的证据、可运行的 Python 计算(22 段程序)、原典与作者的假说。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 155.9, 2431.9
branch at detection, expand-contract: 0.8930 0.0510 0.0560 expand-contract: A = 0.9997034, down 155.9 min a year mean outage per bad release 359.7 s DET 3.30e-06 FAST 6.62e-06 COMP 1.30e-05 REST 1.90e-04 MAN 8.38e-05 big-bang: A = 0.9953731, down 2431.9 min a year mean outage per bad release 5612.0 s DET 3.28e-06 FAST 0.00e+00 COMP 0.00e+00 REST 3.21e-03 MAN 1.42e-03
查看完整验算程序
# Chapter 3. p32: a six-state availability Markov chain for releases.
# States: UP; DET (a bad release is failing, not yet detected); FAST
# (pointer flipped back, mean 9 s); COMP (undo with reverse backfill,
# mean 309 s); REST (restore from backup, mean 3909 s); MAN (manual
# rebuild after a failed restore, mean 4 h). Rates are reciprocals of
# mean holding times (exponential holding, the usual CTMC reading).
# Bad releases arrive 26 times a year (p31); detection takes 4 s on
# average (p11, "tighter"). At detection the branch shares come from
# where the fault falls against the bake period (p22): expand-contract
# with B = 24 h, or big-bang (always REST). A failed FAST or COMP undo
# falls back to REST, a failed REST goes to MAN. The stationary law
# solves pi Q = 0 with the entries of pi adding to 1, by Gaussian
# elimination with partial pivoting; inner products use math.fsum.
# All rates and probabilities are illustrative.
import math
YEAR_S = 365.0 * 86400.0
NAMES = ("UP", "DET", "FAST", "COMP", "REST", "MAN")
LAM = 26.0 / YEAR_S
MEAN = {"DET": 4.0, "FAST": 9.0, "COMP": 309.0, "REST": 3909.0,
"MAN": 14400.0}
OK = {"FAST": 0.998, "COMP": 0.978, "REST": 0.8802}
def cdf(x_h, med=2.0, spread=2.0):
z = (math.log(x_h) - math.log(med)) / spread
return 0.5 * (1.0 + math.erf(z / math.sqrt(2.0)))
def generator(branch):
n = len(NAMES)
ix = {s: i for i, s in enumerate(NAMES)}
q = [[0.0] * n for _ in range(n)]
def add(a, b, rate):
q[ix[a]][ix[b]] = rate
add("UP", "DET", LAM)
for tgt, share in zip(("FAST", "COMP", "REST"), branch):
add("DET", tgt, share / MEAN["DET"])
for st in ("FAST", "COMP"):
add(st, "UP", OK[st] / MEAN[st])
add(st, "REST", (1.0 - OK[st]) / MEAN[st])
add("REST", "UP", OK["REST"] / MEAN["REST"])
add("REST", "MAN", (1.0 - OK["REST"]) / MEAN["REST"])
add("MAN", "UP", 1.0 / MEAN["MAN"])
for i in range(n):
q[i][i] = -math.fsum(q[i][j] for j in range(n) if j != i)
return q
def stationary(q):
n = len(q)
a = [[q[j][i] for j in range(n)] + [0.0] for i in range(n)]
a[-1] = [1.0] * n + [1.0]
for c in range(n):
p = max(range(c, n), key=lambda r: abs(a[r][c]))
a[c], a[p] = a[p], a[c]
for r in range(n):
if r != c and a[r][c] != 0.0:
f = a[r][c] / a[c][c]
a[r] = [x - f * y for x, y in zip(a[r], a[c])]
return [max(0.0, a[i][n] / a[i][i]) for i in range(n)]
p1 = cdf(24.0)
p2 = cdf(48.0) - p1
POLICIES = (("expand-contract", (p1, p2, 1.0 - p1 - p2)),
("big-bang", (0.0, 0.0, 1.0)))
print("branch at detection, expand-contract: %.4f %.4f %.4f" % (
p1, p2, 1.0 - p1 - p2))
for label, br in POLICIES:
pi = stationary(generator(br))
down = 1.0 - pi[0]
print("%s: A = %.7f, down %.1f min a year" % (
label, pi[0], down * YEAR_S / 60.0))
print(" mean outage per bad release %.1f s" % (down * YEAR_S / 26.0))
print(" " + " ".join("%s %.2e" % (s, p)
for s, p in zip(NAMES[1:], pi[1:])))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《单机多容器零停机热迁与回滚、共享隧道架构生产库无损演进与十秒止血契约母典》第 3 章「可用性马尔可夫链:修复时间如何吃掉全年预算」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-269 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026269,
author = {Fan, Yafu},
title = {Zero-Downtime Hot Migration and Rollback on Multi-Container Single Hosts: Lossless Schema Evolution behind a Shared Tunnel and a Ten-Second Stop-the-Bleeding Contract},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}