Gatling Introduction For Java Section-A
Gatling Introduction For Java Section-A
Introduction for
Java Users
A1 - Section Overview 3
A2 - Gatling Introduction 4
A3 - Gatling Prerequisites 7
Java JDK 7
IntelliJ IDE 8
● 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 or Gradle
Gatling.io website
At a high-level, we can say Gatling is an open-source load testing tool. It'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:
Load test scripts in Gatling can be written in either Scala, Kotlin or Java. In fact, the
expressive DSL that it ships with means that users need only know little code in order to
write Gatling load tests.
The extensive Gatling documentation explains exactly what each DSL method in the Gatling
library does, for all of the supported languages. The documentation can be found online
here: https://gatling.io/docs/gatling/
● 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, 11 and 17 are recommended for Gatling as they have been
tested the most, but any version after 8 should work
● 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:
$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
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://www.oracle.com/java/technologies/downloads/ , and download the appropriate
version for your operating system
If you require further installation instructions, refer to the JDK installation guide here -
https://docs.oracle.com/en/java/javase/18/install/overview-jdk-installation.html
The other thing required is an IDE. For this course, we will be using IntelliJ IDEA. IntelliJ can
be downloaded from here: https://www.jetbrains.com/idea/download
Simply download the Community edition, and follow the onscreen instructions to install.
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 it's 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:
$ git clone
https://github.com/gatling/gatling-maven-plugin-demo-java.git
Cloning into 'gatling-maven-plugin-demo-java'...
remote: Enumerating objects: 49, done.
remote: Counting objects: 100% (49/49), done.
remote: Compressing objects: 100% (36/36), done.
remote: Total 436 (delta 20), reused 35 (delta 10), pack-reused 387
Receiving objects: 100% (436/436), 58.05 KiB | 667.00 KiB/s, done.
Resolving deltas: 100% (184/184), done.
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.
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:
As with Maven previously, the easiest way to get started is by cloning an example project
and adapting that for your requirements. You can find the an example project here:
https://github.com/gatling/gatling-gradle-plugin-demo-java
You can browse to that repository and click Code > Download Zip, or you can clone the
project directly onto your machine through Git:
$ git clone
https://github.com/gatling/gatling-gradle-plugin-demo-java.git
Cloning into 'gatling-gradle-plugin-demo-java'...
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 58 (delta 15), reused 42 (delta 8), pack-reused 0
Unpacking objects: 100% (58/58), done.
Gradle will import the project and all the required dependencies for Gatling into IntelliJ.
Once everything has been imported, we can run the sample script that ships with the project
by executing the following:
$ ./gradlew gatlingRun-computerdatabase.BasicSimulation
We could also run every script that exists within our project by simply executing:
$ ./gradlew gatlingRun
For full instructions on using the Gatling Gradle plugin, check out the official documentation
here: https://gatling.io/docs/current/extensions/gradle_plugin/