Microservices — Performance testing with Gatling framework

Karthikeyan Sadayamuthu
Devexchange Programming Blog
2 min readJul 4, 2019

--

Gatling is an open-source load and performance testing framework based on Scala, Akka and Netty. The software is designed to be used as a load testing tool for analyzing and measuring the performance your web applications.

The Project’s aims include;

  • High performance
  • Ready-to-present HTML reports
  • Scenario recorder and developer-friendly DSL

It officially supports the following protocols;

  • HTTP
  • WebSockets
  • Server-sent events
  • JMS

A simulation, aka stress test, has one or more scenarios. One scenario is a series of requests to a service and response checks, so we can emulate the service usage under a high load. Gatling sends simultaneous requests after a specific scenario. At the end of a simulation, Gatling provides a detailed HTML report.

Gatling Gradle Plugin

io.oneclicklabs.gatling plugin provides simplified task & configuration to execute gatling simulations. here

Build script snippet for use in all Gradle versions:

buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.io.oneclicklabs.gatling:gatling-gradle-plugin:0.0.3"
}
}
apply plugin: "io.oneclicklabs.gatling"

Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:

plugins {
id "io.oneclicklabs.gatling" version "0.0.3"
}

Create a java or scala gradle project

Clone gatling-load-testing-demo sample project and import to workspace.

gatling-load-testing-demo java or scala project--src
-- main
-- test
-- performanceTest
-- scala
-- Simulation Class

-- resources

add gatling framework dependencies to build.gradle

performanceTest "io.gatling.highcharts:gatling-charts-highcharts:2.2.3"
performanceTest
"io.gatling:gatling-app:2.2.3"
performanceTest "io.gatling:gatling-core:2.2.3"
performanceTest "io.gatling:gatling-http:2.2.3"

add sourceSets to build.gradle

sourceSets {
perfTest {
scala {
srcDirs = ["src/performanceTest/scala"]
}
}
}

add performanceTestCompile gradle task to build.gradle

task performanceTestCompile(type: org.gradle.api.tasks.scala.ScalaCompile) {
source = sourceSets.perfTest.scala.srcDirs
destinationDir = sourceSets.perfTest.output.classesDir
classpath = configurations.performanceTest
}

add perfTestGoogle gradle task to run standalone test.

task perfTestGoogle(type: io.oneclicklabs.gatling.gradle.plugin.PerfTestTask, dependsOn: [performanceTestCompile]) {
warmUpURL = "http://www.google.com"
simulationClass = "io.oneclicklabs.gatling.demo.GooglePerfTest"
simulationClassesFolder = "${project.buildDir}/classes/perfTest"
}

add perfSuite gradle task to run all simulation class together.

task perfSuite(type: io.oneclicklabs.gatling.gradle.plugin.PerfTestTask, dependsOn: [performanceTestCompile]) {
warmUpURL = "http://www.google.com"
sysProperties = ["-Dcomcast.extra=CheckThis"]
simulationClassesFolder = "${project.buildDir}/classes/perfTest"
simulationClass
= ["io.oneclicklabs.gatling.demo.GooglePerfTest"]
}

download build.gradle — here

Create a test simulation

To create a simulation you need to:

  • import io.gatling.core.Predef._ and io.gatling.http.Predef._
  • extend io.gatling.core.scenario.Simulation
  • provide the scenario (requests to a service and response checks)
  • setting up the scenario for load test
  • Configure an http base URL of the service.
  • Configure the scenario CRUD requests to the service and check the response. We will use JSONPath for processing JSON in the responses.
  • Configure the scenario to use the specific number of simultaneous requests.
  • Configure the scenario to repeat it as many times as it was set in SimulationConfig.

--

--