Gatling is a library which allows you to test the performance of your API’s/websites by mimicking real world load scenarios. In this article ill be showing you a Gatling load test example so that you can run some load tests.
Gatling gives a nice summary of how you performed which includes errors that are present in your website under high load. Gatling also allows you to customise and configure the load when testing & also the duration of the test.
Gatling is written in Scala so what language best to use for the simplest Gatling load test example. In this article ill be showing you how to edit and run the most simple Gatling load test locally on your machine.
I will be assuming you already have Scala installed (view prerequisites). This Gatling load test example should only be used to test your own API’s to website, please do not abuse other services unless you have permission.
- Scala installed – Follow this guide
- Java 1.8 installed – Follow this guide
- A GitHub account – Create one here
- An IDE setup for Scala or any way to edit code (I use IntelliJ) – Get it here
Editing the load test
- Clone my repository from here: simple-gatling-load-test
- Open the project and navigate to the file called
val website = "http://tech-grounds.com"to include your website instead
val page = "/gatling-load-test-example"to the page you want to load test, or leave as
/to test the homepage
- Navigate to
BaselineSimulations.scalaand go to
- Edit the
maxRPS(requests per second), to your desired amount
line 55& change the minutes figures to how long you want the load test to run for
Running the load test
- Be sure to have Scala & Java 8 & sbt installed – follow this guide if you have not installed it yet
- Open up your operating systems command line (Windows – Command prompt, Macos – Terminal)
- Navigate to the
- Type in
sbt, you should enter into sbt
- Type in
gatling:test, this should run the load test you configured previously
- You should see the output below, while the test is running
Once the test finishes running, you should be presented with a full report of the load test. It will look something like this:
Viewing load test results
Gatling also generates a
index.html. This file contains the full report of the load test but displayed in a nice GUI. It has a lot more metrics and information then the report on the terminal windows. Once the load test finishes, it should give you a directory associated with the load test you just ran. Navigate to this directory and open the
index.html file in Chrome/Firefox etc.
Some of the metrics in the GUI look like this:
Having these metrics stored is very useful as you can use them to compare different runs. Once you make a significant change to your website or API you can rerun the load test and compare it to the previous load tests.
Additionally, you may experience slow down on your machine when the Gatling load test is running. This is because Gatling is using a high percentage of the CPU power to make the necessary requests for the load test. I tend to leave the load test running and go do something else while so that it does not affect the results. Having a more powerful CPU will allow you to make more RPS, which is a very good thing as if you want to test with 3000+ RPS then you will need a very well performing CPU.
I have a Windows machine which I use more often but it is not as powerful as my Mac, so whenever I run any load tests I use my mac. My Macs specs are: