You are currently viewing K6 Load Testing in 2021

K6 Load Testing in 2021

  • Post author:
  • Post category:K6
  • Post comments:0 Comments

The best tool in 2021, I came across was doing Load Testing using K6. Story behind it, I was recently looking into the options for load testing tools. On a previous project we had used Load-runner. That worked well, and the reports were good, but now that I’m on a new team, I wanted to see what was out there. I was looking for something with which we could write tests in a more familiar language.

Along with K6, The tools I came across were these:

It was doubtful anyone on the team was gonna be familiar with Scala, nor am I a big Scala user. Python is probably the language I know the best, but only QAs use it here. The front-end folks all know JavaScript, and the API folks use Go, which pushed me more towards k6 and Vegeta.

All of these are open source by the way, and some have enterprise solutions.

It’s basically a github repo with a README and some instructions on how to install it, run it, etc.

k6 looked much more polished/full-featured. You write tests in JavaScript, it’s console output is clean, and it can output to DataDog, Kafka, and more.

Since k6 just looked friendlier to use, and I’m more familiar with JavaScript anyway, I decided to give it a whirl!

Taking K6 for a toast

If you’re on a Mac, you can just brew install k6

Sweet.

They also have a docker image which is also cool, but I went with brew for now.

I created a folder named k6 on my computer.

I created a script.js file and followed the documentation to get started.

K6 Sample Script

 

Sample Script

You might notice that I have a package.json file. I ran yarn init to initialize my project here expecting that I would have to install packages. But evidently, brew-installing k6 was enough and these imports worked 🤷‍♂️

more on this later 👀

Anyway…Now that I had created the script.js file, all I had to do was run it.

$ k6 run script.js

Results

 

1 User Results

Here, you can see that vus (virtual users) is 1 by default, as is vus_max.

If we want to up those numbers, we can pass them as options.

Results

 

10 User Results

This time, I had k6 run with 10 virtual users, and hit the server for 30 seconds.

Conclusion

As we showcased, getting started with k6 load testing.

By using a methodical approach, starting small and applying known principles you can now get started with performance testing using k6 as well!

About the Author

Pawan Sinha is a blogger whose interests in writing blogs on a day to day issues for any engineer working for a software company. To discuss his work, He has a background in Testing/DevOps/Engineering/Cloud/AWS/GCP. His portfolio.

Leave a Reply