Performance Testing
When to Use
When you need to validate that a system can handle expected load, find bottlenecks before users do, or establish performance baselines.
Core Jobs
1. Define Performance Requirements
Before testing, specify:
- Throughput target: X requests/sec at peak
- Latency target: P95 < Nms, P99 < Nms
- Error rate target: < X% under load
- Duration: how long must it sustain this load?
Without these, you don't know if your test passed.
2. Write Load Test Scripts
k6 example:
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '2m', target: 50 }, // ramp up to 50 users
{ duration: '5m', target: 50 }, // stay at 50
{ duration: '2m', target: 100 }, // ramp to 100
{ duration: '5m', target: 100 }, // stay at 100
{ duration: '2m', target: 0 }, // ramp down
],
};
export default function () {
const res = http.get('https://api.example.com/users');
check(res, { 'status was 200': (r) => r.status === 200 });
sleep(1);
}
3. Run and Observe
During the test, watch:
- Latency trend (is it flat or climbing?)
- Error rate
- CPU and memory on the server
- Database connection pool utilization
- Queue depths (if async)
The throughput "knee" = where latency starts degrading rapidly. Don't target above this.
4. Profile and Fix Bottlenecks
When tests fail:
- Use APM (Datadog, New Relic) to find slow traces
- Database: check slow query log, explain plan, missing indexes
- CPU: profile with py-spy, pprof, or async-profiler (JVM)
- Memory: heap dump analysis
Key Outputs
- Load test script (version controlled)
- Performance requirements document
- Test results report (percentile breakdown)
- Bottleneck analysis and fixes
Anti-Patterns
- Testing without defined pass/fail criteria
- Testing average load only (not peak or spike)
- No profiling when tests fail — "we need more servers" is rarely the fix
- Running performance tests against production
1---2name: performance-testing3description: Use when load testing APIs, profiling bottlenecks, or validating performance SLAs before release4---56# Performance Testing78## When to Use9When you need to validate that a system can handle expected load, find bottlenecks before users do, or establish performance baselines.1011## Core Jobs1213### 1. Define Performance Requirements14Before testing, specify:15- **Throughput target**: X requests/sec at peak16- **Latency target**: P95 < Nms, P99 < Nms17- **Error rate target**: < X% under load18- **Duration**: how long must it sustain this load?1920Without these, you don't know if your test passed.2122### 2. Write Load Test Scripts23k6 example:24```javascript25import http from 'k6/http';26import { check, sleep } from 'k6';2728export const options = {29 stages: [30 { duration: '2m', target: 50 }, // ramp up to 50 users31 { duration: '5m', target: 50 }, // stay at 5032 { duration: '2m', target: 100 }, // ramp to 10033 { duration: '5m', target: 100 }, // stay at 10034 { duration: '2m', target: 0 }, // ramp down35 ],36};3738export default function () {39 const res = http.get('https://api.example.com/users');40 check(res, { 'status was 200': (r) => r.status === 200 });41 sleep(1);42}43```4445### 3. Run and Observe46During the test, watch:47- Latency trend (is it flat or climbing?)48- Error rate49- CPU and memory on the server50- Database connection pool utilization51- Queue depths (if async)5253The throughput "knee" = where latency starts degrading rapidly. Don't target above this.5455### 4. Profile and Fix Bottlenecks56When tests fail:57- Use APM (Datadog, New Relic) to find slow traces58- Database: check slow query log, explain plan, missing indexes59- CPU: profile with py-spy, pprof, or async-profiler (JVM)60- Memory: heap dump analysis6162## Key Outputs63- Load test script (version controlled)64- Performance requirements document65- Test results report (percentile breakdown)66- Bottleneck analysis and fixes6768## Anti-Patterns69- Testing without defined pass/fail criteria70- Testing average load only (not peak or spike)71- No profiling when tests fail — "we need more servers" is rarely the fix72- Running performance tests against production