Tuesday, August 11, 2015

Gatling : Things to know to work with Gatling

Virtual User : Some load testing tools can’t deal with logic between requests but Gatling can deal with virtual users, each one having its own data and maybe taking a distinct browsing path.

Some tools implement those virtual users as threads but Gatling implements them as messages that scales much better and can deal easily with thousands of concurrent users.

Scenario : Gatling represents user’s behavior as scenario which is written as scripts following Scala syntax. Creation of the scenarios is very important as it is the key to meaningful results of the load test.
So it should be designed in such a way that represent true users behavior. Virtual users will follow the scenario that represents a typical user behavior.

For example, a standard search application scenario could be:

  1. Open the Browser and go to the site : http://www.bing.com/
  2. Enter the text “Gatling” at search text box
  3. Click Search button and Gatling related page with link is displayed
  4. Click on the link text “Gatling - Official Site”

Scenarios are represented as scripts in conjunction with a DSL (Domain Specific Language). This allows fast writing of scenarios and easy maintenance of existing scenarios.

If we want to write the above scenario using DSL then,

  scenario("GatlingSearch")
  .exec(http("Go to Bing Site").get("http://www.bing.com/")
  .pause(10)
  .exec(http("Search with the word 'Gatling'").get("http://www.bing.com/search?q=Gatling")
  .pause(30)
   .exec(http("Click in the link Gatling - Official Site").get("http://gatling.io/#/")
  .pause(10)

Note in this scenario, “GatlingSearch” is the scenario name, contains 3 HTTP Requests and 3 pauses.
Pauses are used to simulate user think time. HTTP requests are actually sent to the application under test when a user clicks on a button or a link.

Simulation : Simulation defines how many users will perform the scenario. There may be different types of users and their numbers are different for different scenario. It also defines on how virtual users will be injected. All the users execute the scenario at a time or ramp up in a certain time period.

For example,

val standardUser= scenario("Scenario X")
val adminUser= scenario("Scenario Y")
val advancedUser= scenario("Scenario Z")

setUp(
  standardUser.inject(atOnceUsers(2000)),
  adminUser.inject(nothingFor(60 seconds), rampUsers(5) over (400 seconds)),
  advancedUser.inject(rampUsers(500) over (200 seconds))
)

Session : Each virtual user is backed by a Session that is basically a state placeholder, where testers can inject or capture and store data.

Feeders : Feeders are API for testers to provide test data from an external source into the virtual users’ sessions since Gatling doesn’t provide any tools to generate test data.

Checks : Gatling analyze and verifies the response using Check which is a response processor that captures some part of response and verifies that it meets some given condition(s). It can also be used to capture some elements and store them into the Session so that they can be reused later.

Assertions : Assertions are used to define acceptance criteria on Gatling statistics that would make Gatling fail and return an error status code for the test as a whole.

Reports : Reports are automatically generated by default at the end of a simulation. They consist of HTML files that are portable and can be viewed on any device with a web browser.

We will discuss more on everything on our future post.

Happy Load testing using Gatling!!!