Revised: February 24, 2018
Gatling for Load and
Performance Testing
Kevin McGoldrick
GATLING TO SHIFT LEFT
Why use Gatling?
Develop QA Perf Stage Production
2
Develop QA Perf Stage Production
3
GATLING FOR DEVELOPERS
How to use Gatling?
• Compare to Jmeter, Locust, The Grinder, Intuit Tank, etc.
• Scala is a general-purpose programming language providing
support for functional programming and a strong static type
system. Designed to be concise, many of Scala's design
decisions aimed to address criticisms of Java.
• Gatling Cheat Sheet
val httpConf = http
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101
Firefox/16.0")
val google = scenario("Search for Game of Thrones on Google")
.exec(http("https://google.com/search?q=game+of+thrones")
.get("https://google.com/search?q=game+of+thrones"))
val yahoo = scenario("Search for Game of Thrones on Yahoo")
.exec(http("https://search.yahoo.com/search?p=game+of+thrones")
.get("https://search.yahoo.com/search?p=game+of+thrones"))
setUp(
google.inject(constantUsersPerSec(2) during(2 minutes)),
yahoo.inject(constantUsersPerSec(2) during(2 minutes))
).protocols(httpConf)
GATLING WITH MAVEN
Executing the test
5
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
</plugin>
mvn gatling:execute -Dgatling.simulationClass=<simulationName> -Denv=perf -Dpercent=10 -Dramp=15 -
Dduration=60
GATLING LOGGING, CHARTING
Fast Debugging for faster turnaround
6
GATLING LOGGING, CHARTING
Fast Debugging for faster turnaround
7
>>>>>>>>>>>>>>>>>>>>>>>>>>
Request:https://google.com/search?q=game+of+thrones: KO status.find.in(200,304,201,202,203,204,205,206,207,208,209),
but actually found 404
=========================
HTTP request:
GET https://google.com/searchz?q=game+of+thrones
headers=Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8DNT: 1Accept-Language: en-
US,en;q=0.5Accept-Encoding: gzip, deflateUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0)
Gecko/20100101 Firefox/16.0
host: google.com
=========================
HTTP response:
status=404 Not Found
headers= Content-Type: text/html; charset=UTF-8Referrer-Policy: no-referrerContent-Length: 1568Date: Thu, 22 Feb
2018 02:23:09 GMTAlt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337;
quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
Body=….a bunch of HTML returned with the 404 that I’ve hidden to fit on the slide…
<<<<<<<<<<<<<<<<<<<<<<<<<
• Header for requesting compressed content
• http.acceptEncodingHeader("gzip, deflate") or
• .header(HttpHeaderNames.ContentEncoding,"gzip, deflate")
• Compress upload payload
• .processRequestBody(gzipBody)
• .header(HttpHeaderNames.ContentEncoding, "gzip")
GATLING COMPRESSION HEADERS
Don’t forget to act like a browser
8
9
GATLING FEEDERS
Everything is a new thread
• RecordSeqFeederBuilder
• CSV feeders
• JSON feeders
• JDBC feeder
• Sitemap Feeder
• Redis feeder
Documentation
GATLING CHECKS
Validate call responses
val scn = scenario(“test”)
.exec(http(…)
.check(
status.is(200),
jsonPath("$.iamTicket.ticket").saveAs("ticket"),
jsonPath("$.iamTicket.userId").saveAs("authid")
)
)
Documentation
GATLING ASSUMPTIONS
Validation done in code
11
setUp(
…
).assertions(
forAll.responseTime.percentile1.lte(600), //50th pecentile
forAll.responseTime.percentile3.lte(800), //95th pecentile
forAll.responseTime.percentile4.lte(5000), //99th pecentile
global.successfulRequests.percent.gt(99)
)
Documentation
CONCURRENTHASHMAP
To share data between threads
12
• Data specific to a user, or situation can be stored in a way
the async threads can access without error.
• Source
• API for Pipelining automated testing
• Live charting of performance data (Cassandra)
• Driver machines utilized from cloud providers
• Split load across driver machines
• frontline
GATLING WITH FRONTLINE
Pipeline testing
13
Thank you

Gatling.for.load.and.performance.testing

  • 1.
    Revised: February 24,2018 Gatling for Load and Performance Testing Kevin McGoldrick
  • 2.
    GATLING TO SHIFTLEFT Why use Gatling? Develop QA Perf Stage Production 2 Develop QA Perf Stage Production
  • 3.
    3 GATLING FOR DEVELOPERS Howto use Gatling? • Compare to Jmeter, Locust, The Grinder, Intuit Tank, etc. • Scala is a general-purpose programming language providing support for functional programming and a strong static type system. Designed to be concise, many of Scala's design decisions aimed to address criticisms of Java. • Gatling Cheat Sheet
  • 4.
    val httpConf =http .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") .doNotTrackHeader("1") .acceptLanguageHeader("en-US,en;q=0.5") .acceptEncodingHeader("gzip, deflate") .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0") val google = scenario("Search for Game of Thrones on Google") .exec(http("https://google.com/search?q=game+of+thrones") .get("https://google.com/search?q=game+of+thrones")) val yahoo = scenario("Search for Game of Thrones on Yahoo") .exec(http("https://search.yahoo.com/search?p=game+of+thrones") .get("https://search.yahoo.com/search?p=game+of+thrones")) setUp( google.inject(constantUsersPerSec(2) during(2 minutes)), yahoo.inject(constantUsersPerSec(2) during(2 minutes)) ).protocols(httpConf)
  • 5.
    GATLING WITH MAVEN Executingthe test 5 <plugin> <groupId>io.gatling</groupId> <artifactId>gatling-maven-plugin</artifactId> <version>3.0.0-M2</version> <executions> <execution> <goals> <goal>execute</goal> </goals> </execution> </executions> </plugin> mvn gatling:execute -Dgatling.simulationClass=<simulationName> -Denv=perf -Dpercent=10 -Dramp=15 - Dduration=60
  • 6.
    GATLING LOGGING, CHARTING FastDebugging for faster turnaround 6
  • 7.
    GATLING LOGGING, CHARTING FastDebugging for faster turnaround 7 >>>>>>>>>>>>>>>>>>>>>>>>>> Request:https://google.com/search?q=game+of+thrones: KO status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 404 ========================= HTTP request: GET https://google.com/searchz?q=game+of+thrones headers=Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8DNT: 1Accept-Language: en- US,en;q=0.5Accept-Encoding: gzip, deflateUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0 host: google.com ========================= HTTP response: status=404 Not Found headers= Content-Type: text/html; charset=UTF-8Referrer-Policy: no-referrerContent-Length: 1568Date: Thu, 22 Feb 2018 02:23:09 GMTAlt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35" Body=….a bunch of HTML returned with the 404 that I’ve hidden to fit on the slide… <<<<<<<<<<<<<<<<<<<<<<<<<
  • 8.
    • Header forrequesting compressed content • http.acceptEncodingHeader("gzip, deflate") or • .header(HttpHeaderNames.ContentEncoding,"gzip, deflate") • Compress upload payload • .processRequestBody(gzipBody) • .header(HttpHeaderNames.ContentEncoding, "gzip") GATLING COMPRESSION HEADERS Don’t forget to act like a browser 8
  • 9.
    9 GATLING FEEDERS Everything isa new thread • RecordSeqFeederBuilder • CSV feeders • JSON feeders • JDBC feeder • Sitemap Feeder • Redis feeder Documentation
  • 10.
    GATLING CHECKS Validate callresponses val scn = scenario(“test”) .exec(http(…) .check( status.is(200), jsonPath("$.iamTicket.ticket").saveAs("ticket"), jsonPath("$.iamTicket.userId").saveAs("authid") ) ) Documentation
  • 11.
    GATLING ASSUMPTIONS Validation donein code 11 setUp( … ).assertions( forAll.responseTime.percentile1.lte(600), //50th pecentile forAll.responseTime.percentile3.lte(800), //95th pecentile forAll.responseTime.percentile4.lte(5000), //99th pecentile global.successfulRequests.percent.gt(99) ) Documentation
  • 12.
    CONCURRENTHASHMAP To share databetween threads 12 • Data specific to a user, or situation can be stored in a way the async threads can access without error. • Source
  • 13.
    • API forPipelining automated testing • Live charting of performance data (Cassandra) • Driver machines utilized from cloud providers • Split load across driver machines • frontline GATLING WITH FRONTLINE Pipeline testing 13
  • 14.

Editor's Notes

  • #3 Solving for: Developers own the perf code, to be updated as part of the same workflow as adding the feature, and QA testing of feature Existing work flow passes the same work between different owners. Each one learning the code, and requesting help from previous owners to complete. Shift left puts more work on the initial developer to own the outcome by owning each of the stages the code passes through. Reduces Context switching as issues are found and developers need to be spun back up on something old to them.
  • #4 Programmers are already comfortable with programming solutions. Gatling provides the testing tool in the form of programming a solution.
  • #7 Example of failure during test run on desktop
  • #8 Existing work flow passes the same work between different owners. Each one learning the code, and requesting help from previous owners to complete. Shift left puts more work on the initial developer to own the outcome by owning each of the stages the code passes through. Reduces Context switching as issues are found and developers need to be spun back up on something old to them.
  • #9 With great power comes great responsibility