-
Notifications
You must be signed in to change notification settings - Fork 994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virtual threads metrics #5067
Virtual threads metrics #5067
Conversation
This looks generally good. Have you tried this out in an application yet? What is remaining for this to be ready to merge, you think? I couldn't see what the build failure was perhaps because it is too old at this point. Could you rebase on the latest It'd be good to have a test for this also. You can make the test disabled on Java versions before 21. Copying from the issue to keep the discussion here where changes would be made:
Is there any API used that isn't available in Java 8? If it is only a runtime issue of the specific JFR events won't be available except on Java 21 and later, I don't think we need to do anything special with the source or making a separate module. It will be up to users to not bind the MeterBinder if they are not on Java 21 or later.
Agreed. I think we can ignore those because users can instrument run time of virtual threads via instrumenting the executor as you said or they can instrument the execution of a single virtual thread created ad hoc.
Logging a stack trace can be enabled with the system property As for tagging the method signature where the pinning happened, I'm not sure. I think I would err on the side of not including it initially. The cardinality of it is hard to know and application-specific. Without that tag, users will know how much pinning is happening and for how long, at least. Maybe that provides enough value. We can consider adding it after getting some feedback on the metrics without it. Thoughts? |
Hi @shakuzen , I've been using this meter binder for a couple of months already. I think the JFR streaming API is available only from JDK 14; that's why I've asked about a separate module for jdk21. Additionally, covering it with unit tests is easier on jdk21 since we have access to virtual threads builders. I agree that neither logging pinned stack trace nor tagging with class caused pinning is incorrect for meter binder implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some review on the implementation. I'll discuss with @jonatan-ivanov about making a new java 21+ module for this and get back to you.
this.recordingStream = new RecordingStream(); | ||
|
||
recordingStream.enable("jdk.VirtualThreadPinnedEvent"); | ||
recordingStream.enable("jdk.VirtualThreadSubmitFailedEvent"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the right RecordingStream
usage, but I was looking at this blog, and it made me wonder: do we not need to start the stream? And should we not set a max age so we don't accumulate events indefinitely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @shakuzen,
Do you think we need to expose maxAge duration as a constructor parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I had the same thought, but I'm not sure due to my lack of familiarity with JFR and in particular RecordingStream
. I don't understand what this max age means in terms of the event listeners we register. I assume the event listeners are run nearly instantly after an event is recorded. So I'm not sure the max age could affect them. Or will max age effectively filter out events with a duration longer than the max age duration?
...ore/src/main/java/io/micrometer/core/instrument/binder/jvm/JvmVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
I talked to @jonatan-ivanov about where to put this code. I think a new micrometer-java21 module is probably the least bad solution unless someone has other suggestions. @ArtyomGabeev would you update the PR to move this to such a module? You can see the micrometer-java11 module for something similar that already exists. |
I've extracted micrometer-java21 module and have a couple of questions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than remove any CI executors, see what is done in the micrometer-jetty12
module:
micrometer/micrometer-jetty12/build.gradle
Lines 3 to 6 in 9917c67
// skip this module when building with jdk <17 | |
if (!javaLanguageVersion.canCompileOrRun(17)) { | |
project.tasks.configureEach { task -> task.enabled = false } | |
} |
- What is the minimum supported java version? If it is 8, we are not running any builds right now on jdk8.
It is 8. It would be nice if we still have a JDK 8 build but it became a pain to maintain that due to test dependencies. The intention is that using the -release
option set to 8 should catch compatibility issues.
Done. |
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think overall this looks good. I'll try to take a look at some prior art on instrumenting metrics with JFR to make sure we aren't missing any best practices. I left a review comment more for the maintainers to consider.
@jonatan-ivanov any concerns with this PR?
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
.../test/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetricsTests.java
Outdated
Show resolved
Hide resolved
.../test/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetricsTests.java
Outdated
Show resolved
Hide resolved
.../test/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetricsTests.java
Outdated
Show resolved
Hide resolved
...1/src/main/java/io/micrometer/java21/instrument/binder/jfr/JfrVirtualThreadEventMetrics.java
Outdated
Show resolved
Hide resolved
@ArtyomGabeev @shakuzen I fixed the comments I made on a branch except the package and class rename, see first commit here: ArtyomGabeev/micrometer@virtual-threads-metrics...jonatan-ivanov:micrometer:virtual-threads-metrics I also found a way to test starting and unparking failures and receive JFR events for them. Unfortunately this is a hack with reflection. Even more unfortunate that the JDK tests are doing the same, see the comments of the test. |
Hi, @jonatan-ivanov |
Thank you! |
...er-java21/src/main/java/io/micrometer/java21/instrument/binder/jdk/VirtualThreadMetrics.java
Show resolved
Hide resolved
@ArtyomGabeev @shakuzen I separated the reflective tests, see the last commit and let me know what you think: 11f1016 |
Fixes #3956