k6 - The Best Developer Experience for Load Testing

The performance testing industry has experienced a radical transformation in recent years. Traditionally, load testing has been performed by performance testing engineers, as well as QA engineers and testers. These roles usually worked as independent units, doing performance testing once the developers had finished building the applications.

With the adoption of agile principles among software development teams, performance testing as activity starts much earlier in the development process, so-called shift-left testing. Instead of leaving performance testing to the QA department, software teams now do their testing independently or in collaboration with the QA engineers.

Another benefit of shifting the testing left is a growing increase in the adoption of performance testing in software teams. But many of these new users demand tools that fit nicely into their everyday workflow, allowing them to test regularly with minimal effort. Traditional tools like JMeter and LoadRunner didn’t fit that well, and instead, they are turning to a new generation of tools, like k6.

Unveiling k6

k6 is a free and open-source load testing tool aiming to make performance testing a productive and enjoyable experience.

The tool is scriptable, and k6 tests are written in Javascript, giving the ability to write your tests in one of the most well-known programming languages around.

A powerful scripting language and API present the necessary flexibility to mimic real-world scenarios in your scripts. Since applications and systems continuously evolve, having the ability to modularize your tests will dramatically enhance the efficiency of your testing process.

/assets/images/carbo-k6-gist1.png

k6 is a Command Line Tool available for Windows, Linux, and Mac. Alternatively, there is an official Docker image.

Running a performance test with k6 is as simple as running a bash command:

/assets/images/carbo-k6-gist2.png

A few notable scripting features are:

  • Robust and well-documented Javascript APIs for test scripting
  • Deep customization through multiple configuration options
  • Scenarios
  • Parameterization through environment variables
  • Websockets support
  • Lifecycle hooks for customizing setup and teardown
  • Checks, metrics, tags, Cookies…

Session recorder & converters

As most sophisticated load testing tools, k6 has a session recorder that facilitates the creation of load tests from a user session. You only need to provide a HAR file from a browser or user session, and the recorder will create the k6 test for you. This is particularly helpful if you are load testing websites.

Additionally, other tools can help you to autogenerate k6 tests from different technologies:

  • JMeter converter: convert a JMeter .jmx file to k6 script.
  • Postman converter: convert a Postman collection to k6 script.
  • OpenAPI converter: convert Swagger/OpenAPI specification to k6 script.
  • Browser extension: generate a k6 script from a browser session. Only available for users of the k6 Cloud.

Although you don’t need to use the recorder and converters to start testing, these tools could help to onboard your team into k6, or script your tests, faster.

Session recorder and converter

Result visualization

By default, k6 outputs the result to the console. Additionally, several integrations are available to help you during the analysis and visualization of your test results:

  • Apache Kafka
  • k6 Cloud
  • DataDog
  • InfluxDB + Grafana
  • JSON
  • NewRelic
  • StatsD

/assets/images/result_visualization@3x.png

Continuous and automated testing

In the testing community, automation is the end-goal for many organizations. When your application and system changes, automating and running frequent tests will help you catch performance regressions earlier.

The documentation provides guides for most popular CI/CD tools, allowing you to effortlessly integrate k6 into your CI pipelines.

  • Azure Pipelines
  • CircleCI
  • GitHub Actions
  • GitLab
  • Jenkins
  • TeamCity

The k6 team believes that making testing goal-oriented is an indispensable requisite for automation. When running automated tests, your test’s primary purpose should be first to validate the performance expectations of your system, and second, to alert you if the system does not meet the performance goals. For example, validating that:

  • The response time for 95% of requests is not above 600ms.
  • The system does not produce more than 0.5% errors.

In k6, you define these expectations with Thresholds in your test. If your system does not reach them, k6 will inform you about the failure returning a non-zero exit code.

/assets/images/carbo-k6-gist3.png

If you want to learn more about this topic, read the k6 guide for performance testing automation and the Thresholds documentation.

k6 Cloud

k6 Cloud is the commercial SaaS product that accompanies the open-source k6 tool. k6 OSS is free to use and has several integrations to manage load tests in your own infrastructure. The k6 Cloud is an optional service that provides the load testing infrastructure and systems to help you with your performance testing efforts.

To understand better what the k6 Cloud is, let’s enumerate a few of its features:

  • Scale tests horizontally and in different geographic locations.
  • Store and visualize test results.
  • Detect performance issues automatically.
  • Correlate results between various tests.
  • Onboard users with the GUI test builder.
  • Organize teams and tests in a central location.
  • Provide dedicated support.

k6 Cloud

Community

The k6 community is genuinely supportive and helpful - the force behind the success of the project.

If you are starting with k6, do not forget to reach them in Slack or the community forum for any type of questions. There are several channels and categories for different topics like #grafana, #documentation, #feedback, #discussion, etc.

For those interested in the internals of the project, follow the project in GitHub.

Conclusion

This post aims to present an intro of k6 - one of the most exciting load testing tools. If you want to learn what more has k6 to offer, we recommend reading the k6 Docs.

With only four years of life, k6 has become feature-rich and competes with well-established tools, gaining stellar adoption in developers, DevOps, and testing communities.

The k6 team and community have built a developer-centric performance testing tool that meets the demand and needs for a new era.