Gatling Performance Framework
Repeatable, CI-friendly load testing for APIs and web endpoints using Gatling. Generate actionable reports and integrate with CI for automated regression detection.
Overview
Design the framework for maintainability and CI: separate simulations, use feeders for variable data, assert SLAs (p95/p99, error rates) and store artifacts for comparison.
- Capabilities: CSV feeders, realistic pause/ramp profiles, checks & thresholds, HTML reports
- Artifacts: HTML reports under `target/gatling/`, raw metrics CSV/JSON for long-term storage
- Environments: Run locally for validation, in CI for regression checks, and in container clusters for scale
Quick start
- Install JDK 11+ and Maven (or Gradle).
- Create the project layout and add the Gatling plugin to `pom.xml` (example below).
- Add simulations under `src/gatling/scala/simulations` and resources under `src/gatling/resources`.
- Run `mvn gatling:test` and review `target/gatling/` report.
Recommended project layout
/project-root
├─ pom.xml
├─ src
│ ├─ gatling
│ │ ├─ scala
│ │ │ └─ simulations
│ │ │ └─ BasicSimulation.scala
│ │ └─ resources
│ │ └─ feeders
│ │ └─ users.csv
│ └─ main
│ └─ resources
└─ reports
Maven plugin snippet
Add to the `build/plugins` section of `pom.xml`:
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>3.10.0</version>
</plugin>
Sample simulation
Example placed at `src/gatling/scala/simulations/BasicSimulation.scala` — uses CSV feeder and assertions.
package simulations
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class BasicSimulation extends Simulation {
val httpProtocol = http.baseUrl("https://api.example.com").acceptHeader("application/json")
val feeder = csv("feeders/users.csv").circular
val scn = scenario("API Load Scenario")
.feed(feeder)
.exec(http("Get user").get("/users/${userId}").check(status.is(200)))
.pause(1.second, 4.seconds)
setUp(
scn.inject(atOnceUsers(5), rampUsers(50) during (30.seconds))
).protocols(httpProtocol)
.assertions(global.successfulRequests.percent.gte(95), global.responseTime.percentile4.lte(2000))
}
Update `baseUrl` and endpoints to match your environment. Use feeders to avoid cache artifacts and to vary request parameters.
Run locally & reports
Run locally:
mvn gatling:test
Open target/gatling/<simulation-name>-<timestamp>/index.html for the HTML report. Upload sample reports to reports/ and link them from this page for easy sharing.
CI integration (GitHub Actions)
name: perf-test
on: [push]
jobs:
gatling:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Run Gatling tests
run: mvn -B -q gatling:test
- name: Upload Gatling report
uses: actions/upload-artifact@v4
with:
name: gatling-report
path: target/gatling
Consider running lightweight smoke tests on each PR and heavier load runs on schedules or dedicated runners.
Tips & best practices
- Use realistic user journeys and think in business transactions (e.g., checkout flow).
- Prefer programmatic feeders for complex synthetic data or use CSV for simple cases.
- Assert SLOs (p95, error rate) and fail CI when thresholds are breached.
- Store raw metrics to enable trend comparisons over time.
- Run large scale tests from container clusters or distributed runners; use Docker images for reproducible environments.