Gatling is a powerful, open-source load-testing tool designed to analyze and measure the performance of web applications.
Introduction
Gatling is a powerful, open-source load-testing tool designed to analyze and measure the performance of web applications. It uses a simple and expressive domain-specific language (DSL) that allows you to define complex load-testing scenarios with ease.
Performance testing is a crucial aspect of ensuring that applications can handle a large number of users and requests without faltering.
Simulation
Create a new Kotlin file in the test ?? directory of your project.
Extend the Simulation class
Gatling scripts extend Simulation. Add the class declaration:
: }Define the HTTP protocol
Configure the target base URL and headers so Gatling knows how to talk to your application:
:
// Define HTTP configuration
// Reference: https://docs.gatling.io/reference/script/http/protocol/
val protocol .
.
}Key callouts:
http.baseUrl("http://localhost:8080")sets the server you will exercise.- Custom headers (user agent, accept) mimic a real browser. Adjust them when testing your own system.
Describe a scenario
Scenarios encode user journeys. Start with a single request:
: val protocol .
.
// Define scenario
// Reference: https://docs.gatling.io/concepts/scenario/
val scenario .
}Here you:
- Name the scenario (“BasicSimulation”).
- Issue a
GETrequest against /greeting with a query parametername=David.. - Leave room to add checks or additional steps later.
Choose an injection profile
Configure the arrival rate and duration for virtual users:
: val protocol .
.
val scenario .
// Define injection profile and execute the test
// Reference: https://docs.gatling.io/concepts/injection/
init this.
.
}
}This configuration launches 50 users per second for 15 seconds. Tweak the numbers once the script works.
Results
After running the simulation, Gatling generates an HTML report in the build/reports/gatling directory. You can analyze this report to understand the performance of your application under stress.