Manuals / Performance Testing Basics / Ch 4

B · ExecuteIntermediate45 min read

4. Script a load test (k6 lite)

Performance Testing Basics · 36 pages source format

Virtual users, thresholds, stages. Start tiny. Grow. Watch errors before celebrating RPS.

What you'll learn

  • VUs & iterations
  • Thresholds
  • Stages

First script

HIT a safe endpoint. Check status. Threshold on http_req_failed and p95.

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

export const options = {
  stages: [
    { duration: '30s', target: 5 },
    { duration: '1m', target: 5 },
    { duration: '30s', target: 0 },
  ],
  thresholds: {
    http_req_failed: ['rate<0.01'],
    http_req_duration: ['p(95)<800'],
  },
};

export default function () {
  const res = http.get('https://test.k6.io');
  check(res, { 'status 200': (r) => r.status === 200 });
  sleep(1);
}

Do this now

Run a 1-minute smoke. Then a small load stage.

Pro tip. Use test.k6.io or your staging — not random public sites at scale.

Clear?

Checklist