Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to monitor "Full GC" frequency in JMX (on HotSpot)?

I want to monitor Full GC frequency in JMX. A MBean exposes GC count. (cf. http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/GarbageCollectorMXBean.html - java.lang:type=GarbageCollector,name=).

The problem is that MBean does not distinguish between minor and full gc.

Does someone have an idea ?

Thanks.

Arnault

like image 618
ajeanson Avatar asked Jan 08 '11 11:01

ajeanson


1 Answers

I'm not completely sure about this but I assume that the garbage collector that controls all the memory pools (at least the one for Old Gen) is the one used for major gc. e.g.: I have a JVM running with these 2 collectors:

  • PS MarkSweep
    • MemoryPoolNames: PS Eden Space, PS Survivor Space, PS Old Gen, PS Perm Gen
    • CollectionCount: 68
  • PS Scavenge
    • MemoryPoolNames: PS Eden Space, PS Survivor Space
    • CollectionCount: 2690

Taking this into account I would say, PS Scavenge is used for minor gc and PS MarkSweep for major gc.

UPDATE (based on @ajeanson comment, thanks for your feedback btw):

Effectively, the example I put in there was taken from the information exposed in the MXBeans of the JVM I was using. As you mentioned, these are GC algorithms, and the name the MXBean for the GC is using is based on the algorithm the GC is using. I've been looking for some more information about this; in this article http://download.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html, reads the following:

The Java HotSpot VM defines two generations: the young generation (sometimes called the "nursery") and the old generation. The young generation consists of an "Eden space" and two "survivor spaces." The VM initially assigns all objects to the Eden space, and most objects die there. When it performs a minor GC, the VM moves any remaining objects from the Eden space to one of the survivor spaces. The VM moves objects that live long enough in the survivor spaces to the "tenured" space in the old generation. When the tenured generation fills up, there is a full GC that is often much slower because it involves all live objects. The permanent generation holds all the reflective data of the virtual machine itself, such as class and method objects.

Taking a look at the collectionCount property on the MXBeans, in the case of my "PS MarkSweep" collector (the one managing the Old Generation pool), the collection count seems to increase only when I get a full GC in the verbose output. I might be wrong and maybe in some cases this Collector performs also minor GC, but I would need to run more tests to be totally sure about this. Please, let me know if someone finds out something else or you have some more specific information about this issue as I'm quite interested in it.

like image 165
Gotxi Avatar answered Oct 14 '22 11:10

Gotxi