OOM on gatling

I am getting this when running gatling:

Dumping heap to java_pid8409.hprof …
Heap dump file created [585273257 bytes in 5.761 secs]
Uncaught error from thread [GatlingSystem-akka.actor.default-dispatcher-7] shutting down JVM since ‘akka.jvm-exit-on-fatal-error’ is enabled for ActorSystem[GatlingSystem]
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:2694)
at java.lang.String.(String.java:203)
at java.nio.HeapCharBuffer.toString(HeapCharBuffer.java:561)
at java.nio.CharBuffer.toString(CharBuffer.java:1201)
at org.jboss.netty.buffer.ChannelBuffers.decodeString(ChannelBuffers.java:1207)
at org.jboss.netty.buffer.AbstractChannelBuffer.toString(AbstractChannelBuffer.java:550)
at org.jboss.netty.buffer.AbstractChannelBuffer.toString(AbstractChannelBuffer.java:542)
at com.ning.http.client.providers.netty.NettyResponse.getResponseBody(NettyResponse.java:92)
at io.gatling.http.response.GatlingResponse.getResponseBody(Response.scala:61)
at io.gatling.http.check.HttpCheckBuilders$$anonfun$2.apply(HttpCheckBuilders.scala:36)
at io.gatling.http.check.HttpCheckBuilders$$anonfun$2.apply(HttpCheckBuilders.scala:36)
at io.gatling.core.check.CheckBase$$anonfun$memoizedPrepared$1$1.apply(Check.scala:53)
at io.gatling.core.check.CheckBase$$anonfun$memoizedPrepared$1$1.apply(Check.scala:53)
at scala.collection.mutable.MapLike$class.getOrElseUpdate(MapLike.scala:189)
at scala.collection.mutable.AbstractMap.getOrElseUpdate(Map.scala:91)
at io.gatling.core.check.CheckBase.memoizedPrepared$1(Check.scala:53)
at io.gatling.core.check.CheckBase.check(Check.scala:63)
at io.gatling.http.check.HttpCheck.check(HttpCheck.scala:30)
at io.gatling.http.check.HttpCheck.check(HttpCheck.scala:29)
at io.gatling.core.check.Checks$$anonfun$check$1$$anonfun$apply$1.apply(Check.scala:30)
at io.gatling.core.check.Checks$$anonfun$check$1$$anonfun$apply$1.apply(Check.scala:30)
at io.gatling.core.validation.Success.flatMap(Validation.scala:27)
at io.gatling.core.check.Checks$$anonfun$check$1.apply(Check.scala:30)
at io.gatling.core.check.Checks$$anonfun$check$1.apply(Check.scala:29)
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
at scala.collection.immutable.List.foldLeft(List.scala:84)
at io.gatling.core.check.Checks$.check(Check.scala:29)
at io.gatling.http.ahc.GatlingAsyncHandlerActor.checkAndProceed$1(GatlingAsyncHandlerActor.scala:224)
at io.gatling.http.ahc.GatlingAsyncHandlerActor.io$gatling$http$ahc$GatlingAsyncHandlerActor$$processResponse(GatlingAsyncHandlerActor.scala:237)
at io.gatling.http.ahc.GatlingAsyncHandlerActor$$anonfun$receive$1.applyOrElse(GatlingAsyncHandlerActor.scala:103)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
at akka.actor.ActorCell.invoke(ActorCell.scala:386)

I am getting it quite often now even i am up the xmx to 3072M (used to be 512M).

My scenario is a little bit tricky, since as requested, our testing scenarios are long sessions from the start of the run to the end of the run. So I guess probably that is why the memory can not be released and cause this OOM?

Any help on this?

Well, I would need your heap dump.
Would you happen to do your own stuff with the response bodies, like saving them into the Session (willingly, or unwillingly, like doing a substring or a regex and saving the result)?

Add this option to Java for the heap dump: -XX:+HeapDumpOnOutOfMemoryError

Yeah, I do need to save some bodyString to parse since the regex does not fit me. Should I use the tranform function instead of saving the body string in sessions and do the parse there? Will that make differences?

Yes, you should be using transform so that you only save the bits you’re interested in and the body strings can be garbage collected ASAP.
If you don’t/can’t do that, at least remove the attributes storing body strings as soon as you’re done parsing them.

Ok I will remove those attributes from the sessions after done.

So I am using 2.0.0M.
https://github.com/excilys/gatling/wiki/Gatling-2

Does session still have the removeAttribute functions? Seems like it goes away for 2.0.0. What's the best way to do that?

session.set(attributeName, null)?

BTW, Do you have some good examples on how to use transform function? I looked at wiki one, it is pretty simple. Want to get more help on how to write those

Never mind, it is more about scala, I can figure it out by myself

Thx for the help!