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

Download our Introduction to API Performance Testing and learn why testing your API is just as important as testing your website, and how to start today.

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!

Find scaling and performance issues before your customers do with our Introduction to High-Capacity Load Testing guide.

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.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}