Loadtest web service with k6

First install k6 in your system. We will go for Linux (Ubuntu).
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61echo "deb https://dl.bintray.com/loadimpact/deb stable main" | sudo tee -a /etc/apt/sources.listsudo apt-get updatesudo apt-get install k6
Open any IDE for writing test code. We will use WebStorm. To enable code suggestion for k6, install this library with npm:
$ npm init --yes# install the k6 types as dev dependency$ npm install --save-dev @types/k6
For showing visual chart while the test is running, we have some of the methods:
- Amazon CloudWatch
- Apache Kafka
- InfluxDB + Grafana
- Cloud
- CSV
- Data Dog
We will use InfluxDB and Grafana for visualization.
Install InfluxDB with Docker
docker run -p 8086:8086 \
-v $PWD:/var/lib/influxdb \
influxdb
Install Grafana as service in Ubuntu
sudo apt-get install -y adduser libfontconfig1
wget https://dl.grafana.com/oss/release/grafana_7.3.4_amd64.deb
sudo dpkg -i grafana_7.3.4_amd64.deb
Example code to run
Here we run the test with GraphQL API, set the virtual user for running as:
export let options = {
vus: 1000,
duration: '300s',
};
Run the test and we will see the dashboard on grafana:
k6 run --insecure-skip-tls-verify --out influxdb=http://localhost:8086/k6db script.js
(Skip tls security
--insecure-skip-tls-verify
)

Hope it helps.
~~PEACE~~