Using K6 for the most common types of performance tests

5 min read
using k6 for the most common types of performance tests zen8labs

What is performance testing?

Performance testing is crucial for ensuring that software applications are stable, scalable, and reliable. The world today is a faster and more responsive world, it’s more important than ever to make sure your application can handle the pressure. This is where performance testing shines, by validating how an application behaves under different levels of demand.

The three most common types of performance tests include stress testing, load testing, and spike testing. Unlike functional tests, which ensure that the web app works as expected, performance testing focuses on how the app behaves when the demand on the system increases. They are typically classified as “non-functional” tests.

Spike, load, and stress testing

Load testing: Simulating real-world traffic

Load testing measures how your system performs under expected traffic loads. The goal here is to simulate real-world conditions to ensure your app can handle the anticipated number of users without slowing down or breaking.

For instance, if you expect your website to handle 1,000 users per minute during peak times, a load test will simulate that traffic to see how your system responds. The test will assess performance metrics like response times, throughput, and server resource usage under the specified load.

Load testing helps identify performance bottlenecks, such as slow database queries or limited server capacity, long before your application reaches production. This ensures your system is optimized for smooth performance under normal traffic conditions.

Spike testing: Preparing for the unexpected

Spike testing addresses how your system handles sudden and unpredictable traffic surges. Similar to that of a load test, it measures the performance under strain, but it does so by simulating sudden and fluctuating bursts of traffic. For example, instead of a steady 1,000 users per minute, a spike test might simulate 4,000 users in the first minute, followed by a sudden drop to zero users, and then another surge of 6,000 users after a short period.

The key difference between spike testing and stress testing is that spike tests don’t aim to crash the system. Instead, they ensure your system can handle and recover from these sudden spikes in traffic. Spike testing helps you anticipate unexpected traffic patterns and gives insights into how your system will react during sudden bursts.

Stress Testing: Pushing to the breaking point

Stress testing, on the other hand, is all about determining your system’s limits. This type of test pushes your application beyond its normal operational capacity to find its breaking point. For example, if your app typically handles 1,000 users per minute, a stress test would increase that number progressively until your system starts to fail, perhaps at 1,300 or 12,000 users.

Stress tests show you two critical pieces of information: (1) the maximum number of users your system can handle before it crashes, and (2) where bottlenecks are occurring. The goal is not only to find the failure point but also to measure how quickly and effectively the system recovers.

K6 the modern tool for performance testing

K6, was introduced by Grafana Labs in 2021. It is an advanced performance testing tool that offers several advantages over older tools such as JMeter. Built with modern technologies, K6 provides speed, efficiency, scalability, and flexibility in scenario creation, along with rich output and reporting.

One of the key features of K6 is its efficient design. While many legacy tools struggle to adapt to new technologies, K6 is developed with the Go programming language, making it faster and easier to use. It provides a command-line interface (CLI) that simplifies the process of writing and running performance tests. This means you can focus on running efficient tests without being bogged down by complex configurations.

Key concepts in K6

When running tests with K6, there are a few essential parameters to define. These parameters are set within the Options object, and they help control how your tests are executed. 

  • VUs (Virtual Users): The number of users simulated during the test.
  • Iterations: The number of times each virtual user will repeat the scenario. 
  • Duration: How long the test will run, typically measured in milliseconds.
  • Checks: Response validation, similar to assertions in traditional tests.
  • Thresholds: The performance thresholds set for the test, where exceeding them may mark the test as failed.

These settings allow you to create a wide range of performance test scenarios tailored to your needs.

Scenarios and executors in K6

K6 testing zen8labs

In K6, an executor controls how the load is applied during a test. This flexibility lets you simulate various real-world scenarios under different performance testing methodologies:

  • Smoke Tests: Low VUs for 1–5 minutes, ensuring basic functionality under light load.
  • Load Tests: Average VUs for 10–60 minutes, testing sustained performance under expected traffic. 
  • Stress Tests: High VUs for 1–2 hours, pushing the system to its limits.
  • Spike Tests: Very high VUs for short periods, testing how the system handles sudden spikes.
  • Breakpoint Tests: Gradually increasing VUs over time to find the system’s breaking point.

These methodologies give you control over how the load is distributed, helping you better understand how your application performs under different conditions.

Visualizing K6 metrics: Real-time monitoring

One of the most powerful features of K6 is the ability to visualize test results in real-time. Instead of simply analyzing metrics in a text format, you can monitor live data directly on your local machine. This real-time insight allows you to catch performance issues as they happen.

K6 integrates with several platforms, such as Prometheus, Datadog, and Amazon CloudWatch, among others. This flexibility allows you to store and visualize your test results easily, providing a deeper understanding of how your application behaves under load.

zen8labs using k6 for the most common types of performance tests.

Conclusion

Ensuring your application can handle varying levels of user traffic is essential to maintaining performance and user satisfaction. With performance testing, particularly load, spike, and stress tests, you can simulate real-world conditions and push your system to its limits to identify bottlenecks before they affect your users.

K6 stands out as a versatile and user-friendly tool for executing these tests, offering a modern approach with easy scripting, robust scenarios, and real-time monitoring. By using K6, you gain valuable insights into how your system performs under different conditions, helping you optimize resources, improve scalability, and ensure a great user experience.

As you integrate K6 into your testing practices, you’ll not only catch potential issues early but also prepare your system for the unpredictable. Whether it’s anticipating traffic spikes or managing steady growth, performance testing with K6 is a crucial part of delivering reliable, high-performing applications. 

Overall, performance testing is an essential part of ensuring your application’s stability and scalability. Whether you’re preparing for unexpected traffic with spike testing, pushing your app to its limits with stress testing, or using K6 for modern, efficient testing, the insights you gain will help you create a more robust and resilient system. If you want help to carry out your own performance test or any other type of IT consulting, then zen8labs is here for you.

Hung Do, Head of Solutions

Related posts

When selecting a technology stack for a new project, developers often need substantial time to evaluate various options. The process from initiation to achieving a stable codebase can be daunting, especially for projects requiring rapid development. With Supabase, zen8labs' team has managed to expedite this process while providing scalability and stability for our projects.
5 min read
What is the CSS happy learning path and how does it affect javascript developers? Then this blog is for you to show you the ways that CSS can offer you a happy learning experience.
5 min read
Scaling a web application transcends mere technical challenges - In our latest blog we look at how to improve the system design of a website to allow us to go from zero users to millions of users in a professional manner.
7 min read