Search code examples
javasbtheap-memoryload-testinggatling

Gatling: Parsing log file - OutOfMemoryError: Java heap space


I start sbt with -Xmx4G options specified:

java -Xms2G -Xmx4G -jar "C:\Program Files (x86)\sbt\bin\sbt-launch.jar"

But at the end of the test run, Gatling fails with OutOfMemoryError: Java heap space

Parsing log file(s)...
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid17300.hprof ...Only 1223s
Dumping heap to java_pid17300.hprof ...Heap dump file created [1320803380 bytes in 4.554 secs]
[error] Uncaught exception when running test.FeLoadTest: java.lang.OutOfMemoryError: Java heap space

It is seen from the error message that the heap is only 1320803380 bytes ~> 1.2G. But as I have set Xmx to 4G, I do not understand why this OutOfMemoryError happens - the allocated memory should be enough. Any help to overcome this error while parsing the test log file is appreciated.


Solution

  • Finally, found the answer - see here

    The solution is to increase memory for gatling-plugin, not for sbt. In build.sbt file need to add javaOptions:

    # this is build.sbt file
    
    lazy val root = Project("testing-gatling", file("."))
      .enablePlugins(GatlingPlugin)
      .settings(...)
      .settings(javaOptions in Gatling := overrideDefaultJavaOptions("-Xms1024m", "-Xmx4096m"))
    

    It works for me now.