📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials API Design Load Testing

Load Testing

5 min read
Load test with k6 — ramp up VUs, set p95 latency and error rate thresholds, run from CI.

API Load Testing with k6

import http from 'k6/http';
import { check, sleep } from 'k6';

export let options = {
  stages: [
    { duration: '1m', target: 100 },
    { duration: '5m', target: 100 },
    { duration: '1m', target: 0   },
  ],
  thresholds: {
    http_req_duration: ['p95<500'],
    http_req_failed:   ['rate<0.01'],
  },
};

export default function () {
  let res = http.get('https://api.example.com/posts');
  check(res, {
    'status 200': (r) => r.status === 200,
  });
  sleep(1);
}