Skip to main content

Gatling Load Test Tricks and Debug

Introduction:

Gatling is a light weighted load generator. Though it is 'load test as code', sometimes it is hard to debug. Especially when there is lack of documentation and tutorial. I run into an issue when upgrading from 2.3.1 to 3.0.2. The error message is not very helpful.

Here I will show this case to illustrate an upgrading issue, as well is tricks to print out some debug information.

Some Debug Tricks:

According to gatling document, you can print out debug information in 2 ways.
  • change conf/logback.xml to DEBUG/TRACE for logger name="io.gatling.http.engine.response"
This generates too much information and my tests times out.

  •  Use println in exec. This is more flexible and can prints the exact information I need. How ever I would like to put the debug messages in a separate file. Here is an example:
val file = System.getProperty("file", "/tmp/debug_cookie.out")
 val scn = scenario(myReadScenario) 
 .during (myDuration) { feed(userData)
 .exec(http(myReadRequest)
 .get("something that returns pagedResultsCookie at the end")
 .queryParam("_pageSize", "1")
 .check(jsonPath("$.pagedResultsCookie").saveAs("pageCookie")))
 .asLongAs(some-condition) {
 exec(session => {
 scala.tools.nsc.io.File(file).appendAll("debug====")
 scala.tools.nsc.io.File(file).appendAll(session("pageCookie").as[String]+"\n")
 session
 })
 .exec(http(myReadRequest)
 .get("something that returns pagedResultsCookie at the end")
 .queryParam("_pageSize", "50")
 .queryParam("_pagedResultsCookie", "${pageCookie}")
 .check(jsonPath("$.pagedResultsCookie").saveAs("pageCookie")))
}
The code won't work in 3.0.2, but as an example how to print debug information tailored to my case.

It works in 2.3.1 But not in 3.0.2:

I have a test that go over each page of pagination. In 2.3.1, I used something like:
val scn = scenario(myReadScenario)
.during (myDuration) {
    feed(userData)
   .exec(http(myReadRequest)
   .get("something that returns pagedResultsCookie at the end")
   .queryParam("_pageSize", "50")
   .check(jsonPath("$.pagedResultsCookie").saveAs("pageCookie")))
   .asLongAs(session => session("pageCookie").as[String] != null) {
           exec(http(myReadRequest)
       .get("/openidm/managed/role/${name}/members")
       .queryParam("_pageSize", "50")
       .queryParam("_pagedResultsCookie", "${pageCookie}")
       .check(jsonPath("$.pagedResultsCookie").saveAs("pageCookie")))
   }
}
In 3.0.2, It throws an exception 'j.l.ClassCastException: value is null'

I have to read the gatling session source code to understand why the exception is thrown. The session("key") returns asOption. When the response has '"PagedResultsCookie": null' the asOption tries to cast the value null into String. That is the short version of the explanation. But I do not understand why it works in 2.3.1.
My current workaround is use:
.asLongAs(session => session.attributes.getOrElse("pageCookie", null) != null )
This will by pass the wrapper for session. Maybe there is a better solution, I'd be happy to know it.

References:

https://gatling.io/docs/current/whats_new/3.0/?highlight=transformresponse
https://gatling.io/docs/current/migration_guides/2.3-to-3.0/

Comments

Popular posts from this blog

Performance Test with Gatling in Cloud

Introduction: A lot of our performance tests are driven by gatling. When moving our tests to Google cloud, we face a lot of questions. One of them is how to manage the life cycle of the test. First, we need to generate the .csv file as the feeder to the gatling test. Second, we need to know when the test is finished. Third, we need to retrieve the results from the cloud. According to  Distributed load testing with Gatling and Kubernetes , a Kubernetes Job should be used. While this blog provides good information, I still need to figure out how to create the feeder .csv and share it with gatling script.  Using InitContainers to pre-populate Volume data in Kubernetes provides me another piece of information. In this blog post, I will show you my experiment of creating a Kubernetes job to drive performance workload with Gatling. Create Feeder script: My gatling script reads the feeder .csv (benchmark.csv). I have a python script generating the benchmark.csv file. 

G1GC Performance Tuning Parameters

G1GC Performance Tuning Parameters In this post, I will list some common observations from G1GC logs, and the parameters you can try to tune the performance. To print GC logs, please refer to  my blog about how to print gc logs . Threads Related In JDK9, with -Xlog:gc*=info, or -Xlog:gc+cpu=info, you can get log entry like: [12.420s][info][gc,cpu      ] GC(0) User=0.14s Sys=0.03s Real=0.02s This can give you some indication about the cpu utilization for the GC pause. For example, this entry indicates for this gc pause, total user-cpu is 0.14s, wall time is 0.02s, and system time is 0.03s. The ratio of User/Real could be used as an estimation of number of gc threads you need. For this case, 18 gc threads should be good. If you see long termination time,  User/Real less than the gc threads, you can try to reduce the number of gc threads. Here is a list of threads related parameters: Name Pa