chore: 工具迁入正式工程 + 工程 README + 根目录草稿报告入 ignore

- eip4-poc/tools/{s3_rewriter,loadtest} → tools/(P4 改写器种子与压测 harness 随工程演进,PoC 冻结)
- 新增工程 README(模块图/纪律/常用命令/自举说明)
- 根目录 parity-reports/ 为 CLI 默认输出草稿,入 .gitignore(正式报告在 platform-parity/parity-reports/)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 11:20:01 +08:00
parent f10d11c958
commit c174fbdf83
94 changed files with 17746 additions and 0 deletions

148
tools/loadtest/load_p95.py Normal file
View File

@@ -0,0 +1,148 @@
#!/usr/bin/env python3
"""
EIP4 M0-C3:高频实体基础压测,输出 P50/P90/P95/P99 延迟基线。
零依赖(标准库)。用法:
python3 load_p95.py --base http://localhost:8084 \
--entities SYS_USERGROUP,PM_LABORCOMPANY --requests 200 --concurrency 10 \
--out-md 基线.md --out-json 基线.json
说明:
- Top10「高频」实体在客户生产访问日志可得前,以样本库行数 Top 实体为代理口径,
正式基线须在客户库副本(192.168.20.68:5435)网络恢复后重跑并替换。
- 每实体先 3 次预热(不计入),再发 --requests 次列表查询(page=1,perPage=20)。
"""
import argparse
import json
import statistics
import sys
import threading
import time
import urllib.error
import urllib.request
from queue import Queue
def percentile(sorted_vals, p):
if not sorted_vals:
return None
k = (len(sorted_vals) - 1) * p / 100.0
f = int(k)
c = min(f + 1, len(sorted_vals) - 1)
return sorted_vals[f] + (sorted_vals[c] - sorted_vals[f]) * (k - f)
def fire(url, timeout):
t0 = time.perf_counter()
try:
with urllib.request.urlopen(url, timeout=timeout) as r:
body = r.read()
ms = (time.perf_counter() - t0) * 1000
ok = r.status == 200
# 引擎错误也可能 200 包 status!=0,粗校验 JSON 外形
if ok and body[:1] not in (b"{", b"["):
ok = False
return ms, ok
except Exception:
return (time.perf_counter() - t0) * 1000, False
def bench_entity(base, entity, n_req, concurrency, timeout):
url = f"{base}/api/entity/{entity}/list?page=1&perPage=20"
for _ in range(3): # 预热
fire(url, timeout)
q = Queue()
for _ in range(n_req):
q.put(url)
lat, errs = [], 0
lock = threading.Lock()
def worker():
nonlocal errs
while True:
try:
u = q.get_nowait()
except Exception:
return
ms, ok = fire(u, timeout)
with lock:
lat.append(ms)
if not ok:
errs += 1
q.task_done()
t0 = time.perf_counter()
threads = [threading.Thread(target=worker, daemon=True) for _ in range(concurrency)]
for t in threads:
t.start()
for t in threads:
t.join()
wall = time.perf_counter() - t0
s = sorted(lat)
return {
"entity": entity,
"requests": n_req,
"concurrency": concurrency,
"errors": errs,
"rps": round(n_req / wall, 1) if wall > 0 else None,
"p50_ms": round(percentile(s, 50), 1),
"p90_ms": round(percentile(s, 90), 1),
"p95_ms": round(percentile(s, 95), 1),
"p99_ms": round(percentile(s, 99), 1),
"max_ms": round(s[-1], 1) if s else None,
"mean_ms": round(statistics.fmean(s), 1) if s else None,
}
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--base", default="http://localhost:8084")
ap.add_argument("--entities", required=True, help="逗号分隔实体表名")
ap.add_argument("--requests", type=int, default=200)
ap.add_argument("--concurrency", type=int, default=10)
ap.add_argument("--timeout", type=float, default=30.0)
ap.add_argument("--out-md", default=None)
ap.add_argument("--out-json", default=None)
ap.add_argument("--note", default="本地自举环境基线;客户库副本基线待网络恢复后重跑")
args = ap.parse_args()
results = []
for e in [x.strip() for x in args.entities.split(",") if x.strip()]:
print(f"压测 {e} ...", flush=True)
r = bench_entity(args.base, e, args.requests, args.concurrency, args.timeout)
print(f" P95={r['p95_ms']}ms P99={r['p99_ms']}ms RPS={r['rps']} 错误={r['errors']}")
results.append(r)
payload = {
"generated_at": time.strftime("%Y-%m-%d %H:%M:%S"),
"base": args.base,
"note": args.note,
"results": results,
}
if args.out_json:
with open(args.out_json, "w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=False, indent=2)
if args.out_md:
lines = [
"# C3 压测基线",
"",
f"> 生成时间:{payload['generated_at']} | 目标:{args.base}",
f"> 口径:每实体 {args.requests} 请求 / 并发 {args.concurrency} / list 第 1 页 20 行",
f"> {args.note}",
"",
"| 实体 | P50(ms) | P90(ms) | P95(ms) | P99(ms) | Max(ms) | RPS | 错误 |",
"|------|--------:|--------:|--------:|--------:|--------:|----:|----:|",
]
for r in results:
lines.append(
f"| {r['entity']} | {r['p50_ms']} | {r['p90_ms']} | {r['p95_ms']} "
f"| {r['p99_ms']} | {r['max_ms']} | {r['rps']} | {r['errors']} |")
with open(args.out_md, "w", encoding="utf-8") as f:
f.write("\n".join(lines) + "\n")
bad = sum(r["errors"] for r in results)
print(f"完成:{len(results)} 实体,总错误 {bad}")
sys.exit(1 if bad else 0)
if __name__ == "__main__":
main()