Load testing is an important step in verifying that an application can withstand the demands of real-world usage. Users today access applications to perform various tasks. Most of the time, the application behaves well. However, if the system is not designed to handle increased traffic, for example during peak hours, it may cause performance issues such as slow response times, server crashes, or unresponsiveness.
Hence, it is important to simulate these scenarios and identify potential performance bottlenecks before adversely affecting the user experience.
In this blog post, we'll look at Gatling, a load testing tool, and see how we can use Gatling with Testkube for load testing in Kubernetes.
Load testing ensures an application can withstand expected user traffic without affecting performance. In a situation where multiple users are using the application simultaneously, it helps identify potential issues such as slow response times, server crashes, or lack of responsiveness.
Load testing simulates real-world traffic to identify performance bottlenecks and improve the application’s performance and user experience before deployment.
Some of the benefits include:
In addition to its considerable advantages in terms of scalability and performance, it also introduces complexity in terms of configuration, execution, aggregation of results, etc.
Gatling is a powerful load testing solution designed to analyze and measure the performance of web applications under varying levels of load. Load testing primarily determines how the application behaves when exposed to various traffic loads, ensuring it can manage the expected user load without experiencing performance degradation.
Load testing, particularly with Gatling, displays actual traffic and how the application performs in that traffic situation. This enables developers to identify performance bottlenecks and optimize application scalability and overall user experience before deploying the application in production.
Besides simulating real-world behavior, Gatling helps identify potential bottlenecks and performance issues, enabling you to resolve them before they adversely affect users.
Gatling can run as a standalone tool and even supports integration with various build tools like Gradle and Maven and CI/CD tools like GitLab and Jenkins.
Refer to the Gatling documentation for more information.
While Gatling is powerful, load testing comes with several challenges that need to be managed to ensure accurate and efficient execution. The following are some challenges we generally encounter while performing Gatling load testing:
Testkube is a test orchestration platform that supports the execution of any testing tool in a containerized application infrastructure. It leverages Kubernetes to provide a scalable and consistent execution environment for all your tests and includes a unified dashboard for test definition, reporting, and troubleshooting.
Testkube makes load testing in Kubernetes environments easier, allowing you to ensure that your application can withstand loads and perform consistently.
Learn more about Test Workflows and how they help developers create complex tests quickly by centralizing and streamlining the testing process.
We’ll now look at creating a simple Gatling test workflow using Gradle in Testkube. The test code and related files are in our Gatling Test repository.
For a visual walkthrough of this tutorial, you can watch the accompanying video below before diving into the written instructions and prerequisites.
Once the prerequisites are met, you can launch a target Kubernetes cluster with a configured Testkube agent.
Navigate to the test workflow section and click the “Add New Test Workflow” button.
A “Create a Test Workflow” dialog appears that provides you with four options to create a test workflow:
Choose the “Create from Wizard” option to create this workflow.
Enter the following information into the designated field of the “Name & Type” tab:
Click Next.
In the “Content” tab, choose “Git” as the content source from the drop-down menu and then provide the following information:
Click Next.
In the “Run” tab, provide the following information:
Click Next. The Summary tab will open, showing you the generated spec file.
The entire workflow specification is available in YAML format. To set up and execute the test workflow, click the "Create & Run" button.
After you click on “Create & Run”, the test workflow will start being executed.
To check real-time progress and logs, click on each step in the test procedure. After the execution, Testkube collects all artifacts, including a Gatling stats report with all of the results and outputs.
Click the "Artifacts" tab and then select the.html file to view the logs in a new tab.
This was a simple demonstration of how to use test workflows for Kubernetes testing. To maximize the benefits of test workflows, you can create complex test workflows or import custom workflows into Testkube.
Let's analyze the Gatling Test Workflow that was used to set up and carry out this test:
kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
name: gradle-testkube-simple
namespace: testkube
labels:
test-workflow-templates: "yes"
spec:
use:
- name: official--gradle--v1
config:
run: ./gradlew gatlingRun
version: 8.7.0-jdk21-alpine
content:
git:
uri: https://github.com/kubeshop/testkube-examples/
revision: main
paths:
- Gradle/Gatling/Simple
container:
workingDir: /data/repo/Gradle/Gatling/Simple
steps:
- name: Saving artifacts
condition: always
artifacts:
paths:
- /data/repo/Gradle/Gatling/Simple/build/reports/**
status: {}
The spec file includes the following components:
This article describes the importance of load testing and how to use Gatling to create simple load tests that withstand real-world traffic scenarios. Using Gatling for load testing ensures that web applications are optimized for performance and can handle the expected loads from users. Gatling can also be used for distributed load testing. To learn more about this, read our next article “Distributed Load Testing with Gatling and Testkube on Kubernetes”.
Running Gatling tests with Testkube provides lots of benefits from making it Kubernetes native to giving you more control and flexibility over your tests.
Get started with Testkube today, or visit the Testkube documentation to learn more about running distributed tests in Testkube using other testing tools. If you find yourself struggling with anything, feel free to drop a note in our active Slack community, and someone will help you out. Need to generate heavy load to test your application? Follow
Testkube is a test execution and orchestration framework for Kubernetes that works with any CI/CD system and testing tool you need, empowering teams to deliver on the promise of agile, efficient, and comprehensive testing programs by leveraging all the capabilities of K8s to eliminate CI/CD bottlenecks, perfecting your testing workflow. Get started with Testkube's free trial today!
Related topics: