Load & Performance
k6, JMeter, and Stress Testing.
Load Testing
Functionality is pointless if the server crashes at 10 users.
Types of Performance Tests
- Load Test: Simulate expected usage (e.g., 100 users). Verify response time stays low.
- Stress Test: Increase load until it breaks. Find the breaking point (e.g., "We die at 5000 users").
- Soak Test: Run load for 24 hours. Finds memory leaks.
- Spike Test: Sudden burst (Black Friday). Does autoscaling kick in fast enough?
Tools: k6
The modern standard. Written in Go, scripted in JavaScript.
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 100, // Virtual Users
duration: '30s',
};
export default function () {
const res = http.get('https://test-api.com');
check(res, { 'status was 200': (r) => r.status == 200 });
sleep(1);
}Interpreting Results
- Throughput: Requests per second (RPS).
- Latency (P95/P99): "99% of users saw a response faster than X".
- Average is useless. If 50% get 100ms and 50% get 10s, the average is 5s, which looks okay, but half your users are angry. Look at P99.