
How many concurrent users can your infrastructure handle? Do you know when your most critical features have regressed in performance? Will your website survive a Denial of Service attack? If you are unsure, Gatling's lightweight and powerful capabilities will help answer these questions.
Advantages of Gatling
- Gatling is load testing as code which is ideal for integration with DevOps, Continuous Integration, and build tools.
- Simulate thousands of requests per second against your APIs and applications.
- Identify or troubleshoot performance and load issues.
- Are your APIs and website C10k compliant? Determine how many concurrent users your infrastructure, APIs, and applications can handle.
- Test your public APIs and applications against Denial of Service attacks.
- Automatically generates an exhaustive, dynamic, and colorful report with high-precision metrics.
- Performance is measured in percentiles which is more reliable than averages.
Gatling Installation (5 minutes)
Gatling has several installation options:
- Download Gatling's bundle and run Gatling locally as a standalone tool (recommended).
- Install and run Gatling via a build tool.
- Install and run Gatling using an IDE.
Gatling Directory Structure
Source code directory:
- $GATLING_HOME/user-files/simulations (directory for your Scala load tests)
- $GATLING_HOME/user-files/resources (directory for your users.csv file if you need a load test with multiple unique authenticated users)
Running your first load test (5 minutes)
- Copy/Merge the user-files directory from my GitHub repo to your local $GATLING_HOME directory. The $GATLING_HOME directory will be your Gatling download directory. Refer to the user-files/simulations directory for tests.
- Run Gatling locally as a standalone application by running the following command:
- On Linux/Unix: $GATLING_HOME/bin/gatling.sh
- On Windows: %GATLING_HOME%\bin\gatling.bat
- Which test to run? Choose any test simulation to run.
- Enter an optional test description? Hit enter to skip.
- When the simulation is done, the console will display a link to the HTML reports.
Gatling will prompt a few questions:
Load Test Examples
Refer to the user-files/simulations directory for test examples. I have a few authenticated and unauthenticated load tests for REST APIs and a website. The authenticated tests refer to user data (users.csv). The Gatling installation also has several load tests for Web applications (refer to tests in $GATLING_HOME/user-files/simulations/computerdatabase).
class ItunesApiAuthenticatedLoadTest extends Simulation { | |
private val loadTestName = "api-itunes-load-test" | |
private val repeatTimes = 1 // How often to repeat the test scenario per user | |
private val httpProtocol = http.baseUrl("https://itunes.apple.com") | |
private val users = csv("users.csv") | |
private val loadTestAPI = repeat(repeatTimes, "n") { | |
exec(http(loadTestName) | |
.get("/search?term=michael+jackson&limit=25") | |
.basicAuth("${username}", "${password}") | |
) | |
} | |
private val scn = scenario("page") | |
.feed(users) | |
.exec(loadTestAPI) | |
// Run the load test with your preferred load (rampUsers & repeatTimes) within your preferred duration (seconds) | |
setUp(scn.inject(rampUsers(10) during (10 seconds))).protocols(httpProtocol) | |
} |
Reports
Load test reports are automatically generated in $GATLING_HOME/results when your load test completes. Refer to the console when your test finishes for the full path. Gatling creates beautiful charts!
