A Gatling simulation is a self-contained program that describes who does what, for how long, and at what rate. It is made up of three components: an HTTP protocol configuration that establishes connection defaults, a scenario that encodes a user journey as a sequence of HTTP requests, and an injection profile that controls how virtual users are introduced over time. This tutorial walks through each component in sequence — starting from a bare file and finishing with a complete, runnable simulation that targets the Gatling demo e-commerce API atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/gatling/gatling.io-doc/llms.txt
Use this file to discover all available pages before exploring further.
https://api-ecomm.gatling.io.
This tutorial targets the Gatling demo API at
https://api-ecomm.gatling.io. This endpoint is public and read-only — safe to use freely for learning and experimentation.Before You Begin
Make sure Gatling is installed and the demo project is cloned. If you haven’t done that yet, complete the Installation Guide first, then return here.- Java prerequisites
- JavaScript prerequisites
- 64-bit OpenJDK LTS 11–25 installed (Java 17 or 21 recommended)
- Demo project cloned:
https://github.com/gatling/se-ecommerce-demo-gatling-tests.git - Working directory:
se-ecommerce-demo-gatling-tests/java/maven
Build the Simulation Step by Step
Set Up the File and Imports
Open the starter simulation file in your IDE. Delete any placeholder content below the import statements so only the package declaration and imports remain.
- Java
- JavaScript
File: The static imports bring all Gatling DSL methods (
src/test/java/example/BasicSimulation.javascenario, http, constantUsersPerSec, etc.) into scope without needing to qualify them. The class imports provide the builder types (ScenarioBuilder, HttpProtocolBuilder, Simulation).Declare the Simulation Class or Function
Every Gatling simulation has a top-level container. In Java, your class extends
Simulation. In JavaScript, you export a simulation() call.- Java
- JavaScript
The class name (
BasicSimulation) must match the filename (BasicSimulation.java) and the fully qualified class name you pass to gatling:test -Dgatling.simulationClass=example.BasicSimulation.Define the HTTP Protocol Configuration
The HTTP protocol builder sets connection-level defaults that apply to every request in the simulation. At minimum you need
baseUrl. Additional options like acceptHeader and userAgentHeader make your virtual users look more like real browser clients.- Java
- JavaScript
http.baseUrl(...) means every request URL in the scenario can be written as a relative path (e.g. /session instead of https://api-ecomm.gatling.io/session).Describe a Scenario
A scenario is a named sequence of actions that models what one virtual user does. Start with a single GET request to keep things simple, then add more steps once the simulation runs successfully.
- Java
- JavaScript
scenario("Scenario")— names the scenario. This name appears in the HTML report..exec(...)— appends one action to the scenario chain.http("Session")— names the individual request. Request names appear as rows in the report..get("/session")— issues an HTTP GET. The full URL isbaseUrl + "/session".
Choose an Injection Profile
The injection profile tells Gatling how many virtual users to launch and when. The instance initializer block (
constantUsersPerSec(2).during(60) is an open injection model that adds 2 new users every second for 60 seconds — 120 users total, each running the scenario independently.- Java
- JavaScript
{ setUp(...) }) is how setUp is called in Java simulations. It runs when Gatling instantiates your Simulation class.The Completed Simulation
Here is the full simulation file with all pieces assembled:
- Java
- JavaScript
Run the Simulation via the CLI
Execute the simulation from the terminal. Gatling prints a live progress summary while the test runs and an HTML report path when it finishes.Select The report is written to Common troubleshooting:
- Java (Maven)
- JavaScript (npm)
[1] example.BasicSimulation when prompted, or skip the prompt:target/gatling/basicsimulation-<timestamp>/index.html.| Symptom | Fix |
|---|---|
Permission denied: ./mvnw | Run chmod +x mvnw on Linux/macOS |
Compilation error | Verify all braces and imports are in place |
Module not found (JS) | Run npm install in the project directory |
| Simulation not listed (JS) | Confirm the file ends with .gatling.js and is in src/ |
| Network errors | Check https://api-ecomm.gatling.io/session is reachable in a browser |
Understanding the Report
Once the test completes, open theindex.html file in your browser. The report contains:
- Summary table — total requests, success count, error count, and response time percentiles per request
- Active users over time — visualizes the shape of your injection profile
- Response time percentiles over time — shows how latency evolves as load increases
- Requests/responses per second — throughput across the test duration
Next Steps
Deploy to Gatling Enterprise
Package your simulation with
./mvnw gatling:enterprisePackage or npx gatling enterprise-package and upload it to Gatling Enterprise for distributed, cloud-scale execution.Low-Code Tools
Already have a Postman collection? Import it directly into a Gatling simulation without writing the HTTP requests by hand.