question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible memory leak when resetting session inside a loop

See original GitHub issue

Hi guys.

I think there is a memleak in the session object when you reset your session attributes while looping via repeat/asLongAs/forever/etc. statements. I use session reset to mimic close workload model of the SUT.

Please see below.

The environment:

  • current Gatling version: 2.3.1
  • OS version: macOS High Sierra 10.13.6
  • Gatling run via current SBT plugin (gatling/gatling-sbt-plugin-demo)

The steps:

  • clone the newest gatling/gatling-sbt-plugin-demo project
  • enable verbose logback output to see all requests/session bags
  • edit the ComputerWorld simulation to run in a loop with session reset:
class ComputerWorld extends Simulation {
  val httpProtocol = http
    .baseURL("http://computer-database.gatling.io")
    .acceptHeader("""text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""")
    .acceptEncodingHeader("""gzip, deflate""")
    .acceptLanguageHeader("""en-gb,en;q=0.5""")
    .userAgentHeader("""Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0""")

  val computerDbScn = scenario("Computer Scenario").repeat(10, "repeat_counter") {
    pause(5).exec(_.reset)

    .exec(http("getComputers")
    .get("/computers")
      .check(
        status is 200,
        regex("""\d+ computers found"""),
        css("#add", "href").saveAs("addComputer")))

    .exec(http("addNewComputer")
    .get("${addComputer}")
      .check(substring("Add a computer")))

    .exec(_.set("homeComputer", s"homeComputer_${ThreadLocalRandom.current.nextInt(Int.MaxValue)}"))
    .exec(http("postComputers") 
    .post("/computers")
      .formParam("name", "${homeComputer}") 
      .formParam("introduced", "2015-10-10") 
      .formParam("discontinued", "2017-10-10") 
      .formParam("company", "") 
      .check(substring("${homeComputer}")))
  }

  setUp(computerDbScn.inject(
    atOnceUsers(1)
  ).protocols(httpProtocol)) 
}
  • run the ComputerWorld simulation, i.e.: sbt "gatling:testOnly computerdatabase.ComputerWorld"
  • observe the contents of the session in the logback output

Actual result: The size of the blockStack inside session increases with new instances of ExitOnCompleteLoopBlock added in each loop iteration, i.e.:

List(ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter), ExitOnCompleteLoopBlock(repeat_counter))

Moreover, the simulation loops forever instead of stopping after requested number of repetitions, which bothers me even more.

Expected result: There should be only one instance of ExitOnCompleteLoopBlock in the session, like it is when the session is not reset inside a loop. The simulation should stop after looping the requested times.

I hope you’ll be able to reproduce and fix this 😃

Thanks for the great piece of software and best regards, Adam

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
slandellecommented, Aug 27, 2018

Note that Session#reset will no longer remove Gatling internal attributes, including caches. Also note that Gatling 3 will support closed workload model.

0reactions
slandellecommented, Aug 27, 2018

closed by 8164abd

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tensorflow : Memory leak even while closing Session?
Explicitly create a new graph in each for loop. This might be necessary if the structure of the graph depends on the data...
Read more >
Mystery Memory Leak: Where Did My Memory Go?!
If you have a memory leak and get to the point of almost running out of memory, the normal procedure is to reboot...
Read more >
Chapter 12 Release Memory | Best Coding Practices for R
Here in the code above I am running a long loop but after every 100 iterations I am freeing up memory by running...
Read more >
Avoiding Memory Leaks in Node.js: Best Practices for ...
In simple terms, a memory leak is nothing but an orphan block of memory on the heap that is no longer used by...
Read more >
Java Memory Leaks: Solutions, Tools, Tutorials & More - Stackify
This is true, even if you specify System.gc(). The garbage collector will probably run when memory runs low or when the available memory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found