Performance
Load Testing
Validate API performance under load. Use k6 or Gatling to run smoke tests, load tests, stress tests, and capacity planning.
< 200ms
Response Time (P95)
< 500ms
Response Time (P99)
> 1000 RPS
Throughput
< 0.1%
Error Rate
> 99.9%
Availability
Load Test Profiles
| Profile | VUs | Duration | Use Case |
|---|---|---|---|
Smoke Test Minimal load to verify system works | 1-5 | 1 min | CI/CD validation |
Load Test Expected production traffic | 50-200 | 10-30 min | Baseline performance |
Stress Test Beyond normal capacity | 200-1000 | 30-60 min | Find breaking points |
Spike Test Sudden traffic bursts | 10→1000→10 | 5-10 min | Elasticity testing |
Soak Test Extended duration load | 100-200 | 4-12 hours | Memory leaks, degradation |
k6 Load Test Script
Modern load testing with JavaScript. Run locally or in the cloud.
loadtest.js
// k6 Load Test Script for JustKalm API
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Rate, Trend } from 'k6/metrics';
// Custom metrics
const errorRate = new Rate('errors');
const valuationDuration = new Trend('valuation_duration');
// Test configuration
export const options = {
stages: [
{ duration: '2m', target: 50 }, // Ramp up
{ duration: '5m', target: 100 }, // Steady state
{ duration: '2m', target: 200 }, // Stress
{ duration: '1m', target: 0 }, // Ramp down
],
thresholds: {
http_req_duration: ['p(95)<200', 'p(99)<500'],
errors: ['rate<0.01'],
valuation_duration: ['p(95)<300'],
},
};
const API_BASE = 'https://api.justkalm.com';
const API_KEY = __ENV.JUSTKALM_API_KEY;
const products = [
{ brand: 'Louis Vuitton', category: 'bags', condition: 'excellent' },
{ brand: 'Rolex', category: 'watches', condition: 'good' },
{ brand: 'Hermès', category: 'bags', condition: 'new' },
{ brand: 'Cartier', category: 'jewelry', condition: 'excellent' },
];
export default function() {
const product = products[Math.floor(Math.random() * products.length)];
const startTime = Date.now();
const response = http.post(
`${API_BASE}/v1/valuations`,
JSON.stringify(product),
{
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
}
);
valuationDuration.add(Date.now() - startTime);
const success = check(response, {
'status is 200': (r) => r.status === 200,
'has valuation id': (r) => JSON.parse(r.body).id !== undefined,
'has estimated value': (r) => JSON.parse(r.body).estimated_value !== undefined,
});
errorRate.add(!success);
sleep(Math.random() * 2 + 0.5); // 0.5-2.5s think time
}# Run the load test k6 run --env JUSTKALM_API_KEY=sk_test_... loadtest.js # Run with cloud execution k6 cloud loadtest.js
Best Practices
Run in CI/CD
Execute smoke tests on every deployment
Use Realistic Data
Feed tests with production-like payloads
Set Baselines
Establish performance baselines before changes
Monitor During Tests
Watch metrics in real-time for anomalies
Test from Multiple Regions
Validate latency from user locations
Schedule Regular Tests
Weekly soak tests catch regressions