Skip to main content

Documentation 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.

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 at 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.
  • 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
java -version   # must succeed before continuing

Build the Simulation Step by Step

1

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.
File: src/test/java/example/BasicSimulation.java
package example;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;
The static imports bring all Gatling DSL methods (scenario, http, constantUsersPerSec, etc.) into scope without needing to qualify them. The class imports provide the builder types (ScenarioBuilder, HttpProtocolBuilder, Simulation).
2

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.
package example;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

public class BasicSimulation extends Simulation {
  // Protocol, scenario, and setUp go here
}
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.
3

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.
HttpProtocolBuilder httpProtocol =
  http.baseUrl("https://api-ecomm.gatling.io")
      .acceptHeader("application/json")
      .userAgentHeader(
          "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " +
          "AppleWebKit/537.36 (KHTML, like Gecko) " +
          "Chrome/134.0.0.0 Safari/537.36");
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).
4

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.
ScenarioBuilder scenario =
  scenario("Scenario").exec(http("Session").get("/session"));
  • 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 is baseUrl + "/session".
Add a status check to the request to make the simulation fail on unexpected responses:Java: .get("/session").check(status().is(200))JavaScript: .get("/session").check(status().is(200))
5

Choose an Injection Profile

The injection profile tells Gatling how many virtual users to launch and when. 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.
{
  setUp(scenario.injectOpen(constantUsersPerSec(2).during(60)))
    .protocols(httpProtocol);
}
The instance initializer block ({ setUp(...) }) is how setUp is called in Java simulations. It runs when Gatling instantiates your Simulation class.
6

The Completed Simulation

Here is the full simulation file with all pieces assembled:
package example;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

public class BasicSimulation extends Simulation {

  // HTTP protocol configuration
  HttpProtocolBuilder httpProtocol =
    http.baseUrl("https://api-ecomm.gatling.io")
        .acceptHeader("application/json")
        .userAgentHeader(
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " +
            "AppleWebKit/537.36 (KHTML, like Gecko) " +
            "Chrome/134.0.0.0 Safari/537.36");

  // Scenario: one virtual user action
  ScenarioBuilder scenario =
    scenario("Scenario").exec(http("Session").get("/session"));

  // Injection profile: 2 users/sec for 60 seconds
  {
    setUp(scenario.injectOpen(constantUsersPerSec(2).during(60)))
      .protocols(httpProtocol);
  }
}
7

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.
# Linux / macOS
./mvnw gatling:test

# Windows
mvnw.cmd gatling:test
Select [1] example.BasicSimulation when prompted, or skip the prompt:
./mvnw gatling:test -Dgatling.simulationClass=example.BasicSimulation
The report is written to target/gatling/basicsimulation-<timestamp>/index.html.
Common troubleshooting:
SymptomFix
Permission denied: ./mvnwRun chmod +x mvnw on Linux/macOS
Compilation errorVerify 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 errorsCheck https://api-ecomm.gatling.io/session is reachable in a browser

Understanding the Report

Once the test completes, open the index.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
Use the 95th and 99th percentile response times — not the mean — as your primary performance indicators. The mean can hide a long tail of slow responses that affect a meaningful fraction of users.

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.

Build docs developers (and LLMs) love