info@brightest.be
+32 3 450 88 42

Technical Thursday

k6

Posted by: Berte Verhoeven
Category: Performance testing
If you’re looking to test how performant your application is, your test tool should be performant, right? This makes sense. Well, allow us to introduce you to k6. An open-source, high-performing load testing tool, scriptable in JavaScript.

About

Initially, LoadImpact released k6 as an open-source alternative to their own proprietary tool. As the early adoption was so successful and the community quickly grew, the guys knew they had something special on their hands. So, they decided to rebrand the company to k6.
Fast forward to 2021. Their merger with open-source analytics leaders, Grafana Labs, has strengthened the company’s position.

Why k6?

k6 is a load testing tool for developers and testers in the DevOps era. With the modern methodologies where Agile is being widely adopted and DevOps is knocking on the door to become the next best thing, developer roles are stepping into the testing process more and more.

As organizations are starting to shift left, there’s a need for the testing process to become faster, more efficient and of higher quality. We can achieve this by introducing the rights tools that enable developer participation and will allow us to really implement continuous testing. k6 is that tool because it supports a scripting language, JavaScript, so developers can create, maintain and collaborate on end-to-end tests efficiently.

Who tests the test tools?

Obviously, tool performance is just as important as the performance of your test subject. One of the things that sets k6 apart from other popular open-source performance testing tools is… its performance.

k6 vs. JMeter

k6 was developed with performance in mind and written in Go. Let us compare its performance with another tool, for example our trustworthy, popular friend JMeter.
JMeter is developed in Java and known to be quite memory hungry. If you ever worked with JMeter, you’re probably familiar with the “Out Of Memory” error. k6 on the other hand likes memory but isn’t as greedy. Depending on different test scenarios it uses ~1-5MB per VU.

In terms of efficiency, a single k6 process will be able to use all CPU cores on a load generator machine. A single instance of k6 is often enough to generate load of 30,000-40,000 simultaneous users (VUs).

Less resources

So, what does all this mumbo-jumbo mean I can hear you say? Well, to explain it in terms everyone understands; k6 is cheaper. It needs less resources to do more so you can save money on infrastructure costs.

Pros and cons

Pros

Apart from its performance, another strength of the tool is that it integrates well with many solutions to visualize the results. As we all know, running tests is one thing. But having the results and being able to visualize and compare them, that’s what is important.

k6 exports to filetypes like JSON and CSV. But it is also able to leverage Grafana solutions like Grafana cloud or a local InfluxDB, as well as other solutions like Datadog, Netdata or New Relic.

Cons

One of the things that could be considered a downside of k6 is that it does not have a GUI in the OSS version. Something like JMeter is GUI driven which makes it more all-round user-friendly. While k6 is script driven which is often reserved for the more advanced users.
It is possible to use the test builder as a GUI, but this is only available in the k6 cloud offering, so you need a k6 Cloud account to use it. However, it is free, and you do not need an active subscription to utilize this feature. k6 Cloud is a managed performance testing solution to build tests, launch them from different geographic locations and visualize the results.

Another potential weakness is the protocols that are natively supported. k6 supports HTTP/1.1, HTTP/2, WebSockets, gRPC and SOAP / REST Webservices.
Looking at JMeter again, it supports a lot more protocols out-of-the-box and even more through plugins.

grafana-dave

Conclusion

k6 is an open-source solution that integrates with other open-source tools and developer ecosystems. It allows automated testing to fit nicely into the software delivery cycles. If you’re looking for a performant, code driven load testing tool, why not give it a try? But ultimately keep in mind there’s no best tool; there’s only the right tool for your project and context.

Written by Joren Molenaers