23

I am facing below OutOfMemor errors, and JMeter stops working....

java.lang.OutOfMemoryError: Java heap space Dumping heap to
    java_pid4412.hprof ... Heap dump file created [591747609 bytes in
    71.244 secs] Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space Exception in thread
    "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError:
    Java heap space Exception in thread "AWT-EventQueue-0"
    java.lang.OutOfMemoryError: Java heap space

How can it be resolved?
My System is having very good specification like 16GB RAM, 2x Quad Core processors, with 146 GB HDD.

Can anyone help me?

1

11 Answers 11

19

Your Heap dump shows that you are using default JMeter settings of 512 Mo. so even if you have 16gb you are not using them.

Replace default JVM optional in jmeter.bat to the right size:

set HEAP=-server -Xms768m -Xmx768m -Xss128k 

set NEW=-XX:NewSize=1024m -XX:MaxNewSize=1024m

Also look at:

17

How much memory have you allocated for the JVM? Somewhere aroung 512 MB?

The configuration is

java -Xms<initial heap size> -Xmx<maximum heap size>
2
  • That's right -> u'll need to check the heap size allocated to the program.
    – Pure.Krome
    Mar 26, 2010 at 2:52
  • What are these initial and maximum values?
    – Andrew
    Aug 2, 2019 at 19:56
14

To optimize OutOfMemoryError these steps should be followed:

  • Increase the Java Heap Size:

JMeter is a Java tool it runs with JVM. To obtain maximum capability, we need to provide maximum resources to JMeter during execution.First, we need to increase heap size (Inside JMeter bin directory, we get jmeter.bat/sh).

HEAP=-Xms512m –Xmx512m

It means default allocated heap size is minimum 512MB, maximum 512MB. Configure it as per you own machine configuration. It should also be kept in mind that OS also need some amount of memory, so all of the physical RAM shouldn't be allocated.

  • Run Tests in Non-GUI Mode:

JMeter is Java GUI application. It also has the non-GUI edition which is very resource intensive(CPU/RAM). If we run Jmeter in non-GUI mode , it will consume less resource and we can run more thread.

  • Disable ALL Listeners during the Test Run. They are only for debugging and use them to design the desired script.

Listeners should be disabled during load tests. Enabling them causes additional overheads, which consume valuable resources that are needed by more important elements of your test.

  • Use Up-to-Date Software:

Java and JMeter should be kept updated.

  • Decide Which Metrics You Need to Store:

When it comes to storing requests and response headers, assertion results and response data can consume a lot of memory! So it is wise try not to store these values on JMeter unless it’s absolutely necessary.

  • Tweak JVM:

The following JVM arguments in JMeter startup scripts can also be added or modified:

1. Add memory allocation rate:

NEW=-XX:NewSize=128m -XX:MaxNewSize=512m

This means memory will be increased at this rate.

2.-server - this switches JVM into “server” mode with runtime parameters optimization. In this mode, JMeter starts more slowly, but the overall throughput will be higher.

3. -d64 - While using a 64-bit OS, using this parameter can explicitly tell JVM to run in 64-bit mode.

4. -XX:+UseConcMarkSweepGC - this forces the usage of the CMS garbage collector. It will lower the overall throughput but leads to much shorter CPU intensive garbage collections.

5. -XX:+DisableExplicitGC - this prevents applications from forcing expensive garbage collections and helps avoid unexpected pauses.

For better and more elaborated understanding, this blog about 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure is helpful.

8

A lot of these answers are out-of-date. Currently using jmeter v5.1.1 r1855137:

# Set var to increase available memory
JVM_ARGS="-Xms2048m -Xmx4096m"
# Run jmeter via sh script, e.g.:
/jmeter/5.1.1/libexec/bin/jmeter.sh -n -t testfile.jmx -l results.jtl -j log.txt

You can verify that the increase in memory is available via the log.txt file, which will show the following using the values above:

INFO o.a.j.JMeter: Max memory     =3817865216
5

I also had this problem and it did not matter how much I adjusted the configuration java -Xms<initial heap size> -Xmx<maximum heap size>, as I always ran out of memory. In the end I found out that running JMeter in GUI mode (especially with listeners) causes a bottleneck. The best way to use JMeter, especially for extended testing or running multiple slave servers, is in non-GUI mode, which looks something like this:

jmeter -n -t testplan.jmx -r

Check out this link and read how to do remote testing the proper way: http://wiki.apache.org/jmeter/JMeterFAQ#How_to_do_remote_testing_the_.27proper_way.27.3F. Read the section on remote testing the 'proper way'.

Hope this helps.

4

You should check whether you're not using a tree result listener during your tests with many users.

Check jmeter best practices to avoid this kind of issues.

Regards

2

Though your server has 16 GB RAM, JMeter's default heap size 512 MB, Increase heap size by following below steps

1. Open jmeter file using vi editor /text editor
2. Search for "HEAP"
3. Change minimum (-Xms) and Maximum (-Xmx) heap values as you required
4. Save and quit (!wq enter)  
5. Start Jmeter by sh jmeter.sh or bash jmeter.bat or java -jar ApacheJMeter.jar
2

You have to change HEAP SIZE in jmeter.bat file. First you have to convert 2GB or 6GB (OR the size which you want to put) size into mb and then save it and relaunch .bat file.

Set value for "set HEAP=-Xms512m -Xmx512m"

2

In Jmeter version 3.x it is mentioned in $JMETER_HOME/bin/jemter.sh(jmeter.bat):

## Environment variables:
## JVM_ARGS - optional java args, e.g. -Dprop=val
## e.g.
## JVM_ARGS="-Xms512m -Xmx512m" jmeter.sh etc.

so in your case you can set it as much as sufficient to your needs for example:

JVM_ARGS="-Xms1024m -Xmx1024m"
2

Run Jmeter in non-GUI mode. Increase the heap size of the memory. Add very less/no listeners. For running Jmeter in non-GUI mode, go to bin directory and open command prompt in that window. use the following command "jmeter.bat -n -t Test.jmx -l Test.csv" here Test.jmx is the test file I need to open in non-GUI mode and Test.csv is the file in which I need my results stored. For increasing size of the memory use the command HEAP="-Xms512m -Xmx2048m" here 512 is the already allocated memory and 2048 is the memory I need to allot to Jmeter.

Hope this helps

0

Adjust the heap size as mentioned in the other answers and also take some best practices into account

  • When running a test (not when validating of course) use the non-gui mode
  • Disable any heavy listener such as View Result Tree but instead use a Simple Data Writer and analyze your data afterwards

These 2 items will already greatly increase your performance and heap size usage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.