from decimal import Decimal
from pathlib import Path
import json
page_bytes=30_000;views=50_000;gross=page_bytes*views
origin=Decimal(gross)*Decimal('.35')*(1-Decimal('.6'))
assert gross==1_500_000_000 and origin==Decimal('210000000.000')
def outage_minutes(percent,days=30):return Decimal(days)*24*60*(1-Decimal(percent)/100)
assert outage_minutes('99')==Decimal('432.00') and outage_minutes('99.9')==Decimal('43.200') and outage_minutes('99.99')==Decimal('4.3200')
files={p.name:p.stat().st_size for p in (Path(__file__).parent/'public').iterdir() if p.is_file()}
print(json.dumps({'decimal_GB':gross/1_000_000_000,'binary_GiB':gross/(1024**3),'origin_bytes_in_fixture':str(origin),'assumptions':{'compression_ratio':'.35','cache_hit':'.6'},'outage_minutes_30_days':{x:str(outage_minutes(x)) for x in ['99','99.9','99.99']},'actual_local_files':files,'real_capacity_benchmark':False},ensure_ascii=False))
本例需在 本地Python3.12/SQLite;PHP8.4.27 -n;回环HTTP 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:本地Python3.12/SQLite;PHP8.4.27 -n;回环HTTP
入口文件:projects/hosting-lab/capacity.py
预期结果与验证条件观察提示
- 1.5GB及210000000B假设、三种可用性预算计算正确
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联11章) · 含当前章节或实例 · mbskycom202611a516.zip