Java heap space exception

Hi,

I am on a Linux box with 7.5 GiB of memory and I have set my Java heap space through SBT with a max of 5G

$ sbt -J-Xmx5G -J-Xms2G

I am receiving this exception:

java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid1707.hprof …
Heap dump file created [603376716 bytes in 2.324 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:1191)

I was wondering if there was anything else I could do without running the tests on multiple machines?

Many Thanks

Adrian

Hi Adrian,

Could you share the heap dump + the full stracktrace, please?

Except if there’s a bug in Gatling (or some limitation like the one that was recently reported against the InputStream/slow network combo), I usually see this when people just save tons of response bodies in the session and never clean up.

Hi Stephane

This is the full stack trace.

java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid9127.hprof …
Heap dump file created [601070997 bytes in 2.235 secs]
Exception in thread “pool-5-thread-7” java.lang.OutOfMemoryError: Java heap space
Feb 05, 2015 9:23:50 AM org.jboss.netty.channel.socket.nio.AbstractNioSelector
WARNING: Unexpected exception in the selector loop.
java.lang.OutOfMemoryError: Java heap space

Feb 05, 2015 9:24:16 AM org.jboss.netty.channel.socket.nio.AbstractNioSelector
WARNING: Unexpected exception in the selector loop.
java.lang.OutOfMemoryError: Java heap space

Uncaught error from thread [GatlingSystem-akka.actor.default-dispatcher-3] shutting down JVM since ‘akka.jvm-exit-on-fatal-error’ is enabled for ActorSystem[GatlingSystem]
java.lang.OutOfMemoryError: Java heap space
Uncaught error from thread [GatlingSystem-akka.actor.default-dispatcher-10] shutting down JVM since ‘akka.jvm-exit-on-fatal-error’ is enabled for ActorSystem[GatlingSystem]
java.lang.OutOfMemoryError: Java heap space
Uncaught error from thread [GatlingSystem-akka.actor.default-dispatcher-6] shutting down JVM since ‘akka.jvm-exit-on-fatal-error’ is enabled for ActorSystem[GatlingSystem]
java.lang.OutOfMemoryError: Java heap space
Feb 05, 2015 9:24:02 AM org.jboss.netty.channel.socket.nio.AbstractNioSelector
WARNING: Unexpected exception in the selector loop.
java.lang.OutOfMemoryError: Java heap space

Exception in thread “Thread-1” java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2598)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1318)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
at sbt.React.react(ForkTests.scala:114)
at sbt.ForkTests$$anonfun$mainTestTask$1$Acceptor$2$.run(ForkTests.scala:74)
at java.lang.Thread.run(Thread.java:745)
[info] Simulation(s) execution ended.
[error] Error during tests:
[error] Running java with options -classpath /home/adrian_lewis/gatling-load-tests/target/scala-2.11/gatling-classes:/home/adrian_lewis/gatling-load-tests/target/scala-2.11/classes:/home/adrian_lewis/gatling-load-tests/target/scala-2.11/test-classes:/home/adrian_l
ewis/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.5.jar:/home/adrian_lewis/.ivy2/cache/io.gatling.highcharts/gatling-charts-highcharts/jars/gatling-charts-highcharts-2.1.3.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-charts/jars/gatling-charts
-2.1.3.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-core/jars/gatling-core-2.1.3.jar:/home/adrian_lewis/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.5.jar:/home/adrian_lewis/.ivy2/cache/com.typesafe.akka/akka-actor_2.11/jars/akka-actor_2.11-2.
3.8.jar:/home/adrian_lewis/.ivy2/cache/com.typesafe/config/bundles/config-1.2.1.jar:/home/adrian_lewis/.ivy2/cache/com.dongxiguo/fastring_2.11/jars/fastring_2.11-0.2.4.jar:/home/adrian_lewis/.ivy2/cache/net.sf.opencsv/opencsv/jars/opencsv-2.3.jar:/home/adrian_lewis/.ivy2/
cache/com.googlecode.concurrentlinkedhashmap/concurrentlinkedhashmap-lru/jars/concurrentlinkedhashmap-lru-1.4.1.jar:/home/adrian_lewis/.ivy2/cache/org.threeten/threetenbp/jars/threetenbp-1.2.jar:/home/adrian_lewis/.ivy2/cache/org.scala-lang.modules/scala-parser-combinator
s_2.11/bundles/scala-parser-combinators_2.11-1.0.3.jar:/home/adrian_lewis/.ivy2/cache/com.ning/async-http-client/jars/async-http-client-1.9.5.jar:/home/adrian_lewis/.ivy2/cache/io.netty/netty/bundles/netty-3.10.0.Final.jar:/home/adrian_lewis/.ivy2/cache/org.slf4j/slf4j-ap
i/jars/slf4j-api-1.7.9.jar:/home/adrian_lewis/.ivy2/cache/com.typesafe.scala-logging/scala-logging_2.11/jars/scala-logging_2.11-3.1.0.jar:/home/adrian_lewis/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.1.2.jar:/home/adrian_lewis/.ivy2/cache/ch.qos.log
back/logback-core/jars/logback-core-1.1.2.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/jsonpath_2.11/jars/jsonpath_2.11-0.6.2.jar:/home/adrian_lewis/.ivy2/cache/com.fasterxml.jackson.core/jackson-databind/bundles/jackson-databind-2.4.4.jar:/home/adrian_lewis/.ivy2/cache/
com.fasterxml.jackson.core/jackson-annotations/bundles/jackson-annotations-2.4.0.jar:/home/adrian_lewis/.ivy2/cache/com.fasterxml.jackson.core/jackson-core/bundles/jackson-core-2.4.4.jar:/home/adrian_lewis/.ivy2/cache/io.fastjson/boon/jars/boon-0.30.jar:/home/adrian_lewis
/.ivy2/cache/net.sf.saxon/Saxon-HE/jars/Saxon-HE-9.6.0-3.jar:/home/adrian_lewis/.ivy2/cache/org.jodd/jodd-lagarto/jars/jodd-lagarto-3.6.3.jar:/home/adrian_lewis/.ivy2/cache/org.jodd/jodd-core/jars/jodd-core-3.6.3.jar:/home/adrian_lewis/.ivy2/cache/org.jodd/jodd-log/jars/j
odd-log-3.6.3.jar:/home/adrian_lewis/.ivy2/cache/com.tdunning/t-digest/jars/t-digest-3.0.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-app/jars/gatling-app-2.1.3.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-http/jars/gatling-http-2.1.3.jar:/home/adrian_le
wis/.ivy2/cache/com.jcraft/jzlib/jars/jzlib-1.1.3.jar:/home/adrian_lewis/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.3.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-jms/jars/gatling-jms-2.1.3.jar:/home/adrian_lewis/.ivy2/cache/org.
apache.geronimo.specs/geronimo-jms_1.1_spec/jars/geronimo-jms_1.1_spec-1.1.1.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-jdbc/jars/gatling-jdbc-2.1.3.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-redis/jars/gatling-redis-2.1.3.jar:/home/adrian_lewis/.ivy
2/cache/net.debasishg/redisclient_2.11/jars/redisclient_2.11-2.14.jar:/home/adrian_lewis/.ivy2/cache/commons-pool/commons-pool/jars/commons-pool-1.6.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-metrics/jars/gatling-metrics-2.1.3.jar:/home/adrian_lewis/.ivy2/cache
/com.github.scopt/scopt_2.11/jars/scopt_2.11-3.3.0.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-recorder/jars/gatling-recorder-2.1.3.jar:/home/adrian_lewis/.ivy2/cache/org.scala-lang.modules/scala-swing_2.11/bundles/scala-swing_2.11-1.0.1.jar:/home/adrian_lewis/.
ivy2/cache/org.bouncycastle/bcpkix-jdk15on/jars/bcpkix-jdk15on-1.51.jar:/home/adrian_lewis/.ivy2/cache/org.bouncycastle/bcprov-jdk15on/jars/bcprov-jdk15on-1.51.jar:/home/adrian_lewis/.ivy2/cache/io.gatling/gatling-test-framework/jars/gatling-test-framework-2.1.3.jar:/home
/adrian_lewis/.ivy2/cache/org.scala-sbt/test-interface/jars/test-interface-1.0.jar:/home/adrian_lewis/.sbt/boot/scala-2.10.4/org.scala-sbt/sbt/0.13.7/test-agent-0.13.7.jar:/home/adrian_lewis/.sbt/boot/scala-2.10.4/org.scala-sbt/sbt/0.13.7/test-interface-1.0.jar sbt.ForkMa
in 39915 failed with exit code 255
[error] (gatling:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 234 s, completed 05-Feb-2015 09:24:32

I will also send the heap dump once I SCP it.

Many Thanks

Adrian

Hi Stephane,

Logback is only logging failed requests/responses which are few.

https://github.com/BBC/gatling-load-tests/blob/master/src/test/resources/logback-test.xml#L22

Adrian

You’re actually still running with the default 512Mo heap.

I’m not sure how you increase it from the sbt plugin. Pierre, our sbt expert will answer in a few hours.

Hi,

What you’ve did here is increase the heap size for SBT, but this does not affect Gatling.

If you want to modify the max heap size for Gatling, you’ll need to do it through the ‘javaOptions in Gatling’ setting, e.g. in your build.sbt file:

javaOptions in Gatling := “-Xms2G-Xmx5G”

Cheers,

Pierre

You’re a genius Pierre…

For anyone else:
// build.sbt

import io.gatling.sbt.GatlingPlugin.Gatling

javaOptions in Gatling := Seq("-Xms2G", “-Xmx5G”)

Adrian

Thank you :slight_smile:

This is indeed something that should be better documented, and it will : https://github.com/gatling/gatling/issues/2547