Menu

Tuesday 28 May 2019

Types of GC , analyze GC logging and REDHAT JVM Tool.

1. Serial Garbage Collector.
2. Parallel Garbage Collector.
3. CMS Garbage Collector.
4. G1 Garbage Collector.





1. Serial Garbage Collector (-XX:+UseSerialGC):-

  • The serial GC works on a single thread to perform Garbage Collection. 
  • It is best for single core processor machine.
  • While performing GC, it's stop/freezes all the threads of application(Stop The World).
  • The (-XX:+UseSerialGC) argument have to be used on JVM configuration, to enable Serial Garbage Collector.


2. Parallel Garbage Collector (-XX:+UseParallelGC):-

  • The Parallel  GC works on multiple threads to perform Garbage Collection also known as the throughput collector.
  • Similar to serial, it also freezes all the threads of application(Stop The World).
  • The Parallel collector uses multiple CPU  to perform Garbage Collection.
  • This is default GC collector on most of JVM machines.
  • Parallel GC can be enabled using  (-XX:+UseParallelGC) argument on JVM.
  • Only minor collections are executed in parallel using (-XX:+UseParallelGC) argument.
  • For minor and major collections in parallel GC, we have to put (-XX:+UseParallelOldGC) argument on JVM.
  • The number of GC threads can be controlled with the command line option (-XX: ParallelGCThreads=<N>) argument on JVM.



3. CMS Garbage Collector (-XX:+UseConcMarkSweepGC):-

  • The CMS stands for Concurrent Mark Sweep (CMS) Garbage Collector. 
  • The CMS uses multiple threads to perform Garbage Collection.
  • Here the Garbage Collection is done concurrently with the application threads. hence it reduces the pause time.
  • This garbage collector is entered stop the world mode only in two cases,
  • 1. During marking the referenced objects in the old generation space.
  • 2. Any change in heap memory in parallel with doing the garbage collection.
  • So, (Stop The World) STW time of CMS garbage collector is very short.




4. G1 Garbage Collector (–XX:+UseG1GC):-

  • It is the new GC, experimental start on JDK 6update 14 then it is being introduced and supported in JDK 7 update 4.
  • The G1 uses multiple threads to scan the heap and divides it into the regions.
  • The heap is split into approximately 2000 regions.
  • The regions are spanning from minimum size 1MB to maximum size 32MB. (-XX:G1HeapRegionSize).
  • The G1 collector is a parallel, concurrent and compacting low-pause garbage collector.
  • To enable the G1 collector use (-XX:+UseG1GC) argument on JVM.

*****************************************************************************

Logging in Garbage Collection:

Below is the listed flags, which enable the logging.

  • -XX:+PrintGC (or the alias -verbose:gc) Enable the simple logging mode which prints the logs on every minor or major GC.
  • -XX:+PrintGCDateStamps would print the absolute timestamp in the log statement.
  • -XX:+PrintGCDetails property would print the details of how much memory is reclaimed in each generation.
  • -XX:+PrintGCTimeStamps would Print timestamps at garbage collection. 
  • -Xloggc:<filename> makes Log GC verbose output to the specified file.

Below is the snap how to analyze GC logs,



Link:


*****************************************************************************

IMP Suggestion: The REDHAT labs team provided a JVM Options Configuration Tool online, Where you can get the best JVM argument suggestion.

Link:







Reference links:


Thanks :-)



No comments:

Post a Comment