Skip to main content

Performance testing

Performance tests use k6, an open-source load-testing tool driven from the command line, with test scripts written in JavaScript. Install k6 before you start.

A first script​

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

export const options = {
vus: 10, // virtual users
duration: '30s', // test duration
};

export default function () {
const res = http.get('https://openent.example.org/api/endpoint');
check(res, {
'status was 200': (r) => r.status === 200,
'response time was < 500ms': (r) => r.timings.duration < 500,
});
sleep(1);
}
  • options sets the number of virtual users and the duration.
  • check asserts on each response, here the status code and the response time.
  • sleep pauses between iterations, as a real user would.

Run it:

k6 run script.js

Reading the results​

k6 prints its metrics as the test runs and a summary at the end.

MetricMeaning
http_req_durationResponse time: average, minimum, median, maximum and percentiles
http_req_failedShare of requests that failed
vusVirtual users currently active
iteration_durationTime taken by one full iteration of the script
checksShare of assertions that passed

Ramping the load​

Stages raise and lower the number of virtual users over time:

export const options = {
stages: [
{ duration: '1m', target: 20 },
{ duration: '3m', target: 50 },
{ duration: '2m', target: 0 },
],
};

Scenarios run several load profiles in the same test, each with its own executor, number of virtual users and duration.