Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PS Old Gen memory in Heap Memory Usage: GC settings for Java Out Of Memory Exception

enter image description here

Below are my JVM settings:

 JAVA_OPTS=-server -Xms2G -Xmx2G -XX:MaxPermSize=512M -Dsun.rmi.dgc.client.gcInterval=1200000 -Dsun.rmi.dgc.server.gcInterval=1200000 -XX:+UseParallelOldGC -XX:ParallelGCThreads=2 -XX:+UseCompressedOops  -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jbos88,server=y,suspend=n

Problem: Total Heap Memory: 2GB Old Gen: 1.4GB (2/3 of Heap) New Gen: 600MB(1/3 of Heap)

The Old Gen grows in memory beyond 70% 0f its allocated size and never is subjected to GC even at 100% i.e 1.4GB. One can see the graph below it peaks and never is GC, the drop in memory is when it was forced to GC from the JConsole. This problem is eventually bringing the web server down.

Anything that i am missing or wrongly setting the JVM?

Thanks for the help in advance.

Updating my Question:

After heap analysis it appears like Stateful session bean is the prime suspect: enter image description here We have stateful session beans that hold the persistence logic assisted by Hibernate.

like image 777
amitsalyan Avatar asked Sep 12 '14 23:09

amitsalyan


People also ask

How do I fix out of memory heap space in Java?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

What is PS old Gen memory?

PS Old Gen: The amount of memory (in Megabytes) used in the "Old Generation" memory.

Which exception is throw when Java is out of memory?

One common indication of a memory leak is the java. lang. OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap.


2 Answers

The GC will be called eventually, the old gen is almost never called (because it is extremely slow). The GC does run but it will only run on the new gen and survivor gen at first, it has a completely different algorithm for cleaning the old gen which is slower then new/survivor gens.

Those numbers are really high, the oldgen should never reach sum a high number compared to the newgen. My guess is that you have a memory leak.

I can only guess your program is dealing with big files, you are probably saving references to them for too long.

like image 192
David Limkys Avatar answered Oct 24 '22 00:10

David Limkys


Even still having the main problem (memory leak) resolved, if you still want the old gen to be cleared in frequent small sized pauses, you may try setting

-XX:MaxGCPauseMillis=(time in millis)

and this is only applicable with Parallel Collector and when Adaptive Sizing Policy is on. By default Adaptive Sizing Policy is on, but, if you want to explicitly mention this you can use.

-XX:+UseAdaptiveSizePolicy

Or else you can switch to CMS collector where you can use

-XX:CMSInitiatingOccupancyFraction=(% value) 
-XX:+UseCMSInitiatingOccupancyOnly

Which is a more reliable way of collecting the old gen when it has reached a certain fraction of the the old gen.

like image 37
Tharanga Hewavithana Avatar answered Oct 23 '22 23:10

Tharanga Hewavithana