JMeter out of memory: java.lang.OutOfMemoryError: Java heap space solutions

First, the cause of the problem

When the pressure test with JMeter, sometimes when simulate large concurrent requests or script to run for a long time, JMeter will stop, report OOM (out of memory) error.

The reason is that JMeter is a pure Java development tools, memory management by the java virtual machine JVM, when the memory is not timely recovery, lack of heap memory, the memory overflow error will be reported.

Concept of complementarity:

Memory leaks: the application is not released in time after the use of resources, resulting in the application memory holds unnecessary resources.

Out of memory: application memory can not meet the normal use, the stack has reached the maximum set by the system, leading to a crash.

Usually due to a memory leak caused a stack memory is increasing, causing memory overflow.

The same is true for JMeter tips, JMeter test process, if memory overflow, it usually appears in the figure above: java.lang.OutOfMemoryError: the Java heap Space : means that the heap overflow, not enough

Second, the solution

We know the cause of the error appears due to insufficient memory heap size caused naturally think of memory overflow solution: adjust the heap memory size.

Step (for example in a Windows system, Linux system similar):

1, open jmeter.bat file, keyword "HEAP" search by the original configuration to read as follows:

before fixing:

if not defined HEAP (
    rem See the unix startup file for the rationale of the following parameters,
    rem including some tuning recommendations
    set HEAP=-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m
)

Modified:

if not defined HEAP (
    rem See the unix startup file for the rationale of the following parameters,
    rem including some tuning recommendations
    set HEAP=-Xms512m -Xmx4000m
    set NEW=-XX:NewSize=256m -XX:MaxNewSize=512m
)
set HEAP = -Xms512m -Xmx4000m: adjusting the size of the heap memory 
set NEW = -XX: NewSize = 256m
-XX: MaxNewSize = 512m: adjusting the heap size with newborn

note:

This value is not bigger is better, should be based on measured using a machine press, in general, do not exceed the maximum heap memory of half the physical memory, otherwise easily lead to jmeter run slower,

Caton even memory overflow (because java garbage collection mechanism itself is dynamically allocated memory, adjust itself when it will take up a lot of memory), NEW allocated memory, should not be too large.

2. After editing save, restart the JMeter, to take effect.

III Summary

1, this modified method is applicable only heap size portion of the case, is not a panacea, when the need to simulate a large number of threads, depending on the circumstances require the use of distributed pressure measured in the way.

2, when the command line to run JMeter, be sure to disable the "View Results Tree", "Aggregate Report" and other listeners, because it is really really really consume memory.

 

Guess you like

Origin www.cnblogs.com/ailiailan/p/11562367.html