Lazy Events
Michael Bien
mbien42 at gmail.com
Mon Aug 24 06:15:47 UTC 2020
Hello,
I was wondering if it was ever considered to implement lazy evaluation
of event attributes?
commit() must happen close to the time the event happens since it stores
the time and thread id. Instead of storing all fields on commit using
the client Thread, JFR could potentially append additional fields by
calling event methods before its written to the repository on the JFR
Thread.
class LazyEvent extends Event {
@Label("Normal Field")
String msg1; // taken on commit()
@Lazy
@Label("Lazy Field")
String msg2() { return /** called by JFR thread before its written to repo **/; }
}
Another (simpler) way to allow the same functionality could be a
Event::writeHeader() which would only store eventThread +
startTime/duration values, while the actual Event::commit() would store
the fields without altering the exiting event "header" and could be
called from a different thread later.
I am mostly asking since I wrote a tiny library called JFRLog[1] which
lets you log directly to JFR records using normal logging APIs. While a
traditional logger impl can be usually configured to do potentially
expensive stuff like message formatting or calling toString() on objects
asynchronously (e.g the Thread which writes the message to a file could
do this), JFRLog has to do everything in the caller Thread before
event.commit(). If i would try to put that into its own thread, the
eventThread IDs and startTime would be all wrong.
its mostly just a thought i got while writing the lib - the performance
is sufficient for my needs, I avoid using complex log msgs anyway which
makes it just as fast as loggers which format in their own Threads. JFR
does all the heavy lifting anyway.
best regards,
michael
ps: thank you for the flush-interval flag :)
[1] https://mbien.dev/blog/entry/jfrlog-logging-directly-to-the
More information about the hotspot-jfr-dev
mailing list