Files
gaokao-volunteer-system/reports/perf/T11.1_PERF_REPORT.md
Hermes Agent 3f46811e49
Some checks failed
CI / pytest (Python 3.10) (push) Has been cancelled
CI / pytest (Python 3.11) (push) Has been cancelled
CI / pytest (Python 3.12) (push) Has been cancelled
release: cut v2.1
2026-06-13 14:49:58 +08:00

3.3 KiB
Raw Blame History

T11.1 性能基准报告

日期2026-06-12 仓库:/home/long/project/gaokao-volunteer-system 目标T6.1 FastAPI 管理后台骨架

1. 测试范围

使用 locustfile.py 对以下端点进行 10 并发基准:

  • POST /api/auth/login
  • GET /api/auth/me
  • GET /api/meta
  • GET /api/orders
  • GET /api/orders/{id}404 视为成功路径)
  • GET /api/stats/orders
  • GET /health

用户模型:

  • AdminBrowseUser:已登录后台浏览用户
  • LoginBurstUser:登录高峰用户

2. 测试环境

  • Python: 3.11.13
  • Locust: 2.42.4
  • 服务启动命令:python3 -m admin.app --host 127.0.0.1 --port 18081
  • 测试命令:locust -f locustfile.py --host http://127.0.0.1:18081 --headless -u 10 -r 2 -t 30s --csv reports/perf/t11_1
  • 数据库:/home/long/project/gaokao-volunteer-system/.tmp/t11_1_admin.db
  • JWT secret本地临时测试值64 个 x

3. 发现与修复

首次执行失败,根因是 AuthenticatedHttpUser 作为基类未标记为抽象类Locust 会把它当成可实例化用户,导致:

  • 异常:No tasks defined on AuthenticatedHttpUser
  • 结果:进程退出码 1压测结果不可信

已修复:

  • locustfile.py 中为 AuthenticatedHttpUser 增加 abstract = True

修复后重新执行,压测正常结束,failures.csvexceptions.csv 均为空。

4. 结果摘要

总体:

  • 总请求数327
  • 失败数0
  • 错误率0.00%
  • 平均吞吐11.27 req/s
  • 聚合中位延迟2 ms
  • 聚合平均延迟4.62 ms
  • 聚合 P9527 ms
  • 聚合 P9936 ms
  • 聚合最大值43.53 ms

分端点:

端点 请求数 失败 平均延迟(ms) P95(ms) 最大(ms) 吞吐(req/s)
POST /api/auth/login 27 0 28.53 38 43.53 0.93
GET /api/auth/me 71 0 2.52 3 4.49 2.45
GET /api/meta 55 0 2.38 3 3.37 1.90
GET /api/orders 105 0 2.51 3 4.44 3.62
GET /api/orders/{id} [404] 15 0 2.61 4 3.98 0.52
GET /api/stats/orders 44 0 2.51 3 4.19 1.52
GET /health 10 0 1.77 2 2.04 0.34

5. 结论

结论在本地单机、10 并发、30 秒 headless Locust 基准下T6.1 管理后台骨架表现稳定0 失败,所有 GET 路由 P95 ≤ 4ms登录接口 P95 为 38ms满足“先建立可压测基线”的 T11.1 目标。

当前限制:

  • 这是本地 SQLite + 单进程 uvicorn 基线,不代表生产容量上限。
  • 当前业务仍是 T6.1 骨架,/api/orders/api/stats/orders 返回占位数据;后续真实业务逻辑接入后需重跑基准。
  • 当前测试时长为 30 秒,适合基线验证;若要做发布前容量评估,建议补 5 分钟持续压测与更高并发阶梯测试。

6. 产物

  • locustfile.py
  • reports/perf/T11.1_PERF_REPORT.md
  • reports/perf/t11_1_stats.csv
  • reports/perf/t11_1_stats_history.csv
  • reports/perf/t11_1_failures.csv
  • reports/perf/t11_1_exceptions.csv