Young G1 GC Notification
Rabi
hotspot-gc at kavoori.io
Tue Aug 24 21:51:59 UTC 2021
Hello,
I am new to this mailing list and I am reaching out here as it seemed like
a good place to ask this question. If this is the wrong place for this
question, I apologize.
I would like to get a notification for G1 Young GC pause events and report
the time to an external monitoring service. (See the code below where I
attempted to listen on a notification)
However, what I have noticed is that I never get a 'Notification' even
though I am seeing GC logs report the G1 Young GC pauses. Also, I can see
the same information in the JFR recording.
My application rarely does a full GC, so I am mostly interested in Young G1
GC events and I would like to overlay this information on top of other
application metrics.
Here is what I have attempted :
public class GCEventMonitor implements NotificationListener {
public GCEventMonitor(MetricsRecorder metricsRecorder) {
this.metricsRecorder = metricsRecorder; //external Service, where I
can send information
registerGCBeans();
}
private void registerGCBeans() {
for (GarbageCollectorMXBean gcbean :
ManagementFactory.getGarbageCollectorMXBeans()) { // I have noticed two
beans get registered here G1 Young and G1 Old through a debugger
if (gcbean instanceof NotificationEmitter) {
NotificationEmitter emitter = (NotificationEmitter) gcbean;
emitter.addNotificationListener(this, null, null);
}
}
}
@Override
public void handleNotification(Notification notification, Object
handback) { *//never gets called*
if
(notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION))
{
CompositeData cd = (CompositeData)
notification.getUserData();
GarbageCollectionNotificationInfo info =
GarbageCollectionNotificationInfo.from(cd);
processGCEvent(info, handback); // Extract info.getGcInfo()
here and send gcInfo.getDuration() to external service
}
}
}
I have set a debug point on handleNotification method, but this method
never gets called, even while I can actively see gc logs print the
following information. Why am I not getting a notification? Is my
configuration/registration/setup incorrect?
There is a comment on this stackoverflow question/answer that the VM does
not notify when Young GC happens. Is that true? If so, how does JFR record
that information?
Thanks for your help in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/hotspot-gc-use/attachments/20210824/a2320ba4/attachment.htm>
More information about the hotspot-gc-use
mailing list