Performance Tester
Purpose
Identify performance bottlenecks and validate that systems meet SLOs under realistic and extreme load conditions.
Performance Test Types
| Type | Goal | When |
|---|---|---|
| Load test | Validate normal traffic | Before release |
| Stress test | Find breaking point | Capacity planning |
| Spike test | Handle sudden traffic | Event preparation |
| Soak test | Find memory leaks | Long-running validation |
| Smoke test | Basic sanity check | After deploy |
k6 Test Scripts
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Rate, Trend } from 'k6/metrics';
const errorRate = new Rate('errors');
const apiDuration = new Trend('api_duration');
export const options = {
scenarios: {
// Ramping load test
load_test: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '2m', target: 100 }, // Ramp up
{ duration: '5m', target: 100 }, // Sustain
{ duration: '2m', target: 200 }, // Increase
{ duration: '5m', target: 200 }, // Sustain
{ duration: '2m', target: 0 }, // Ramp down
],
},
},
thresholds: {
http_req_duration: ['p(95)<500', 'p(99)<1000'], // SLO: P95 < 500ms
errors: ['rate<0.01'], // Error rate < 1%
http_req_failed: ['rate<0.01'],
},
};
export default function() {
const res = http.get('https://api.example.com/posts', {
headers: { Authorization: `Bearer ${__ENV.API_TOKEN}` },
});
const success = check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
'has data': (r) => r.json().data !== undefined,
});
errorRate.add(!success);
apiDuration.add(res.timings.duration);
sleep(1);
}
Identifying Bottlenecks
# Profile running Node.js app
node --prof app.js
# Analyze flame graph
npx clinic flame -- node server.js
# Database slow query log
SET GLOBAL slow_query_log = 1;
SET GLOBAL long_query_time = 0.1;
# Profile PostgreSQL queries
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) SELECT ...;
Outputs
- k6 test scripts for all scenarios
- SLO definition (P95, P99 targets)
- Performance baseline report
- Bottleneck analysis
- Optimization recommendations
- Continuous performance monitoring setup