- Install
k6
- Write following js file (for example):
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
thresholds: {
http_req_duration: ['p(99)<1500'], // 99% of requests must complete below 1.5s
},
};
export default function () {
http.get('http://test.k6.io');
// Run other requests and check responses (or just response coce) using check function.
// You can add sleep even between your requests if needed.
sleep(1);
}
# For first time run with log to check requests and responses
k6 --http-debug my-script.js
# or even log request/response body
k6 --http-debug=full my-script.js
# Then if everything is ok, so run with more virtual-users and a duration
k6 --http-debug --vus 100 --duration 120s my-script.js
- Finally run with
stages
config (add stages
section to options
section of your script)
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
thresholds: {
http_req_duration: ['p(99)<1500'], // 99% of requests must complete below 1.5s
},
stages: [
{duration: '1m', target: 100},
{duration: '2m', target: 150},
{duration: '1m', target: 150},
{duration: '2m', target: 250},
{duration: '1m', target: 100},
{duration: '1m', target: 0},
],
};
export default function () {
http.get('http://test.k6.io');
// Run other requests and check responses (or just response coce) using check functions.
// You can add sleep even between each request if needed.
sleep(1);
}
- Run your test to run with the specified stages:
k6 my-script.js