Saturday, September 5, 2015

How to monitor java memory


Java memory management is very important as this will give the health of our application.

Basic options:
Heap: -Xms512m –Xmx512m
Permanent generation:-XX:PermSize=128m -XX:MaxPermSize=256m  
Heap free ratio:-XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=70  

Garbage collectiom
Young generation:
NewRatio:8  -XX:newRatio=8 
Survivor ratio:32   -XX:survivorRatio=32

Garbage collector type: 
G1 --> -XX:+UseG1GC  
ConcurrentMarkAndSweep(old) -> -XX:+UseConcMarkSweepGC 
Garbage collector:-XX:+UseG1GC  

Visual tool : jvisualvm
The below command gives the memory allocation
 jstat -gc <process_id> <time_interval>
 jstat -gc 6781 30000

 S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT   
264192.0 278016.0 180332.1  0.0   842240.0 578974.5  292864.0   214754.4  38400.0 36880.1     18    2.663   1      0.423    3.087
264192.0 278016.0 180332.1  0.0   842240.0 813343.0  292864.0   214754.4  38400.0 36884.6     18    2.663   1      0.423    3.087
where columns are
S0C and S1C:  Current size of the Survivor0 and Survivor1 areas in KB.

S0U and S1U: Current usage of the Survivor0 and Survivor1 areas in KB. One of the survivor areas are empty all the time.

EC and EU:  Current size and usage of Eden space in KB. EU size will keep increasing and as soon as it crosses the EC, Minor GC is called and EU size is decreased.

OC and OU: Current size and current usage of Old generation in KB.

PC and PU: Current size and current usage of Perm Gen in KB.

YGC and YGCT: YGC tells the number of GC event occurred in young generation. YGCT gives the accumulated time for GC operations for Young generation. Both YGC and YGCT will increase in the same row where EU value is dropped because of minor GC.

FGC and FGCT: FGC column is the number of Full GC event occurred. FGCT column gives accumulated time for Full GC operations.Full GC time will be too high when compared to young generation GC timings.

GCT: The total accumulated time for GC operations. Notice that it’s sum of YGCT and FGCT column values.


 If lot of Full GC operations, > increase Old generation memory space
java.lang.OutOfMemoryError: PermGen space errors ==> increase the Perm Gen memory space using -XX:PermGen and -XX:MaxPermGen JVM options More:http://jvmmemory.com/

No comments:

Post a Comment