Load Testing as Code with K6

overview of k6.io, an open-source load testing as code tool

2 min readNov 18, 2021

--

  1. Since you are here, load testing is probably a part of the software development life cycle . It is a great investment for finding bottlenecks of your app and ensuring that your application can perform as expected in production.

Even though JMeter is a fantastic community driven tool. I find it too complicated and might be too much for small applications.

For me personally after using K6, it is my favorite tool at this moment. I pretty much like the idea of load testing as code.

Why do I like K6 ?

  • Fast!
  • lightweight of Javascript (easy to ready)
  • Converting Postman collections to load test scripts
  • Recording sessions using HAR files

To get started, use this command to for windows to install K6 through Chocolatey package manager :

choco install k6

Create a file called script.js and past the following code :

run the following command:

k6 run script.js

InfluxDB + Grafana

We can use Grafana for visualization of our k6 metrics (download here), to do so, we need to upload our test result metrics to InfluxDB. It is an open source time series platform for storing and querying data. (docker for installation).

after running InfluxDB, run this command

k6 run — out influxdb=http://localhost:8086/myk6db script.js

port 8086 is the default port for InfluxDB and myk6db is the name of database.

after installing Grafana, go to http://localhost:3000 (the default port). then create a new data source with database name myk6db.

import new dashboard, use 2587 ID. then select our myk6db as data source.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response