Loading...
Loading...
Compare original and translation side by side
| 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 |
| 类型 | 用途 | 适用时机 |
|---|---|---|
| 负载测试 | 验证预期流量下的表现 | 每次发布 |
| 压力测试 | 测试超出承载能力的极限 | 每季度 |
| 峰值测试 | 应对突发流量激增 | 活动前 |
| 耐久测试 | 检测内存泄漏 | 代码变更后 |
| 可扩展性测试 | 验证扩容能力 | 基础设施变更时 |
| 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% | 稳定性 |
qe-performance-testerqe-quality-analyzerqe-production-intelligenceqe-performance-testerqe-quality-analyzerqe-production-intelligenceexport const options = {
thresholds: {
http_req_duration: ['p(95)<200'], // 95% < 200ms
http_req_failed: ['rate<0.01'], // < 1% failures
},
};export const options = {
thresholds: {
http_req_duration: ['p(95)<200'], // 95% 请求耗时 < 200ms
http_req_failed: ['rate<0.01'], // 错误率 < 1%
},
};// 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
}// 真实行为分布
// 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)); // 思考时间
}// 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] });// 错误: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] });// 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);
}undefined// 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);
}undefined
---
---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%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% ❌| ❌ 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用户 | 逐步加压 |
| 测试时无监控 | 全链路监控 |
| 无基准线 | 建立并追踪趋势 |
| 一次性测试 | 持续性能测试 |
// 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");// 全面负载测试
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");aqe/performance/
├── results/* - Test execution results
├── baselines/* - Performance baselines
├── bottlenecks/* - Identified bottlenecks
└── trends/* - Historical trendsaqe/performance/
├── results/* - 测试执行结果
├── baselines/* - 性能基准线
├── bottlenecks/* - 已识别瓶颈
└── trends/* - 历史趋势const perfFleet = await FleetManager.coordinate({
strategy: 'performance-testing',
agents: [
'qe-performance-tester',
'qe-quality-analyzer',
'qe-production-intelligence',
'qe-deployment-readiness'
],
topology: 'sequential'
});const perfFleet = await FleetManager.coordinate({
strategy: 'performance-testing',
agents: [
'qe-performance-tester',
'qe-quality-analyzer',
'qe-production-intelligence',
'qe-deployment-readiness'
],
topology: 'sequential'
});