Performance Test
Goals theo strategy
- Confirm SLA met (p95 latency < 500ms).
- Identify bottleneck.
- Validate scaling.
- Pre-launch confidence.
Tools comparison
| Tool | Strengths | Weakness |
|---|---|---|
| JMeter | GUI, mature, free | Heavy, hard to version |
| k6 | JS code, lightweight | Newer |
| Gatling | Scala, performant | Less popular |
| Locust | Python, distributed | Python overhead |
| Artillery | YAML config | Less feature |
Test script ví dụ k6
import http from 'k6/http';
import { check, sleep } from 'k6';export const options = {
stages: [
{ duration: '30s', target: 100 },
{ duration: '2m', target: 100 },
{ duration: '30s', target: 0 },
],
};
export default function () {
const res = http.get('https://api.vietnamcos.com/courses');
check(res, { 'status 200': (r) => r.status === 200 });
sleep(1);
}
Metrics track
- Response time (avg, p50, p90, p95, p99).
- Throughput (RPS).
- Error rate.
- CPU, memory, disk, network on server.
Common bottleneck
- DB query slow (missing index).
- N+1 query.
- External API blocking call.
- Memory leak under load.
- Connection pool exhausted.
VN benchmark
- E-com normal: 500-5000 RPS.
- Tết spike: 10× normal.
- Banking: 100-1000 TPS, p99 < 1s.
Setup
- Isolated env, not staging shared.
- Production-like resource (or scaled-down with multiplier).
- Realistic data volume (1M+ records, not 100).