Professional Documents
Culture Documents
Gatling: Section A - Accompanying Documentation
Gatling: Section A - Accompanying Documentation
Introduction
A1 - Section Overview 3
A2 - Gatling Introduction 4
A3 - Gatling Prerequisites 7
Java JDK 7
Scala Binaries 8
IntelliJ IDE & Scala Plugin 9
● Overview of the Gatling tool, having a brief look at how it works and what makes it
such a powerful tool for stress and performance testing.
● Prerequisites required for proper Gatling script development
● Gatling installation:
○ Through standalone download
○ Through a build tool - Maven, Gradle or SBT
Gatling.io website
At a high-level, we can say Gatling is an open-source load testing tool. I t's written purely in
Scala and makes use of the AKKA and Netty frameworks.
This tech stack is extremely powerful for stress and performance testing because it
overcomes the JVM limitation of being able to handle single virtual users on threads.
Traditional JVM based load testing tools such as JMeter can only handle a single virtual user
per thread, as shown in the diagram below:
This severely limits the number of users that can be supported per load injector
Although Gatling is Scala code, the expressive DSL that it ships with means that users don't
need to know any Scala in order to write Gatling tests. Gatling comes with a really helpful
cheat sheet that you can refer to guide you in the creation of your test scenarios. The
documentation in the cheat sheet explains exactly what each DSL method in the Gatling
library does.
● HTTP Proxy Mode - runs as a proxy and captures all traffic, converting that traffic
into a Gatling script
● HAR Converter Mode - Save a HAR file from a user journey in your browser, and
convert that file into a Gatling script
Gatling Recorder
Another great feature of Gatling is that because it represents a load test as code, it makes it
very easy to have this code stored in your version control system. In your Github repository,
for example, you can have your stress tests living side-by-side with your application code.
This makes it easy to run performance tests through your continuous integration solution.
But if you are doing any serious script development in Gatling, then it’s best to have the
following installed on your development machine:
● Java JDK - versions 8 or 11 are recommended for Gatling as they have been tested
the most, but any version after 8 should work
● Scala 2.12
● An IDE such as IntelliJ
Java JDK
You most likely already have Java installed on your machine. To check if you do, open a
terminal or command prompt and type:
$ javac -version
javac 1.8.0_192
If Java is installed, you should see a message printed out telling you which version you have
installed.
In the event that you don't have Java installed, simply browse to
https://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html
This will take you to a guide that shows how to install the JDK on all different operating
systems.
The next thing we need to do is download the Scala binaries, it's important that you use
version 2.12 of Scala with Gatling. Version 2.13 has some compatibility issues with Gatling
and won’t be supported until the next major release of Gatling.
Save the Scala binaries somewhere on your computer, and you can import them into your
IDE once loading it for the first time.
The final thing required is an IDE. For this course, we will be using IntelliJ IDEA along with
the Scala plugin. IntelliJ can be downloaded from here:
https://www.jetbrains.com/idea/download
When you run it for the first time, the IntelliJ landing page should load, and from here you
can install the Scala plugin. Click on "configure" and then "plugins". Make sure you're on the
marketplace and then type in "Scala"
This will download a ZIP file, that you should save and extract somewhere on your machine.
Open up the directory that you just extracted, and change into the /bin folder.
$ ./gatling.sh
GATLING_HOME is set to
/Users/username/Desktop/gatling-charts-highcharts-bundle-3.3.1
Choose a simulation number:
[0] computerdatabase.BasicSimulation
[1] computerdatabase.RecordedSimulation
[2] computerdatabase.advanced.AdvancedSimulationStep01
[3] computerdatabase.advanced.AdvancedSimulationStep02
[4] computerdatabase.advanced.AdvancedSimulationStep03
[5] computerdatabase.advanced.AdvancedSimulationStep04
[6] computerdatabase.advanced.AdvancedSimulationStep05
Enter test for the run description and press enter. A Gatling stress test will execute against
the Computer Database Application and should last for 30 seconds or so. We will be seeing
more of this application later on, as its the target application we will be creating our own
Gatling scripts against.
As the script is executing, every 5 seconds Gatling will print an update to the console with
the progress of the test:
========================================================================
2020-09-16 08:20:25 5s elapsed
---- Requests
------------------------------------------------------------------
> Global (OK=2
KO=0 )
> request_1 (OK=1
KO=0 )
> request_1 Redirect 1 (OK=1
KO=0 )
========================================================================
---- Global Information
--------------------------------------------------------
> request count 13 (OK=13
KO=0 )
> min response time 18 (OK=18
KO=- )
> max response time 41 (OK=41
KO=- )
> mean response time 23 (OK=23
KO=- )
> std deviation 6 (OK=6
KO=- )
> response time 50th percentile 21 (OK=21
KO=- )
> response time 75th percentile 22 (OK=22
KO=- )
> response time 95th percentile 32 (OK=32
KO=- )
> response time 99th percentile 39 (OK=39
KO=- )
> mean requests/sec 0.565 (OK=0.565
KO=- )
---- Response Time Distribution
------------------------------------------------
> t < 800 ms 13 (100%)
> 800 ms < t < 1200 ms 0 ( 0%)
> t > 1200 ms 0 ( 0%)
> failed 0 ( 0%)
========================================================================
The Gatling results report will be covered in greater detail later on in the course, but feel free to
explore the report yourself now in the meanwhile.
If you aren’t familiar with how Git works, you can simply click on Code and Download ZIP:
If you are comfortable with Git, then simply clone this repository onto your computer in the
normal way:
From the IntelliJ landing page choose Open or Import, then browse to the folder that you
just cloned and locate the pom.xml file, and choose Open as Project when prompted.
IntelliJ will now import the project and the IDE will open up. Once the project loads, open the
folder structure on the left-hand side and double click on the BasicSimulation file:
This is the example Gatling simulation that we ran in the previous section.
Note: If you see a message No Scala SDK in Module at the top of the IDE, then you may
need to configure Scala in IntelliJ. Follow the steps in this guide to get that setup.
As before, we can see the logs and results being printed to the console in IntelliJ.
Once the test completes, we can view the test results report that gets created by opening the
target folder and locating the index.html file. Right-click and choose Open in Browser to
view the report:
It is required to have SBT 1 installed, which is available from the link above.
You can browse to that repository and click Code > Download Zip, or you can clone the
project directly onto your machine through Git:
Once the project has been cloned, we need to import it into IntelliJ. From the IntelliJ landing
page, choose Open or Import. Browse to the folder that you just cloned or downloaded, and
double-click on the build.sbt file. Choose Open as Project when prompted.
SBT will import the project and all the required dependencies for Gatling into IntelliJ.
There are two sample scripts in this project that we can view:
With SBT running, we can run all the example scripts in our project (two in our case) with:
$sbt:> gatling:test
Here we are providing the full path of the script, i.e. it lives in the computerDatabase
package and is called BasicSimulation
Once the test has finished, we can again up the index.html file within the target folder to
view the test report directly in the IDE. We simply need to right-click on the file and choose
Open in Browser