Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Gatling: A Lightweight Load Testing Tool

DZone's Guide to

Gatling: A Lightweight Load Testing Tool

Gatling consumes fewer system resources to run a load test than other options. It works asynchronously if the underlying HTTP request is nonblocking.

Free Resource

Transform incident management with machine learning and analytics to help you maintain optimal performance and availability while keeping pace with the growing demands of digital business with this eBook, brought to you in partnership with BMC.

Gatling is a lightweight stress testing tool backed by Scala, Akka, and Netty. It works asynchronously if the underlying HTTP request is nonblocking. It uses messages for virtual user simulation than threads per virtual user. Because of this, it consumes fewer system resources to run a load test. In this article, let's see a REST endpoint load test by following the below steps.

1. Download the Gatling Bundle

You can download this from Gatling. The folder structure of GATLING_HOME is explained below.

gatling_folder_structure

2. Set Environment Variables

Set GATLING_HOME and JAVA_HOME environment variables and write a sample simulation using Scala. As a Java developer, you don't need to have strong Scala knowledge to write Gatling simulations with Scala. We need to have very basic knowledge. A simulation is given below to test a REST endpoint.

package org.smarttechie

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

class SampleRESTEndPointPrefSimulation extends Simulation {

val httpProtocol = http
.baseURL("<base url of your end point>") //the base url of your end point
val restEndPoint = "/posts" //provide the URI of your end point

val restEndpointScenario = scenario("Posts_Pref_Simulation")
.exec(http("request_1")
.get(restEndPoint))
setUp(restEndpointScenario.inject(rampUsers(1000) over (10 seconds))).protocols(httpProtocol)
}

In the above simulation, we are ramping up 1,000 users in 10 seconds. Once the simulation script is ready, go to the BIN folder and launch the gatling.bat/gatling.sh. The script will run the simulation available under the simulations folder and generates the reports under results folder.

The sample report is given below.

gatling_performance_stats

In the coming article, we will see how to use Gatling Maven integration and additional features like feeders, how to externalize the properties, etc. Until then, stay tuned!

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Topics:
gatling ,load testing ,performance

Published at DZone with permission of Siva Prasad Rao Janapati, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}