Gatling

Author: Jase Batchelor

Gatling is a load testing tool that offers both an Enterprise and Open-source version.

For the purposes of our testing we will be using the open-source version.

Test scenarios are written in Scala and executed via CLI.

Test results are available via terminal output and / or a HTML report.

Sections


Installation

Gatling is provided as a zip file. Download from https://gatling.io/open-source/

image Source: https://gatling.io/open-source/

Navigate to the directory where the zip file was saved and extract

cd ~/Downloads
ls
# gatling-charts-highcharts-bundle-3.9.5-bundle.zip

unzip gatling-charts-highcharts-bundle-3.9.5-bundle.zip

cd gatling-charts-highcharts-bundle-3.9.5 
ls 
# LICENSE  bin  conf  lib  results  user-files

ls bin/* conf/* results/ user-files/* 
# bin/gatling.bat  bin/recorder.bat  conf/gatling-akka.conf  conf/logback.xml
# bin/gatling.sh   bin/recorder.sh   conf/gatling.conf       conf/recorder.conf
# 
# results/:
# 
# user-files/lib:
# 
# user-files/resources:
# search.csv
# 
# user-files/simulations:
# computerdatabase

Configuration

Create a test scenario under the $GATLING_HOME/user-files/simulations directory

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class Load8K extends Simulation {

  var baseUrl : String= "http://localhost:8080"
  var url : String = "/hello"
  // 4096 users - 128 x 32
  // 8192 users - 256 x 32
  var increment = 256
  var steps = 32

  val httpProtocol = http
    .baseUrl(baseUrl)
    .acceptHeader("*/*")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")

  val scn = scenario("Receive plain text")
    .forever {
      exec(http("REST Endpoint Client").get(url))
    }

  setUp(
    scn.inject(
      incrementConcurrentUsers(increment)
        .times(steps)
        .eachLevelLasting(20 seconds)
        .separatedByRampsLasting(10 seconds)
        .startingFrom(0)
    )
  ).maxDuration(20 minutes).protocols(httpProtocol)

}

Basic usage

Run a test scenario interactively using the $GATLING_HOME/bin/gatling.sh CLI

./bin/gatling.sh   
# GATLING_HOME is set to /Users/jase/Downloads/gatling-charts-highcharts-bundle-3.9.5
# Do you want to run the simulation locally, on Gatling Enterprise, or just package it?
# Type the number corresponding to your choice and press enter
# [0] <Quit>
# [1] Run the Simulation locally
# [2] Package and upload the Simulation to Gatling Enterprise Cloud, and run it there
# [3] Package the Simulation for Gatling Enterprise
# [4] Show help and exit
1
# 08:25:18.679 [WARN ] i.g.c.ZincCompiler$ - -target is deprecated: Use -release instead to compile against the correct platform API.
# 08:25:19.582 [WARN ] i.g.c.ZincCompiler$ - one warning found
# Choose a simulation number:
#      [0] Load8K
#      [1] computerdatabase.ComputerDatabaseSimulation
1
# Simulation Load8K started...
# ...

Run a test scenario non-interactively using the CLI

./bin/gatling.sh --run-mode local --simulation Load8K
# GATLING_HOME is set to /Users/jase/Downloads/gatling-charts-highcharts-bundle-3.9.5
# Simulation Load8K started...
# ...