Young G1 GC Notification

Ron Reynolds tequilaron at gmail.com
Tue Aug 24 22:28:35 UTC 2021


i use this exact mechanism and it works well.  the only difference between
my code and yours (that i can see, for the most part) is the call to
emitter.addNotificationListener(receiver, filter, bean);

in my case filter is also null but the hand-back is the bean itself (so it
could be written as emitter.addNotificationListener(receiver, filter,
emitter);)

and thus my handler is written:
    private static void onGcEvent(Notification ignore, NotificationEmitter
bean) {
        final GarbageCollectorMXBean gcBean = (GarbageCollectorMXBean) bean;
        final String beanName = gcBean.getName().replaceAll(" ", "_");
        final GcInfo lastGcInfo = gcBean.getLastGcInfo();
...
note, technically i use lambdas and there's other framework code but this
should be the important parts.

On Tue, Aug 24, 2021 at 2:52 PM Rabi <hotspot-gc at kavoori.io> wrote:

> 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!
> _______________________________________________
> hotspot-gc-use mailing list
> hotspot-gc-use at openjdk.java.net
> https://mail.openjdk.java.net/mailman/listinfo/hotspot-gc-use
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/hotspot-gc-use/attachments/20210824/d30bf03b/attachment.htm>


More information about the hotspot-gc-use mailing list