Gatling is a lightweight stress testing tool backed by Scala, Akka, and Netty. It works asynchronously if the underlying HTTP request is non-blocking. It uses messages for virtual user simulation than thread per virtual user. Because of this, it consumes lesser system resources to run the load test. In this article let us see a REST endpoint load testing by following the below steps.
Step 1: Download the Gatling bundle from http://gatling.io/#/resources/download . The folder structure of GATLING_HOME is explained below.
Step 2: Set GATLING_HOME and JAVA_HOME environment variables and write a sample simulation using Scala. As a java developer you no 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 the 1000 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 “simulations” folder and generates the reports under the results folder.
The sample report is given below.
In the coming article, we will see how to use Gatling maven integration and additional features like feeders, externalizing the properties, etc. Till then, Stay Tune!!!
Good article. I will try this testing tool. Please keep posting. Thanks.