All HowTo's Linux Ubuntu, Mint & Debian Linux

Basic Website Stress-Test with Gatling2

This article demonstrates how to run a basic website stress-test using Gatling2. See the previous article on how to install Galting2. In this example, i’m running Gatling2 from “/root/gatling2/”.

Create a file in the “/root/gatling2/user-files/simulation/” directory called “MyTest1.scala” (/root/gatling2/user-files/simulation/MyTest1.scala). Add the following content to it:

import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.http.Headers.Names._
import io.gatling.http.Headers.Values._
import scala.concurrent.duration._
import bootstrap._
import assertions._

class MyTest2 extends Simulation {

        val httpProtocol = http
                .baseURL("http://www.agix.local")
                .acceptHeader("image/png,image/*;q=0.8,*/*;q=0.5")
                .acceptEncodingHeader("gzip, deflate")
                .acceptLanguageHeader("en-us,en;q=0.5")
                .userAgentHeader("Mozilla/5.0 (X11; Linux x86_64; rv:10.0.8) Gecko/20121010 Firefox/10.0.8")

        val headers_1 = Map("""Accept""" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""")

        val headers_4 = Map("""Accept""" -> """*/*""")

        val scn = scenario("Scenario Name")
                .exec(http("request_10")
                        .get("""http://agix.local/blog/?p=2656"""))
                .pause(4)
                .exec(http("request_11")
                        .get("""http://agix.local/blog/?p=2696"""))
                .pause(4)
                .exec(http("request_12")
                        .get("""http://agix.local/blog/?p=2320"""))
                .pause(4)
                .exec(http("request_13")
                        .get("""http://agix.local/blog/?p=3345"""))
                .pause(4)
                .exec(http("request_14")
                        .get("""http://agix.local/blog/?p=912"""))
                .pause(4)
                .exec(http("request_15")
                        .get("""http://agix.local/blog/?p=3458"""))
                .pause(4)

        setUp(scn.inject(atOnce(30 user))).protocols(httpProtocol)
}

In the above, change the URL’s in bold with the URL’s that you want to include in your stress-test.

Now you can run Gatling like this:

cd ~
gatling2/bin/gatling.sh

Output form the above:

GATLING_HOME is set to /root/gatling2
Choose a simulation number:
[0] MyTest1
[1] MyTest2
[2] MyTest3

At this point you can choose the number (relating to the test you want to run) and start the stress-test. When done, you can copy the results (which is a website complete with styles) to your website root directory so you can view the results. For example, i want to copy my results to my webserver at “www.agix.com.au/results”:

scp -r /root/gatling2/results/0-20131125095458 /var/www/html/results/MyTest1