Gatling Performance Testing tool

Gatling vs JMeter
https://blog.flood.io/stress-testing-jmeter-and-gatling/

About Gatling:
It is an open-source load testing framework based on Scala, Akka and Netty

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

Getting the bundle

You can get Gatling bundles as a .zip file here.

Installing

Just unzip the downloaded bundle to a folder of your choice.

Warning Windows users : we recommend that you do not place Gatling in the Programs folder as there may be permission issues.

In order to run Gatling, you need to have a JDK installed. Gatling requires at least JDK7u6, yet we recommend that you use an up-to-date version.

For all details regarding the installation and the tuning of the operating system (OS), please refer to the Operations section.

Warning Gatling launch scripts and Gatling maven plugin honor JAVA_HOME env var if it’s set. OS, like OSX, have their own tricky way of discovering which version of Java to run, so you might end up running a different version than the one java -version tells you. If you get strange errors such as Unsupported major.minor version 51.0 and you were expecting to run a JDK7, you might want to explicitly set JAVA_HOME.

A Word on Encoding

Gatling’s default encoding is UTF-8. If you want to use a different one, you have to:

  • select the proper encoding while using the Recorder
  • configure the proper encoding in the gatling.conf file.

It will be used for compiling your simulations, building your requests and your responses. Make sure your text editor encoding is properly configured to match.

How to Test API endpoint:

  1. Create a scala file under user-files/simulations folder

SearchSimulation.scala

package searchiq

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

class SearchSimulation extends Simulation {

  val httpConf = http.baseURL("http://<hostname>:<port>")
  val feeder = csv("keywords.csv")
  val scn = scenario("My scenario").repeat(1) {
    exec(http("Home")
        .get("/"))
      .pause(1)
      .feed(feeder)
      .exec(
      http("Elasticsearch Search Endpoint Call")
        .get("/api/search/results")
        .queryParam("q","${keyword}")
        .queryParam("engineKey","8b77b9ec9eb9d745c3a3889a5b40e4da")
        .queryParam("page","0")
        .queryParam("itemsPerPage","10")
        .queryParam("target","search_page")
        .queryParam("sortby","relevance")
        .queryParam("documentTypes","post,page,attachment,gallery,portfolio")
        .header(HttpHeaderNames.ContentType, HttpHeaderValues.ApplicationJson)
          .header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
        .check(status.is(200))
    )
  }

  setUp(scn.inject(atOnceUsers(10)).protocols(httpConf))
}
  • Modify the base url and the required parameter according to tests.
  • Regarding keywords see below
  • Last line will setup 10 users, which will place the request at a time.
  • val scn = scenario("My scenario").repeat(1) : will repeat the code once
  • For more inject parameters please click here

If you would like to test the api enpoint with different param values, then please create a csv file under user-files/data. The first row indicates the attribute name. Please see the above script how it is loaded using:

  1. val feeder = csv("keywords.csv")
  2. feed(feeder)
  3. queryParam("q","${keyword}")

Below is the keywords.csv file.

keywords.csv

keyword
cheap
travel
hotel
discount
resort
paris
london
los angeles
mexico
cheap travel

Request and Response Logs

In order to see the request and response logs, uncomment the below mentioned lines in conf/logback.xml file.

<!-- Uncomment for logging ALL HTTP request and responses -->
    <logger name="io.gatling.http.ahc" level="TRACE" />
    <logger name="io.gatling.http.response" level="TRACE" />

Then execute the scala file.

How to execute the scala file.

  1. Run gatling.sh file
  2. It will list the correct file with the specified number
  3. Select the simulation you want to run

For Advanced tutorial click here

results matching ""

    No results matching ""