Skip to content
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

Add metrics related to virtual threads #9619

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

tjquinno
Copy link
Member

@tjquinno tjquinno commented Dec 23, 2024

Description

Resolves #9533

New meters related to virtual thread usage

  • current number of active virtual threads (disabled by default)
  • total number of virtual thread starts (disabled by default)
  • total number of pinned threads
  • timer (with histogram) of pinned threads' durations
  • number of failed attempts to submit virtual threads to platform threads

The virtual thread count meters are disabled by default for performance reasons. Enable them by setting metrics.virtual-threads.count.enabled=true in configuration, but be aware doing so can degrade the server's performance.

New meter related to platform threads

Helidon also now exposes the new system meter thread.starts which displays the total number of platform thread starts performed in the JVM since server start-up.


The PR adds a new MetersProvider implementation to the helidon-metrics-system-meters component. The new implementation registers for selected Java Flight Recorder events to track data related to virtual threads.

The three virtual thread meters that are enabled by default should be rare so monitoring the JFR events for them adds very little overhead. In contrast, to maintain the current number of active virtual threads and the total number of virtual thread starts the added code must register for and respond to virtual thread start and end events which can be costly. That's why those two meters--and the registration of listeners for those events from JFR--are disabled by default.

Documentation

Small additions to the SE and MP metrics guide and doc pages.

@tjquinno tjquinno self-assigned this Dec 23, 2024
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Dec 23, 2024
@spericas
Copy link
Member

spericas commented Jan 2, 2025

Some general questions @tjquinno ...

  • current number of active virtual threads (disabled by default)
  • total number of virtual thread starts (disabled by default)
  • total number of pinned threads

Is there also a counter for platform threads?

  • distribution summary (history) of pinned threads
  • number of failed attempts to submit virtual threads to platform threads

Under what conditions would this counter be incremented?

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a copyright update?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a remnant from an earlier iteration of the change I was contemplating. Not needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. File no longer in the changed list.

@tjquinno
Copy link
Member Author

tjquinno commented Jan 2, 2025

Some general questions @tjquinno ...

  • current number of active virtual threads (disabled by default)
  • total number of virtual thread starts (disabled by default)
  • total number of pinned threads

Is there also a counter for platform threads?

The existing Helidon built-in meters created in `SystemMetersProvider.java include some platform-thread related ones:

  • thread count
  • daemon thread count
  • maximum thread count

This JMX MBean makes a number of other thread-related values available:
https://docs.oracle.com/en/java/javase/21/docs/api/java.management/java/lang/management/ThreadMXBean.html

Probably the most useful value that's available we don't currently expose is the total started thread count. We could add that.

  • distribution summary (history) of pinned threads
    (I edited the description to change "history" to "histogram" which I originally intended!)

Do you have an example?

I don't have an interesting example of the value.

Here is an example of the output, taken from the updated doc that's part of this PR (obviously with no interesting output):

  "vthreads.recentPinned": {
      "count": 0,
      "max": 0.0,
      "mean": 0.0,
      "total": 0.0,
      "p0.5": 0.0,
      "p0.75": 0.0,
      "p0.95": 0.0,
      "p0.98": 0.0,
      "p0.99": 0.0,
      "p0.999": 0.0
    },
  • number of failed attempts to submit virtual threads to platform threads

Under what conditions would this counter be incremented?

Here's what the Java Flight Recorded doc says about the value it reports about pinned virtual threads.

  • distribution summary (history) of pinned threads
  • number of failed attempts to submit virtual threads to platform threads

Under what conditions would this counter be incremented?

See the previous link.

@tjquinno tjquinno force-pushed the 4.x-jfr-vthread-metrics branch from 67800cc to 8040b24 Compare January 2, 2025 22:06
@tjquinno
Copy link
Member Author

tjquinno commented Jan 2, 2025

The latest push accomplished:

  • Removed an unchanged file (except for copyright date) from the changed file list.
  • Added the new non-virtual thread system meter thread.starts to the built-in system meters
  • Changed the meter type for vthreads.recentPinned from distribution summary to timer (the two are basically equivalent except that the timer type displays an elapsed time instead of the more general data value).

…ecause the virtual threads recentPinned meter is now a timer
@tjquinno tjquinno requested a review from spericas January 2, 2025 23:11
@tjquinno tjquinno merged commit 01145f1 into helidon-io:main Jan 3, 2025
55 checks passed
@tjquinno tjquinno deleted the 4.x-jfr-vthread-metrics branch January 3, 2025 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Evaluate adding metrics for virtual threads
2 participants