Introduction¶
In this section we will use Gatling to load test a simple cloud hosted web server and will introduce you to the basic elements of the DSL.
Installing¶
Please check the installation section to pick a setup that matches your needs. Non developers are recommended to start with the bundle setup.
A Word on Encoding¶
Gatling’s default encoding is UTF-8. If you want to use a different one, you have to:
- select the proper encoding while using the Recorder
- configure the proper encoding in the
gatling.conf
file. - It will be used for compiling your simulations, building your requests and your responses.
- configure the proper encoding in the
- make sure your text editor encoding is properly configured to match.
A Word on Scala¶
Gatling simulation scripts are written in Scala, but don’t panic! You can use all the basic functions of Gatling without knowing much about Scala. In most situations the DSL will cover most of your needs and you’ll be able to build your scenarios.
If you are interested in knowing more about Scala, then we recommend that you have a look at Twitter’s Scala School.
Note
Feel also free to join our Google Group and ask for help once you’ve read this documentation.
Test Case¶
This page will guide you through most of Gatling HTTP features. You’ll learn about simulations, scenarios, feeders, recorder, loops, etc.
Application under Test¶
In this tutorial, we will use an application named Computer-Database deployed at the URL: http://computer-database.gatling.io.
This application is a simple CRUD application for managing computer models, and was a sample for the Play Framework before version 2.3.
Scenario¶
To test the performance of this application, we will create scenarios representative of what really happens when users navigate it.
- Here is what we think a real user would do with the application:
- A user arrives at the application.
- The user searches for ‘macbook’.
- The user opens one of the related models.
- The user goes back to home page.
- The user iterates through pages.
- The user creates a new model.
Basics¶
Using the Recorder¶
To ease the creation of the scenario, we will use the Recorder, a tool provided with Gatling that allows you to record your actions on a web application and export them as a Gatling scenario.
This tool is launched with a script located in the bin directory:
On Linux/Unix:
$GATLING_HOME/bin/recorder.sh
On Windows:
%GATLING_HOME%\bin\recorder.bat
Once launched, the following GUI lets you configure how requests and responses will be recorded.
- Set it up with the following options:
- computerdatabase package
- BasicSimulation name
- Follow Redirects? checked
- Automatic Referers? checked
- Black list first filter strategy selected
- .*.css, .*.js and .*.ico in the black list filters

After configuring the recorder, all you have to do is to start it and configure your browser to use Gatling Recorder’s proxy.
Note
For more information regarding Recorder and browser configuration, please check out Recorder reference page.
Recording the scenario¶
- Now simply browse the application:
- Enter ‘Search’ tag.
- Go to the website: http://computer-database.gatling.io
- Search for models with ‘macbook’ in their name.
- Select ‘Macbook pro’.
- Enter ‘Browse’ tag.
- Go back to home page.
- Iterates several times through the model pages by clicking on Next button.
- Enter ‘Edit’ tag.
- Click on Add new computer.
- Fill the form.
- Click on Create this computer.
Try to act as a real user would, don’t immediately jump from one page to another without taking the time to read. This will make your scenario closer to real users’ behavior.
When you have finished playing the scenario, click on Stop
in the Recorder interface.
The Simulation will be generated in the folder user-files/simulations/computerdatabase
of your Gatling installation under the name BasicSimulation.scala
.
Gatling scenario explained¶
Here is the produced output:
package computerdatabase // 1
import io.gatling.core.Predef._ // 2
import io.gatling.http.Predef._
import scala.concurrent.duration._
class BasicSimulation extends Simulation { // 3
val httpProtocol = http // 4
.baseUrl("http://computer-database.gatling.io") // 5
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // 6
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0")
val scn = scenario("BasicSimulation") // 7
.exec(http("request_1") // 8
.get("/")) // 9
.pause(5) // 10
setUp( // 11
scn.inject(atOnceUsers(1)) // 12
).protocols(httpProtocol) // 13
}
What does it mean?
- The optional package.
- The required imports.
- The class declaration. Note that it extends
Simulation
. - The common configuration to all HTTP requests.
Note
val
is the keyword for defining a constant value.
Types are not defined and are inferred by the Scala compiler.
- The baseUrl that will be prepended to all relative urls.
- Common HTTP headers that will be sent with all the requests.
- The scenario definition.
- A HTTP request, named request_1. This name will be displayed in the final reports.
- The url this request targets with the GET method.
- Some pause/think time.
Note
Duration units default to seconds
, e.g. pause(5)
is equivalent to pause(5 seconds)
.
- Where one sets up the scenarios that will be launched in this Simulation.
- Declaring to inject into scenario named scn one single user.
- Attaching the HTTP configuration declared above.
Note
For more details regarding Simulation structure, please check out Simulation reference page.
Running Gatling¶
Launch the second script located in the bin directory:
On Linux/Unix:
$GATLING_HOME/bin/gatling.sh
On Windows:
%GATLING_HOME%\bin\gatling.bat
You should see a menu with the simulation examples:
Choose a simulation number:
[0] computerdatabase.BasicSimulation
When the simulation is done, the console will display a link to the HTML reports.
Note
If Gatling doesn’t work as expected, see our FAQ or ask on our Google Group.
Going Further¶
When you’re ready to go further, please check out the Advanced Tutorial.