Manuals / Performance Testing Basics / Chapter 4

B · Execute · intermediate · Week 2 · Chapter 4 of 9

Script a load test (k6 lite)

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

Path progress
44%

Step 1 of 1

First script

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

First scriptDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →First scriptdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Example

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.

Was this step clear?
Chapter learning outcomes
  • VUs & iterations
  • Thresholds
  • Stages

Clear these before you leave