How to use Gatling for Load testing?

Gatling is an open source load testing tool used to test the web application running under HTTP protocol support. All HTTP protocol specific user request can be triggered by using the DSL (Domain Specific Language) from Scala and the response can be validated using different assertion/checks available in Gatling.

https://gatling.io

Gatling_1

User request can be triggered to the web server using different simulation setup as follows; User injection to the webserver will be commenced with different approach based on your needs;

setUp(

scn.inject(

nothingFor(4 seconds), // 1

atOnceUsers(10), // 2

rampUsers(10) over (5 seconds), // 3

constantUsersPerSec(20) during (15 seconds), // 4

constantUsersPerSec(20) during (15 seconds) randomized, // 5

rampUsersPerSec(10) to 20 during (10 minutes), // 6

rampUsersPerSec(10) to 20 during (10 minutes) randomized, // 7

splitUsers(1000) into (rampUsers(10) over (10 seconds)) separatedBy (10 seconds), // 8

splitUsers(1000) into (rampUsers(10) over (10 seconds)) separatedBy atOnceUsers(30), // 9

heavisideUsers(1000) over (20 seconds) // 10

).protocols(httpConf)

)

Please refer the below URL for detailed information about the simulation setup;

https://gatling.io/docs/2.3/general/simulation_setup/

The advantage of Gatling is Asynchronous support in which virtual users request will be pushed to web server in a dedicated thread in the form of messages (non-blocking approach).

Gatling Concepts:

  1. Session represent the virtual users in which request has been triggered and store the data
  2. Feeders is a data driven model in which test data can be pushed to the session
  3. Checks is used to verify the response code from web server and it can be used to capture the elements, which will be re-use for subsequent request
  4. Assertions is used to define acceptance criteria
  5. Publish HTML reports

Pre-requisite: JDK 8 should be installed in your system in which downloaded Gatling folder is enough to kick-start the load test.

Let us see the basic steps to work on the Wikipedia login request in which 10 concurrent request I’m going to trigger using Gatling tool;

Play with the Browser

  1. Open the Firefox browser (I’ve used V61.0.2)
  2. Click ‘Open Menu’
  3. Click ‘Web Developer’ option
  4. Click ‘Network’ option (Ctrl + Shift + E)
  5. Ensure ‘Persist Logs’ option enabled in the Network Monitor
  6. Copy and paste the URL in the Address bar https://en.wikipedia.org/wiki/Main_Page
  7. You could see request/response in the Network Monitor
  8. Click ‘Log in’ link in the top right corner
  9. Enter the username and password of your Wikipedia account
  10. Click Login button and ensure Wikipedia home page displayed with your account
  11. Click ‘HAR’ option in the top right corner of Network Monitor window
  12. Click ‘Save All As HAR’ (Refer below screenshot) and save the file in your system
  13. Logout and close the browser window

Gatling_2

Play with Gatling Recorder batch file

  1. Download the Gatling setup in zip format using the URL https://gatling.io/download/
  2. Unzip the file
  3. Go to ‘bin’ folder and run the ‘recorder.bat’ in the command prompt based on the below screenshot;

Gatling_3

  1. Gatling ‘Recorder Configuration’ will automatically open
  2. Click ‘HAR Converter’ as ‘Recorder mode’ in the top right corner (By default ‘HTTP Proxy’ will be there)
  3. Click ‘Browse’ button associated with ‘HAR File:’ text box
  4. Enter the package name as ‘wikigatling’ in the ‘Package:’ textbox
  5. Leave all the options as default selection based on the below screenshot
  6. Click ‘Start’ button in bottom right of the recorder configuration window

Gatling_4

  1. You could see the message ‘Success’ message of converting the HAR file to Gatling Simulation based on the below screenshot;

Gatling_5

  1. Close the Recorder Configuration window.
  2. Ensure Gatling simulation in the name of ‘wikigatling’ has been created under the ‘user-files\simulations’ folder

Play with Gatling batch file – Trigger 10 virtual user request to web server

  1. Open the ‘RecordedSimulation.scala’ file under the folder ‘user-files\simulations\wikigatling’
  2. You could see all the user actions available in the file
  3. Wikipedia website URL is available under ‘baseURL’ of httpProtocol variable
  4. HTTP request header information has been captured
  5. Scenario has been created under the name val scn = scenario(“RecordedSimulation”)
  6. Get method has been used to fetch the information from web server
  7. Post method has been used to push the username and password to the webserver
  8. Each individual request is having its unique number Example: http(“request_42”)
  9. Refer the end of the file section in which you could see the setup method
  10. Setup method comprised of scenario injection stuff in which atOnceUsers(1) one user will be appended by default
  11. Change the number of users to 10 in which at once, 10 concurrent user requests will be triggered to the web server
  12. Save the scala file after change the virtual user data as 10;

setUp(scn.inject(atOnceUsers(10))).protocols(httpProtocol)

  1. Run ‘gatling.bat’ file in the command prompt under the bin folder

Gatling_6

  1. Enter the simulation number of [11] ‘wikigatling.RecordedSimulation’ in the command prompt (Please note simulation number will vary for everyone)
  2. Press ‘Enter’ in keyboard by leaving simulation id as blank
  3. Press ‘Enter’ in keyboard by leaving run description as blank
  4. You could see Simulation started message with Requests information

Gatling_7

  1. Load Test execution got completed and Test Report has been generated in the ‘results’ folder
  2. Open the ‘index.html’ file to visualize the detailed load testing report as follows;
  • Response Time in ms – Min, 50th pct, 75th pct, 95th pct, 99th pct, Max, Min, Std Dev
  • Error section
  • Active Users Stats
  • Response Time Distribution
  • Response Time percentiles over time
  • Number of requests per second
  • Number of responses per second

Gatling_8

I will be sharing the feeder (Test data management), checks and assertion usage in the forthcoming Gatling specific post.

Thank you!!!

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 )

Connecting to %s