Skip to content

test/benchmark: turn bench_agents.py into an adaptive stress test - #1436

Open
sufubao wants to merge 5 commits into
ModelTC:mainfrom
sufubao:feat/bench-agents-suite
Open

test/benchmark: turn bench_agents.py into an adaptive stress test#1436
sufubao wants to merge 5 commits into
ModelTC:mainfrom
sufubao:feat/bench-agents-suite

Conversation

@sufubao

@sufubao sufubao commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

背景

test/benchmark/bench_agents.py 用多 session、独立长 system prompt 和持续增长的多轮历史模拟 agent 流量。本次把原来的固定健壮性/性能套件改为真正的自适应压力测试:持续递增负载,找到饱和点后保持压力,便于暴露过载、超时和长时间运行问题。

压力测试模式

  • 新增 --stress:从 --stress-start-qps 开始,按 --stress-step-qps 逐级增加到 --stress-max-qps
  • 每级持续 --stress-step-sec;一旦达到饱和条件就停止递增,并在该 QPS 持续运行 --stress-hold-sec
  • 饱和条件可配置:
    • achieved QPS / target QPS 低于 --stress-min-achieved-ratio
    • 失败或 drain 后仍未完成的请求比例高于 --stress-max-error-rate
    • session 全忙导致的 blocked tick 比例高于 --stress-max-blocked-rate
  • 每阶段实时打印进度,同时写入 <out>/<phase>.log;最终生成 <out>/report.md,标出首个饱和 QPS、失败率、blocked 比例、TTFT 等数据。
  • --quick 将 ramp/hold 时长缩短为四分之一,便于快速验证流程。

一并保留/修复

  1. 兼容 thinking 模型在 reasoning / reasoning_content / text 等字段中的流式输出。
  2. 派发前占用 session,避免 catch-up 时同一 session 被并发重复派发。
  3. 使用全部相邻 token 间隔计算 ITL,并将真实生成回复写回 history。
  4. warmup 请求仍计入完成/失败/unfinished 统计,但只从延迟分位数中排除,避免把 warmup 成功请求误报为 unfinished。
  5. 输出同时写终端和阶段日志,长时间压力保持阶段可实时观察。

用法

# 自适应压力测试:递增到饱和后保持压力
exp -m "agent stress ramp" python test/benchmark/bench_agents.py --stress

# 快速跑通流程
exp -m "quick agent stress ramp" python test/benchmark/bench_agents.py --stress --quick

# 自定义 ramp 和 hold
exp -m "custom agent stress ramp" python test/benchmark/bench_agents.py --stress \
    --stress-start-qps 5 --stress-step-qps 5 --stress-max-qps 100 \
    --stress-step-sec 60 --stress-hold-sec 300 --num-sessions 256

# 仍可运行单一固定负载点
exp -m "single agent stress load" python test/benchmark/bench_agents.py \
    --qps 20 --num-sessions 128 --duration-sec 300 --warmup-sec 10

改动范围

仅修改 test/benchmark/bench_agents.py,不影响服务端运行时逻辑。

sufubao added 4 commits August 5, 2026 19:57
给 bench_agents.py 加了一键健壮性/性能测试套件,并修了几个会导致结果失真的 bug。

Bug 修复:
- 流式 token 字段捕获:原来只读 delta.content / reasoning_content,thinking
  模型输出在 reasoning 字段时会整条流 0 token,误报 "no tokens"。改为通过
  pydantic model_extra 兜底读取 reasoning / reasoning_content / text 等任意字段。
- 并发重复派发:fire_one 只检查 s.pending 就 create_task,但 pending 在 do_turn
  里才置位;catch-up 突发时同一 session 会被重复选中(饱和区最关键处失真)。
  改为 fire_one 里先占位再调度。
- rr_idx 污染:do_turn 的 finally 里不该自增发射游标 rr_idx,会与 fire_one 的
  游标推进冲突,移除。
- ITL 计算:原仅取 token1→token2 单点采样,改为全部相邻间隔的均值,并补上汇总输出。

新增能力:
- --suite:一键跑 smoke -> QPS 扫描(找饱和拐点) -> 过载 -> idle-then-burst,
  可选 --full 追加长稳阶段。每阶段落 *.log,结尾输出 markdown 总表 report.md。
- 实时进度 reporter(--report-sec):每行打印 fired/blocked/ok/err/pend/achQPS
  及当前 TTFT/TPOT,便于长跑观察。
- 默认端口改为 8000;文件头补完整用法说明(单次 bench + 套件两种模式、关键参数、
  输出判读)。
原来 history 里追加的是硬编码桩 "(reply)",下一轮 prefix 几乎不增长,
不像真实多轮 agent。改为累计本轮流式真实输出(content + reasoning)写回
history,使每轮 prefix 真实增长,模拟真实 agent 调用。
@sufubao sufubao changed the title test/benchmark: add --suite mode and fix bugs in bench_agents.py test/benchmark: turn bench_agents.py into an adaptive stress test Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant