%% Last Updated: - [[2021-04-02]] %% First, [download](https://gatling.io/open-source) [[Gatling]]. You’ll want to get the standalone tool for this basic tutorial. You’ll also need [[Java]] to run Gatling. Unzip Gatling. You’ll see that it comes with a few directories: ![](assets/1621807343_142.png) - `bin` contains Gatling’s execution engine and a recorder that will help you create scripts - `conf` contains files you’ll modify to change the default Gatling configuration settings - `lib` contains extra files you may require to run your simulations - `results` will contain data from previous test runs - `target` will contain simulations that you’ve successfully compiled - `user-files` contains your simulations and scala files Gatling comes with a sample script by default, which you can find in `/user-files/simulations/computerdatabase/BasicSimulation.scala`, but let’s take a step back and create our own Gatling simulation to run. Create a folder in `/user-files/simulations` called `gatlingsample` and create a file within that folder called `BasicSimulation.scala`. You can download a copy of this script to follow along. Here’s the most basic version of the script: ```scala package gatlingsample import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.duration._ class SampleSimulation extends Simulation { val httpProtocol = http.baseUrl("https://flooded.io") // This sets your base URL for all subsequent requests val scn = scenario("Basic") // A scenario is a chain of requests and pauses .exec(http("01_Home") // This sets the transaction name .get("/")) // method and relative path to retrieve .check(status.is(200), substring("Smooth Scaling").exists) // Verify that the HTTP code returned is 200 and that the substring exists .pause(7) // think time setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol)) } ``` This script contains one transaction called `01_Home` with the scenario `Basic` that will start one user and make a single GET request for [https://flooded.io](https://flooded.io/). It will then look at the data returned, check for the text “Smooth Scaling”, and then pause for 7 seconds before finishing. To run this script, open up your terminal. Unlike JMeter, Gatling doesn’t have a UI, so you’ll need to get comfortable with the command line in order to use it. Change directory to Gatling’s bin folder and type `./gatling.sh` (Unix) or `./gatling.bat` (Windows). Gatling will compile all simulations it finds. Once that’s done, it’ll then ask you which one you’d like to run. ![](assets/1621807344_143.png) Type 6 and hit the ENTER key. Enter an optional test description and hit ENTER, and Gatling will run the simulation. After the test has finished, you’ll see a cursory report: ![](assets/1621807344_144.png) If you copy that URL into your browser, you’ll see Gatling’s standard HTML report, which you can use to find out more detailed information about your test run: ![](assets/1621807345_145.png) Each run will generate a new report. That script only makes one request, however, so we’ll need to instruct Gatling to iterate. In addition, the scenario so far only runs one user. Let’s make some adjustments: ```scala package gatlingsample import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.duration._ class SampleSimulation extends Simulation { val threads = 10 val rampup = 30 val duration = 300 val httpProtocol = http.baseUrl("https://flooded.io") // This sets your base URL for all subsequent requests val scn = scenario("Basic") // A scenario is a chain of requests and pauses .during(duration seconds) { exec(http("01_Home") // This sets the transaction name .get("/") // method and relative path to retrieve .check(status.is(200), substring("Smooth Scaling").exists) // Verify that the HTTP code returned is 200 and that the substring exists ) .pause(7) // think time } setUp(scn.inject(rampUsers(threads) during (rampup seconds))).protocols(httpProtocol) } ``` This wraps everything in the scenario in a `during {}` loop, and you may notice that I’ve also changed the setUp scenario line so that it ramps up users to a certain number and then maintains that amount of users for the whole duration. In this script, I’ve hardcoded values for those parameters, but if you’re running this script on Flood, you can do this to have the script take the values from the Flood UI: ```scala // Optional, Tricentis Flood will pass in threads, rampup and duration properties from UI val threads = Integer.getInteger("threads", 1000) val rampup = Integer.getInteger("rampup", 60).toLong val duration = Integer.getInteger("duration", 300).toLong ``` Download the final script [here](https://github.com/nicolevanderhoeven/ebook-api/blob/master/scriptsamples/SampleSimulation.scala). ## Related - [[API Load Testing - A Beginner's Guide]]