JMeter – How to increase heap size?

Problem Statement:

Sometimes, JMeter throws a heap dump along with an ‘out of memory’ error while executing the load test.

How to check the error?

  1. Refer to the JMeter log file in the bin folder apache-jmeter-<version> -> bin -> jmeter.log
  2. You may see the error like this.
java.lang.OutOfMemoryError: Java heap space Dumping heap to
    java_pid1102.hprof ... Heap dump file created [851645907 bytes in
    71.244 secs] Exception in thread "Thread Group 1-100" java.lang.OutOfMemoryError: Java heap space Exception in thread
    "Thread Group 1-100" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Thread Group 1-100" java.lang.OutOfMemoryError:
    Java heap space Exception in thread "Thread Group 1-100"
    java.lang.OutOfMemoryError: Java heap space

If you executed the test in GUI mode then click on the error icon (yellow triangle with exclamatory mark) on the right corner of the JMeter and read the error.

JMeter - How to increase heap size
Figure 01

Reason:

The allocated heap size to JVM is not enough to execute the test with the given load (thread).

Solution:

There could be possibly different ways to solve this problem but among them, one of the common solutions is to increase the heap size set for JMeter.

Procedure to increase heap size in JMeter:

  1. Go to the bin folder of JMeter
    apache-jmeter-<version> -> bin
  2. Right-click and open jmeter.bat file in notepad or notepad++
  3. Search for the keyword ‘set Heap’
  4. You can see the default heap size (1 GB – may vary in your JMeter version)
    set HEAP=-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m
  5. Change the -Xms (initial heap size) and -Xmx (maximum heap size) values. You can increase these values up to 80% of total heap. In my case, I just increased the max heap size value. Refer to the below arguments:
    set HEAP=-Xms1g -Xmx2g -XX:MaxMetaspaceSize=256m
  6. To check the total allocated heap to JVM, run the below command in the command prompt:
    java -XX:+PrintFlagsFinal -version | findstr /i “HeapSize PermSize ThreadStackSize”
JMeter - How to increase heap size
Figure 02

How to validate the applied changes?

  1. Launch a new instance of JMeter
  2. Add a ‘Thread Group
  3. Add a ‘JSR223 Sample’ under the ‘Thread Group’
  4. Paste the below code in the ‘Script’ section
java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().each {
    log.info("Effective JVM argument: " + "$it")
}
  1. Run the test
  2. Check the JVM argument values in the log by clicking the yellow colour triangle in the right corner.
Figure 03: JVM Arguments

1 thought on “JMeter – How to increase heap size?”

  1. This code not working for me.. request is passed but there is no information in log
    note :
    Info log level is enabled
    j meter version : 5.1

Comments are closed.