Get Started with K6
K6 is a lightweight open source load generator and testing suite which can can be used to verify expected behaviors are occurring across your infrastructure. This document will cover setting up a basic test script to generate load against a DNS record.
Install K6
K6 Is available on Linux, MacOS, Windows, and as a Docker container. K6 can be installed at K6: Getting Started.
Run the below command to verify your installation was successful:
k6 version
Example:
k6 v0.39.0 ((devel), go1.18.3, darwin/arm64)
Write a Basic Test Script
Our first test script will make GET requests against an IP address or domain
name based on a number of variables we will provide. Start by copying the below
template to a new file named basic-test.js
:
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
http.get('https://domain.tld/'); # Required: Domain or IP to Test
sleep(1); # Required: Desired Sleep in Seconds
}
Now, we will add the two basic variables which should be set in any test: Domain, VUs (virtual users), Sleep Time (time between VU runs) and Test Duration.
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
vus: 10, # Required: Virtual Users as an Integer
duration: '60s', # Required: Test Duration in Time
}
export default function () {
http.get('https://domain.tld/'); # Required: Domain or IP to Test
sleep(1); # Required: Desired Sleep in Seconds
}
Run a K6 Test Script
To run your test, execute the below command with the name of your test script.
In our case this is basic-test.js
:
k6 run basic-test.js
To stop the basic-test.js
script execution early, enter Ctrl-C
. The test script
will exit and the test statistics will be displayed. Read the full K6
Documentation.