Files
water-management-system/tests/performance/README.md
T

33 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 性能压测方案(Issue #94)
## 范围
1. **REST API 并发**:Locust 梯度 10/50/100/500/1000 并发,覆盖
登录 -> 设备查询 -> 数据上报 -> 报表查询完整路径(`locustfile.py`)
2. **数据量**:百万级抄表/营收记录下的分页查询与报表聚合(结合 `db/` 种子数据,
关注慢查询日志 > 500ms 的语句并补索引)
3. **WebSocket 长连接**:`websocket_stress.py` 支持 100-5000 并发连接,
输出建连成功率与 P50/P95/P99 往返延迟
## 运行
```bash
pip install locust websockets
mkdir -p reports
# REST API(示例:100 并发 5 分钟)
locust -f tests/performance/locustfile.py --host http://127.0.0.1:8000 \
-u 100 --spawn-rate 10 --run-time 5m --headless --html reports/api_100.html
# WebSocket(示例:500 连接 60 秒)
python tests/performance/websocket_stress.py --url ws://127.0.0.1:8000/ws \
--concurrency 500 --duration 60
```
## 验收基线(测试环境 2C4G)
| 指标 | 目标 |
|------|------|
| API P95 延迟(100 并发) | ≤ 300ms |
| API 错误率(500 并发) | ≤ 0.5% |
| WebSocket 500 连接建连成功率 | ≥ 99% |
| WS 消息 P95 往返 | ≤ 200ms |