mcpField
H
http-load-profiler

http-load-profiler

github.com/zebbern测试与质量4.7k42 次安装1 天前更新
代码仓库

关于 http-load-profiler

这是一款用于 HTTP 服务的 Python 负载测试技能,可逐级提高并发并识别性能拐点,适合需要分析延迟、吞吐量和错误率的开发者。

主要功能

  1. 01选择 wrk 或 ab 引擎
  2. 02配置并发测试阶梯
  3. 03采集 p50、p90 和 p99 延迟
  4. 04检测四类性能拐点
  5. 05推荐最佳并发级别
  6. 06输出易读文本或 JSON

适用场景

  1. 01测量 HTTP 接口在递增负载下的表现
  2. 02找出延迟加速的并发级别
  3. 03比较各负载阶梯的吞吐量与错误

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/zebbern/claude-code-guide --skill http-load-profiler

安装后在 Claude Code 中输入/http-load-profiler确认已加载。

附带文件LICENSEscripts/http_benchmark.py

详细介绍

HTTP 负载分析器 — 阶梯式并发负载测试 + 拐点分析

对 HTTP 服务运行阶梯式并发负载测试,自动收集延迟百分位数并检测性能拐点。

功能

  • 双引擎支持:自动检测 wrk(首选)或 ab(Apache Bench);也可手动指定
  • 阶梯式并发:按用户定义的并发级别逐步提升(默认:1 → 10 → 50 → 100 → 200 → 500)
  • 延迟百分位数:收集每个级别的 p50 / p90 / p99 延迟
  • 拐点检测:自动识别四种性能拐点
    • p99 延迟加速增长(增幅超过上一步增幅的 2 倍)
    • 吞吐效率显著下降(每个连接的 RPS 下降超过 40%)
    • 吞吐量达到饱和,同时延迟激增(RPS 增幅 < 10%,p99 增幅 > 50%)
    • 错误率激增(超过 1%,且较上一步翻倍)
  • 最优并发建议:根据拐点自动推荐最佳并发级别
  • 零 Python 依赖:纯标准库实现

快速开始

# Basic usage — run default stepped load test against target URL
python3 scripts/http_benchmark.py https://example.com/api/health

# Custom concurrency steps and duration per step
python3 scripts/http_benchmark.py https://example.com/api/health -s 5,20,50,100,300 -d 15

# Specify ab as the engine
python3 scripts/http_benchmark.py https://example.com/ -t ab

# JSON-only output (for programmatic parsing)
python3 scripts/http_benchmark.py https://example.com/api/health --json

# Use ab with a specific number of requests per step
python3 scripts/http_benchmark.py https://example.com/ -t ab -n 5000

# Save JSON report to a file
python3 scripts/http_benchmark.py https://example.com/api/health --json > report.json

参数

参数短参数默认值说明
url—(必填)目标 URL(http:// 或 https://)
--steps-s1,10,50,100,200,500并发级别(以逗号分隔的正整数)
--duration-d10每个级别的持续时间(秒)(wrk 直接使用此值;ab 根据此值估算请求数)
--requests-nconcurrency×100使用 ab 时每个级别的请求总数
--tool-t自动检测指定负载测试工具:wrk 或 ab
--threads—min(concurrency, CPU cores)wrk 的线程数
--json—false仅输出 JSON

输出格式

人类可读(默认)
Tool: wrk
Target URL: https://example.com/api/health
Concurrency steps: [1, 10, 50, 100, 200, 500]
Duration per step: 10s

----------------------------------------------------------------------------------
  Conc. |        RPS |  Avg(ms) |  P50(ms) |  P90(ms) |  P99(ms) |   Errors | Inflection
----------------------------------------------------------------------------------
     1 |      245.3 |      4.1 |      3.8 |      5.2 |      8.1 |   0.00% |
    10 |     2301.5 |      4.3 |      4.0 |      5.8 |      9.3 |   0.00% |
    50 |     9876.2 |      5.1 |      4.6 |      7.2 |     12.5 |   0.00% |
   100 |    14523.1 |      6.9 |      5.8 |     10.3 |     22.7 |   0.00% |
   200 |    15102.3 |     13.2 |     10.1 |     22.5 |     58.3 |   0.12% |  ◀
   500 |    14890.5 |     33.6 |     28.3 |     55.2 |    132.1 |   1.35% |  ◀
----------------------------------------------------------------------------------

Inflection point analysis:
  ▶ Concurrency 200:
    - p99 latency accelerating: 22.7ms → 58.3ms (increase 35.6ms, previous step increase 10.2ms)
    - Throughput saturated with latency spike: RPS grew only 3.9% while p99 latency grew 156.8%
  ▶ Concurrency 500:
    - Error rate surging: 0.12% → 1.35%

Recommended optimal concurrency: 100
JSON 格式(--json)
{
  "url": "https://example.com/api/health",
  "tool": "wrk",
  "duration_per_step": 10,
  "steps": [
    {
      "concurrency": 1,
      "rps": 245.3,
      "avg_latency_ms": 4.1,
      "p50_ms": 3.8,
      "p90_ms": 5.2,
      "p99_ms": 8.1,
      "total_requests": 2453,
      "errors": 0
    }
  ],
  "inflection_points": [
    {
      "concurrency": 200,
      "step_index": 4,
      "reasons": ["p99 latency accelerating: ..."]
    }
  ],
  "recommended_concurrency": 100
}

先决条件

必须安装 wrk 或 ab 中的至少一个:

# Ubuntu / Debian
sudo apt-get install wrk          # recommended
sudo apt-get install apache2-utils # ab

# macOS
brew install wrk
# ab is pre-installed on macOS

拐点检测算法

对于每个并发级别,会将以下指标与前两个级别进行比较:

  1. p99 延迟加速增长:当前 p99 增幅超过上一步增幅的 2 倍时触发
  2. 吞吐效率:每个连接的 RPS 较上一步下降超过 40% 时触发
  3. 饱和检测:RPS 增幅 < 10%,同时 p99 增幅 > 50% 时触发
  4. 错误率:错误率超过 1% 且较上一步翻倍时触发

建议的最优并发级别:第一个拐点前一级的并发级别。如果没有检测到拐点,则选择 RPS 最高的级别。

重要说明

  • 负载测试会向目标服务发送真实流量 — 未经授权,请勿对生产服务运行测试
  • wrk 提供的延迟百分位数比 ab 更准确(wrk 使用 HdrHistogram)
  • ab 不支持持续时间参数;脚本通过请求总数近似控制测试时长
  • 建议每个级别至少测试 10 秒,以获得稳定结果

评论

支持 Markdown