qe-performance-testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePerformance Testing
性能测试
<default_to_action>
When testing performance or planning load tests:
- DEFINE SLOs: p95 response time, throughput, error rate targets
- IDENTIFY critical paths: revenue flows, high-traffic pages, key APIs
- CREATE realistic scenarios: user journeys, think time, varied data
- EXECUTE with monitoring: CPU, memory, DB queries, network
- ANALYZE bottlenecks and fix before production
Quick Test Type Selection:
- Expected load validation → Load testing
- Find breaking point → Stress testing
- Sudden traffic spike → Spike testing
- Memory leaks, resource exhaustion → Endurance/soak testing
- Horizontal/vertical scaling → Scalability testing
Critical Success Factors:
- Performance is a feature, not an afterthought
- Test early and often, not just before release
- Focus on user-impacting bottlenecks </default_to_action>
<default_to_action>
当测试性能或规划负载测试时:
- 定义SLO:p95响应时间、吞吐量、错误率指标
- 识别关键路径:营收流程、高流量页面、核心API
- 创建真实场景:用户旅程、思考时间、多样化数据
- 结合监控执行:CPU、内存、数据库查询、网络
- 分析瓶颈并在上线前修复
快速测试类型选择:
- 预期负载验证 → 负载测试
- 寻找崩溃临界点 → 压力测试
- 突发流量峰值 → 峰值测试
- 内存泄漏、资源耗尽 → 耐久测试/浸泡测试
- 水平/垂直扩容 → 可扩展性测试
关键成功因素:
- 性能是一项功能,而非事后补充
- 尽早且频繁测试,不要仅在发布前进行
- 聚焦影响用户体验的瓶颈 </default_to_action>
Quick Reference Card
快速参考卡片
When to Use
适用场景
- Before major releases
- After infrastructure changes
- Before scaling events (Black Friday)
- When setting SLAs/SLOs
- 重大版本发布前
- 基础设施变更后
- 流量高峰事件前(如黑色星期五)
- 设置SLA/SLO时
Test Types
测试类型
| Type | Purpose | When |
|---|---|---|
| Load | Expected traffic | Every release |
| Stress | Beyond capacity | Quarterly |
| Spike | Sudden surge | Before events |
| Endurance | Memory leaks | After code changes |
| Scalability | Scaling validation | Infrastructure changes |
| 类型 | 用途 | 适用时机 |
|---|---|---|
| 负载测试 | 验证预期流量下的表现 | 每次发布 |
| 压力测试 | 测试超出承载能力的极限 | 每季度 |
| 峰值测试 | 应对突发流量激增 | 活动前 |
| 耐久测试 | 检测内存泄漏 | 代码变更后 |
| 可扩展性测试 | 验证扩容能力 | 基础设施变更时 |
Key Metrics
核心指标
| Metric | Target | Why |
|---|---|---|
| p95 response | < 200ms | User experience |
| Throughput | 10k req/min | Capacity |
| Error rate | < 0.1% | Reliability |
| CPU | < 70% | Headroom |
| Memory | < 80% | Stability |
| 指标 | 目标 | 原因 |
|---|---|---|
| p95响应时间 | < 200ms | 用户体验 |
| 吞吐量 | 10k 请求/分钟 | 系统容量 |
| 错误率 | < 0.1% | 可靠性 |
| CPU使用率 | < 70% | 预留冗余 |
| 内存使用率 | < 80% | 稳定性 |
Tools
工具
- k6: Modern, JS-based, CI/CD friendly
- JMeter: Enterprise, feature-rich
- Artillery: Simple YAML configs
- Gatling: Scala, great reporting
- k6:现代化、基于JS、适配CI/CD
- JMeter:企业级、功能丰富
- Artillery:简洁YAML配置
- Gatling:基于Scala、报表能力出色
Agent Coordination
Agent协作
- : Load test orchestration
qe-performance-tester - : Results analysis
qe-quality-analyzer - : Production comparison
qe-production-intelligence
- :负载测试编排
qe-performance-tester - :结果分析
qe-quality-analyzer - :生产环境对比
qe-production-intelligence
Defining SLOs
定义SLO
Bad: "The system should be fast"
Good: "p95 response time < 200ms under 1,000 concurrent users"
javascript
export const options = {
thresholds: {
http_req_duration: ['p(95)<200'], // 95% < 200ms
http_req_failed: ['rate<0.01'], // < 1% failures
},
};错误示例: "系统应该很快"
正确示例: "1000并发用户下,p95响应时间<200ms"
javascript
export const options = {
thresholds: {
http_req_duration: ['p(95)<200'], // 95% 请求耗时 < 200ms
http_req_failed: ['rate<0.01'], // 错误率 < 1%
},
};Realistic Scenarios
真实场景模拟
Bad: Every user hits homepage repeatedly
Good: Model actual user behavior
javascript
// Realistic distribution
// 40% browse, 30% search, 20% details, 10% checkout
export default function () {
const action = Math.random();
if (action < 0.4) browse();
else if (action < 0.7) search();
else if (action < 0.9) viewProduct();
else checkout();
sleep(randomInt(1, 5)); // Think time
}错误示例: 所有用户重复访问首页
正确示例: 模拟真实用户行为
javascript
// 真实行为分布
// 40% 浏览,30% 搜索,20% 查看详情,10% 结账
export default function () {
const action = Math.random();
if (action < 0.4) browse();
else if (action < 0.7) search();
else if (action < 0.9) viewProduct();
else checkout();
sleep(randomInt(1, 5)); // 思考时间
}Common Bottlenecks
常见瓶颈
Database
数据库
Symptoms: Slow queries under load, connection pool exhaustion
Fixes: Add indexes, optimize N+1 queries, increase pool size, read replicas
症状: 负载下查询缓慢、连接池耗尽
修复方案: 添加索引、优化N+1查询、扩大连接池、读写分离
N+1 Queries
N+1查询问题
javascript
// BAD: 100 orders = 101 queries
const orders = await Order.findAll();
for (const order of orders) {
const customer = await Customer.findById(order.customerId);
}
// GOOD: 1 query
const orders = await Order.findAll({ include: [Customer] });javascript
// 错误:100个订单 = 101次查询
const orders = await Order.findAll();
for (const order of orders) {
const customer = await Customer.findById(order.customerId);
}
// 正确:1次查询
const orders = await Order.findAll({ include: [Customer] });Synchronous Processing
同步处理
Problem: Blocking operations in request path (sending email during checkout)
Fix: Use message queues, process async, return immediately
问题: 请求路径中的阻塞操作(如结账时同步发送邮件)
修复方案: 使用消息队列、异步处理、立即返回结果
Memory Leaks
内存泄漏
Detection: Endurance testing, memory profiling
Common causes: Event listeners not cleaned, caches without eviction
检测方式: 耐久测试、内存分析
常见原因: 事件监听器未清理、缓存无驱逐策略
External Dependencies
外部依赖
Solutions: Aggressive timeouts, circuit breakers, caching, graceful degradation
解决方案: 严格超时设置、熔断机制、缓存、优雅降级
k6 CI/CD Example
k6 CI/CD 示例
javascript
// performance-test.js
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '1m', target: 50 }, // Ramp up
{ duration: '3m', target: 50 }, // Steady
{ duration: '1m', target: 0 }, // Ramp down
],
thresholds: {
http_req_duration: ['p(95)<200'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
const res = http.get('https://api.example.com/products');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 200ms': (r) => r.timings.duration < 200,
});
sleep(1);
}yaml
undefinedjavascript
// performance-test.js
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '1m', target: 50 }, // 逐步加压
{ duration: '3m', target: 50 }, // 稳定负载
{ duration: '1m', target: 0 }, // 逐步减压
],
thresholds: {
http_req_duration: ['p(95)<200'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
const res = http.get('https://api.example.com/products');
check(res, {
'状态码为200': (r) => r.status === 200,
'响应时间<200ms': (r) => r.timings.duration < 200,
});
sleep(1);
}yaml
undefinedGitHub Actions
GitHub Actions
- name: Run k6 test uses: grafana/k6-action@v0.3.0 with: filename: performance-test.js
---- name: 运行k6测试 uses: grafana/k6-action@v0.3.0 with: filename: performance-test.js
---Analyzing Results
结果分析
Good Results
合格结果
Load: 1,000 users | p95: 180ms | Throughput: 5,000 req/s
Error rate: 0.05% | CPU: 65% | Memory: 70%负载:1000用户 | p95:180ms | 吞吐量:5000请求/秒
错误率:0.05% | CPU:65% | 内存:70%Problems
异常结果
Load: 1,000 users | p95: 3,500ms ❌ | Throughput: 500 req/s ❌
Error rate: 5% ❌ | CPU: 95% ❌ | Memory: 90% ❌负载:1000用户 | p95:3500ms ❌ | 吞吐量:500请求/秒 ❌
错误率:5% ❌ | CPU:95% ❌ | 内存:90% ❌Root Cause Analysis
根因分析
- Correlate metrics: When response time spikes, what changes?
- Check logs: Errors, warnings, slow queries
- Profile code: Where is time spent?
- Monitor resources: CPU, memory, disk
- Trace requests: End-to-end flow
- 关联指标:响应时间飙升时,哪些指标发生变化?
- 检查日志:错误、警告、慢查询
- 代码分析:时间消耗在何处?
- 资源监控:CPU、内存、磁盘
- 请求追踪:端到端流程
Anti-Patterns
反模式
| ❌ Anti-Pattern | ✅ Better |
|---|---|
| Testing too late | Test early and often |
| Unrealistic scenarios | Model real user behavior |
| 0 to 1000 users instantly | Ramp up gradually |
| No monitoring during tests | Monitor everything |
| No baseline | Establish and track trends |
| One-time testing | Continuous performance testing |
| ❌ 反模式 | ✅ 优化方案 |
|---|---|
| 测试过晚 | 尽早且频繁测试 |
| 场景不真实 | 模拟真实用户行为 |
| 瞬间从0到1000用户 | 逐步加压 |
| 测试时无监控 | 全链路监控 |
| 无基准线 | 建立并追踪趋势 |
| 一次性测试 | 持续性能测试 |
Agent-Assisted Performance Testing
Agent辅助性能测试
typescript
// Comprehensive load test
await Task("Load Test", {
target: 'https://api.example.com',
scenarios: {
checkout: { vus: 100, duration: '5m' },
search: { vus: 200, duration: '5m' },
browse: { vus: 500, duration: '5m' }
},
thresholds: {
'http_req_duration': ['p(95)<200'],
'http_req_failed': ['rate<0.01']
}
}, "qe-performance-tester");
// Bottleneck analysis
await Task("Analyze Bottlenecks", {
testResults: perfTest,
metrics: ['cpu', 'memory', 'db_queries', 'network']
}, "qe-performance-tester");
// CI integration
await Task("CI Performance Gate", {
mode: 'smoke',
duration: '1m',
vus: 10,
failOn: { 'p95_response_time': 300, 'error_rate': 0.01 }
}, "qe-performance-tester");typescript
// 全面负载测试
await Task("Load Test", {
target: 'https://api.example.com',
scenarios: {
checkout: { vus: 100, duration: '5m' },
search: { vus: 200, duration: '5m' },
browse: { vus: 500, duration: '5m' }
},
thresholds: {
'http_req_duration': ['p(95)<200'],
'http_req_failed': ['rate<0.01']
}
}, "qe-performance-tester");
// 瓶颈分析
await Task("Analyze Bottlenecks", {
testResults: perfTest,
metrics: ['cpu', 'memory', 'db_queries', 'network']
}, "qe-performance-tester");
// CI集成
await Task("CI Performance Gate", {
mode: 'smoke',
duration: '1m',
vus: 10,
failOn: { 'p95_response_time': 300, 'error_rate': 0.01 }
}, "qe-performance-tester");Agent Coordination Hints
Agent协作提示
Memory Namespace
内存命名空间
aqe/performance/
├── results/* - Test execution results
├── baselines/* - Performance baselines
├── bottlenecks/* - Identified bottlenecks
└── trends/* - Historical trendsaqe/performance/
├── results/* - 测试执行结果
├── baselines/* - 性能基准线
├── bottlenecks/* - 已识别瓶颈
└── trends/* - 历史趋势Fleet Coordination
集群协作
typescript
const perfFleet = await FleetManager.coordinate({
strategy: 'performance-testing',
agents: [
'qe-performance-tester',
'qe-quality-analyzer',
'qe-production-intelligence',
'qe-deployment-readiness'
],
topology: 'sequential'
});typescript
const perfFleet = await FleetManager.coordinate({
strategy: 'performance-testing',
agents: [
'qe-performance-tester',
'qe-quality-analyzer',
'qe-production-intelligence',
'qe-deployment-readiness'
],
topology: 'sequential'
});Pre-Production Checklist
上线前检查清单
- Load test passed (expected traffic)
- Stress test passed (2-3x expected)
- Spike test passed (sudden surge)
- Endurance test passed (24+ hours)
- Database indexes in place
- Caching configured
- Monitoring and alerting set up
- Performance baseline established
- 负载测试通过(预期流量)
- 压力测试通过(2-3倍预期流量)
- 峰值测试通过(突发流量)
- 耐久测试通过(24小时以上)
- 数据库索引已配置
- 缓存已启用
- 监控与告警已设置
- 性能基准线已建立
Related Skills
相关技能
- agentic-quality-engineering - Agent coordination
- api-testing-patterns - API performance
- chaos-engineering-resilience - Resilience testing
- agentic-quality-engineering - Agent协作
- api-testing-patterns - API性能测试
- chaos-engineering-resilience - 韧性测试
Remember
要点回顾
Performance is a feature: Test it like functionality
Test continuously: Not just before launch
Monitor production: Synthetic + real user monitoring
Fix what matters: Focus on user-impacting bottlenecks
Trend over time: Catch degradation early
With Agents: Agents automate load testing, analyze bottlenecks, and compare with production. Use agents to maintain performance at scale.
性能是一项功能: 像测试功能一样测试性能
持续测试: 不要仅在上线前测试
监控生产环境: 合成监控+真实用户监控
聚焦关键问题: 优先修复影响用户的瓶颈
追踪趋势: 尽早发现性能退化
借助Agent: Agent可自动化负载测试、分析瓶颈、对比生产环境数据。利用Agent在规模场景下维持性能标准。