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?
- Refer to the JMeter log file in the bin folder apache-jmeter-<version> -> bin -> jmeter.log
- 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.
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:
- Go to the bin folder of JMeter
apache-jmeter-<version> -> bin - Right-click and open jmeter.bat file in notepad or notepad++
- Search for the keyword ‘set Heap’
- You can see the default heap size (1 GB – may vary in your JMeter version)
set HEAP=-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m - 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 - 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”
How to validate the applied changes?
- Launch a new instance of JMeter
- Add a ‘Thread Group‘
- Add a ‘JSR223 Sample’ under the ‘Thread Group’
- Paste the below code in the ‘Script’ section
java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().each {
log.info("Effective JVM argument: " + "$it")
}
- Run the test
- Check the JVM argument values in the log by clicking the yellow colour triangle in the right corner.
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