Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When exactly is the JVM throwing an OutOfMemoryError

We are running a Java application that sometimes "freezes" because some thread is using almost all the heap. Despite the JVM doing Full GC that last more than 60 seconds the application never dies with OutOfMemoryError.

I read from Java documentation that :

The throughput collector will throw an out-of-memory exception if too much time is being spent doing garbage collection. For example, if the JVM is spending more than 98% of the total time doing garbage collection and is recovering less than 2% of the heap, it will throw an out-of-memory expection.

I would like more information about what this 98% of time means (what is the time frame ?), and if it is possible to lower this value, i.e. throw an OOME if the application is spending 90% of time in GC and cannot free more than 10% of the heap.

The goal is to make sure the application will die (instead of running doing only GC) with OOME so we can generate a dump on OOME.

Here are the memory and GC settings we use (OS is Solaris):

-Xms2048m -Xmx2048m \
-Xmn512m \
-XX:PermSize=256m 
-XX:MaxPermSize=256m \
-XX:+UseParNewGC 
-XX:ParallelGCThreads=16 \
-XX:+UseConcMarkSweepGC 
-XX:+CMSParallelRemarkEnabled \
-XX:+DisableExplicitGC \
-XX:+PrintGC 
-XX:+PrintGCDetails 
-XX:+PrintGCTimeStamps \
-XX:+PrintClassHistogram \
-Xloggc:/gcmonitor.log \
-XX:+HandlePromotionFailure \
-XX:SurvivorRatio=4 
-XX:TargetSurvivorRatio=90 
-XX:MaxTenuringThreshold=10 \
-XX:+UseTLAB 
-XX:TLABSize=32k 
-XX:+ResizeTLAB \
-XX:+UseMPSS \
like image 517
neirda Avatar asked Jan 18 '12 16:01

neirda


2 Answers

I would like more information about what this 98% of time means (what is the time frame ?)

Answer to this question: GC overhead limit exceeded suggests it is 1 minute.

is possible to lower this value

Once again looking into the question mentioned above, looks like you can use GCTimeLimit and GCHeapFreeLimit parameters.

like image 194
Tomasz Nurkiewicz Avatar answered Oct 17 '22 08:10

Tomasz Nurkiewicz


If you are only looking to force an OOM to get the side benefit of the heap dump, you can now do this on a running java process at any time:

Find the process:

jps -v

Force a dump

jmap -dump:file=heap.bin

Then analyze heap.bin in your tool of choice.

like image 25
ramanman Avatar answered Oct 17 '22 08:10

ramanman