Load Testing with Gatling

Doug Fitzmaurice

From this

To this

  • How do we ensure stability?
  • How many users can we handle?
  • What is response time like under load?
  • Have we missed any important packages?
  • Does our monitoring work?

Gatling

  • Users, not URLs
  • Tests written in Scala
  • Actor model - high concurrency from one machine
  • Great control over traffic levels
  • Test recorder
  • Visual result summaries
val httpProtocol = http
	.baseURL("http://phpsw.uk")
	.inferHtmlResources()
	.acceptHeader("text/html, */*; q=0.01")
	.acceptEncodingHeader("gzip, deflate")
	.acceptLanguageHeader("en-GB,en;q=0.5")
	.userAgentHeader("Gatling Load Test")
val scn = scenario("PHPSWDemo")
	.exec(http().get("/"))
	.pause(3)
        .exec(http("Log In")
	    .post("/login")
	    .formParam("username", "testuser@phpsw.uk")
	    .formParam("password", "E13php4nt!")
	)
        .pause(7)
	.exec(http().get("/events/237357254-new-skills"))
	.pause(10)
	.exec(http().get("/talks"))
setUp(
	scn.inject(
            atOnceUsers(1),
            rampUsers(10) over(30 seconds)
        )
).protocols(httpProtocol)
================================================================================
2017-05-07 12:49:45                                          25s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=702    KO=0     )
> ticket                                                   (OK=53     KO=0     )
> search                                                   (OK=50     KO=0     )
> event                                                    (OK=128    KO=0     )
> misc                                                     (OK=188    KO=0     )
> artist                                                   (OK=28     KO=0     )
> index                                                    (OK=5      KO=0     )
> stream                                                   (OK=6      KO=0     )
> venue                                                    (OK=15     KO=0     )
> film                                                     (OK=2      KO=0     )

---- Desktop Users -------------------------------------------------------------
[---                                                                       ]  0%
          waiting: 6424   / active: 236    / done:5
---- Mobile Users --------------------------------------------------------------
[---                                                                       ]  0%
          waiting: 3025   / active: 95     / done:3
================================================================================

Log Replay

  • Parse web server logs
  • Produce CSV file of URLs
  • Produce traffic profile:
    • How many users?
    • How many requests each?
    • How much gap between requests?
    • How many arrive at once?
    • How many requests per second?
val webAccessLog = csv("web-traffic.csv").circular
val web = scenario("Desktop Users")
      .repeat(6, "loops") {
        feed(webAccessLog)
        .exec(
          http("${Type}")
          .get("${Path}")
          .check(status.not(500))
        )
        .pause(40)
setUp(
  web.inject(
    constantUsersPerSec(6) during(120 seconds),
    constantUsersPerSec(2) during(600 seconds),
    constantUsersPerSec(3) during(120 seconds),
    constantUsersPerSec(2) during(120 seconds),
    constantUsersPerSec(3) during(120 seconds),
    constantUsersPerSec(2) during(120 seconds),
    constantUsersPerSec(3) during(1000 seconds)
  )
).maxDuration(20 minutes).protocols(httpProtocol)

Questions?

Made with Slides.com