# Java heap space exception

**URL:** <https://community.gatling.io/t/java-heap-space-exception/1972>\
**Category:** Gatling (Open-Source)\
**Created:** [February 5, 2015, 9:07am UTC](https://community.gatling.io/t/java-heap-space-exception/1972 "2015-02-05T09:07:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![empty\_account](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@empty\_account](https://community.gatling.io/u/empty_account)\
**Post date:** [February 5, 2015, 9:07am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/1 "2015-02-05T09:07:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 5, 2015, 9:14am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/2 "2015-02-05T09:14:31Z")

</div>

Hi Adrian,

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

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 5, 2015, 9:22am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/3 "2015-02-05T09:22:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![empty\_account](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@empty\_account](https://community.gatling.io/u/empty_account)\
**Post date:** [February 5, 2015, 9:36am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/4 "2015-02-05T09:36:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![empty\_account](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@empty\_account](https://community.gatling.io/u/empty_account)\
**Post date:** [February 5, 2015, 9:41am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/5 "2015-02-05T09:41:20Z")

</div>

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](https://github.com/BBC/gatling-load-tests/blob/master/src/test/resources/logback-test.xml#L22)

Adrian

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 5, 2015, 10:29am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/6 "2015-02-05T10:29:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)\
**Post date:** [February 5, 2015, 11:07am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/7 "2015-02-05T11:07:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![empty\_account](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@empty\_account](https://community.gatling.io/u/empty_account)\
**Post date:** [February 5, 2015, 11:23am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/8 "2015-02-05T11:23:35Z")

</div>

You’re a genius Pierre…

For anyone else:  
// build.sbt

import io.gatling.sbt.GatlingPlugin.Gatling

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

Adrian

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)\
**Post date:** [February 5, 2015, 11:28am UTC](https://community.gatling.io/t/java-heap-space-exception/1972/9 "2015-02-05T11:28:19Z")

</div>

Thank you 🙂

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