automation · gatling · performance

Gatling For Performance Testing

Since a year, I have been using Gatling for our performance testing and thought I should write something about it.Recently I have given talk on it with my colleague, you can look the slides here:

http://files.meetup.com/3872152/Exploring-Load-Testing-with-Gatling.pdf

What is Gatling:

Gatling is open source performance tool written in Scala, Akka and Netty. It’s high performance tool which based on Actor, Non blocking I/O and asynchronous concept.You can explore more about in these places:

WebSite: http://gatling.io/#/

Google Group: https://groups.google.com/forum/#!forum/gatling

Github: https://github.com/gatling/gatling

Some of the advantage which I found during our use of gatling are:

  1. Easy to write and maintain the test script using Scala DSL
  2. High performance tool which take less memory and cpu on high load.
  3. Detail and configurable reporting support.

Setup Gatling: (I have used the mac to setup gatling)

Check Your Installation:

Test your components. You should see output similar to the following:

$ java -version
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

$ mvn --version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T09:29:23-08:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"

$ scala -version
Scala code runner version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL

Let’s Start the test:

Generate Project Using Maven:

Open you command line and run following command:

You can either use your IDE’s facilities for creating a new project using a Maven archetype or, from the command line, type:

mvn archetype:generate

Then, when prompted:

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):

Type gatling. You should then see:

Choose archetype:
1: remote -> io.gatling.highcharts:gatling-highcharts-maven-archetype (gatling-highcharts-maven-archetype)

Type 1 to select the archetype, then select the version to use 
(I would recommend to always use the latest version.)

Select the groupId, artifactId and package name for your classes before confirming the archetype creation.

Finish by importing the archetype into your preferred IDE.

You should see following structure:.
├── pom.xml
└── src
└── test
├── resources
│   ├── data
│   ├── gatling.conf
│   ├── logback.xml
│   ├── recorder.conf
│   └── request-bodies
└── scala
├── Engine.scala
├── IDEPathHelper.scala
└── Recorder.scala

Even if above instruction doesn't work, it's ok as I just wanted to show, 
how to create the performance project quickly.

Sample POM File structure:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin-demo</artifactId>
    <version>2.1.7</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <gatling.version>${project.version}</gatling.version>
        <gatling-plugin.version>2.1.7</gatling-plugin.version>
        <scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.gatling.highcharts</groupId>
            <artifactId>gatling-charts-highcharts</artifactId>
            <version>${gatling.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
    <profile>
        <id>experimentload</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>io.gatling</groupId>
                    <artifactId>gatling-maven-plugin</artifactId>
                    <version>2.1.7</version>
                    <configuration>
                        <!-- Configuration for the test results-->
                        <configFolder>src/test/resources</configFolder>
                       <dataFolder>src/test/resources/data</dataFolder>
                       <resultsFolder>results</resultsFolder>
                       <!--<requestBodiesFolder>src/test/resources/request-bodies</requestBodiesFolder>-->
                       <simulationsFolder>src/test/scala</simulationsFolder>
                    </configuration>

                    <executions>
                        <execution>
                            <id>tbs_search_test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <simulationClass>experiment.ExperimentingLoad</simulationClass>
                            </configuration>
                        </execution>

                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
</project>

 Here is the code for Simulation:

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

class SearchGoogleLoad extends Simulation {
       val httpProtocol = http
           .baseURL("http://www.google.com")
           .inferHtmlResources()
           .acceptHeader("""text/html,application/xhtml+xml,
                       application/xml;q=0.9,*/*;q=0.8""")
           .acceptEncodingHeader("""gzip, deflate""")
           .acceptLanguageHeader("""en-US,en;q=0.5""")
           .connection("""keep-alive""")
           .contentTypeHeader("""application/x-www-form-urlencoded""")
           .userAgentHeader("""Mozilla/5.0 (Macintosh; 
                               Intel Mac OS X 10.9; rv:35.0) 
                               Gecko/20100101 Firfox/35.0""")

       val header_tbs = Map("""Accept""" ->      
                            """image/png,image/*;q=0.8,*/*;q=0.5""")
       val url = """http://www.google.com"""
       val scn = scenario("Gatling_Search")
                  .exec(http("request_gatling_search")
                  .get(url + """/search?q=gatling"""))
                  .pause(5) //Real time pause
       setUp(scn.inject(atOnceUsers(100))).protocols(httpProtocol)
 }

it’s easy to understand, what’s being tested:
We are going to http://www.google.com and search for gatling keyword.
This test run for 100 users.

Here is the command to run the test:
mvn clean test -Pexperimentload

Here the result of tests:

================================================================================
 ---- Global Information --------------------------------------------------------
 > request count 1100 (OK=1100 KO=0 )
 > min response time 167 (OK=167 KO=- )
 > max response time 45219 (OK=45219 KO=- )
 > mean response time 9548 (OK=9548 KO=- )
 > std deviation 8501 (OK=8501 KO=- )
 > response time 50th percentile 7675 (OK=7675 KO=- )
 > response time 75th percentile 14493 (OK=14493 KO=- )
 > mean requests/sec 19.105 (OK=19.105 KO=- )
 ---- Response Time Distribution ------------------------------------------------
 > t < 800 ms 122 ( 11%)
 > 800 ms < t < 1200 ms 36 ( 3%)
 > t > 1200 ms 942 ( 86%)
 > failed 0 ( 0%)
 ================================================================================

it will also generate a gatling report in html format, which you can access by opening the file. You will see something like this on report:

Setup Jenkins:

Install this plugin on Jenkins:

https://wiki.jenkins-ci.org/display/JENKINS/Gatling+Plugin

Jenkins Report:

Screenshot 2015-11-23 21.05.38

Here is the sample github project, which I created to give the example:

https://github.com/skapil/gatling-google-test

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s