-
Notifications
You must be signed in to change notification settings - Fork 1k
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 thread metrics #3956
Comments
Any developments here? |
Not much I guess. Since this is not available through JMX (like metrics for platform threads are), we need to utilize JFR and |
I am not very familiar with JFR but, in order to retrieve the events count, shouldn't we start and stop a JFR recording? Or even keeping an active recording for the whole life of the JVM? My knowledge about JFR is not enough to contribute this PR. Anyway I will try to find if in Java 22 or beyond there is any plan or JEP to enhance |
I need to look into this but not necessarily in the classic sense where JFR is writing the data into a file. What we need is receiving the JFR events, we need to investigate how to do it so that it does not disturb the app.
Having this info coming from |
Hello here, Let me know if you want me try and contribute support of VT metrics based on JFR continuous event listener. Or are we waiting this data to be exposed via jmx? |
We would consider an implementation based on the JFR events. I am not aware of any plans for anything to be added to JMX, so I don't think just waiting is necessarily likely to yield results. We could ask on the corresponding JDK mailing list about adding support for virtual thread metrics to JMX if there's a reason that's better over the JFR event route. It would also be good for users to share what virtual thread metrics in particular they are interested in and why so we can understand what will be most helpful and why. |
I think we may be interested in two JFR events:
For the first one, things to consider:
Here is an example of VirtualThreadPinnedEvent:
|
I've opened draft PR to demonstrate intentions and come up with the question: I think this instrumentation should be specific to java-21. Should I go and create a java-21 source set or separate gradle module? |
I'm not sure we need to process jdk.VirtualThreadStart and jdk.VirtualThreadEnd events. |
In a recent investigation I used this hacky approach: final Class<?> virtualThreadClass = Class.forName("java.lang.VirtualThread");
final Field defaultSchedulerField = virtualThreadClass.getDeclaredField("DEFAULT_SCHEDULER");
defaultSchedulerField.setAccessible(true);
final ExecutorService defaultScheduler = (ExecutorService) defaultSchedulerField.get(null);
new ExecutorServiceMetrics(defaultScheduler, "virtualThreads").bindTo(metricsRegistry); It did help me observed thread pinning build-up, and as such I'm debating whether to keep it or not even though it's "illegal", but I understand that there's still no official support for virtual thread metrics. |
@celtric Thanks for sharing. I guess you only need to do that because virtual threads are not being created from an executor you can configure in your application. Does that mean virtual threads are only being created like |
Actually I'm creating the executor myself with |
@shakuzen maybe here is a misunderstanding, what @celtric is getting via reflection and instrumenting is the underlying |
As a note, if I try to register
As @juliojgd mentions, I'm registering the |
Thank you all for the additional details. It seems we can't rely on wrapping the
In case you aren't aware, we have |
Follow-up from #3650. See https://openjdk.org/jeps/444#JDK-Flight-Recorder-JFR
Existing thread metrics do not cover virtual threads -
ThreadMXBean
only provides statistics on platform threads.New potential instrumentation of virtual threads is only available via JFR. We can count started/finished virtual threads. The other events available are:
The text was updated successfully, but these errors were encountered: