JEP 349: JFR Event Streaming

OwnerErik Gahlin
TypeFeature
ScopeJDK
StatusCandidate
Componenthotspot / jfr
Discussionhotspot dash jfr dash dev at openjdk dot java dot net
EffortM
DurationS
Reviewed byKaren Kinnear, Mikael Vidstedt
Endorsed byMikael Vidstedt
Created2017/07/11 19:20
Updated2019/08/15 13:59
Issue8184193

Summary

Expose JDK Flight Recorder data for continuous monitoring.

Goals

Non-Goals

Motivation

The HotSpot VM emits more than 500 data points using JFR, most of them not available through other means besides parsing log files.

To consume the data today, a user must start a recording, stop it, dump the contents to disk and then parse the recording file. This works well for application profiling, where typically at least a minute of data is being recorded at a time, but not for monitoring purposes. An example of monitoring usage is a dashboard which displays dynamic updates to the data.

There is overhead associated with creating a recording, such as:

If there were a way to read data being recorded from the disk repository without creating a new recording file, much of this overhead could be avoided.

Description

Define an API by which users can subscribe to events asynchronously.

The following code illustrates how the API can be used. It shows how to print all classes on which threads have blocked for more than 10 ms. If a consumer is not able to keep up, events will be dropped after 600 seconds.

try (RecordingStream rs = new RecordingStream()) {
    rs.enable("jdk.MonitorEnter").withThreshold(Duration.ofMillis(10));
    rs.setMaxAge(Duration.ofSeconds(600));
    rs.onEvent(e -> System.out.println(e.getClass("monitorClass")));
    rs.start();
}

This creates a recording and at a given interval, perhaps once every two seconds, flushes events stored in memory and thread-local buffers to the disk repository. A separate thread parses the most recent file, up to the point in which data has been written, and pushes the events to the consumers.

Alternatives

JMX notifications provide a means for the JDK and third-party applications to expose information for continuous monitoring. There are, however, drawbacks that make JMX unsuited for the purpose of this JEP.

Testing

Risks and Assumptions