-
Notifications
You must be signed in to change notification settings - Fork 990
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 JvmThreadDeadlockMetrics #5222
Conversation
@rkurniawati Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@rkurniawati Thank you for signing the Contributor License Agreement! |
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.
Thank you for the pull request. Those sound like interesting additions. I am concerned though that the JavaDoc for both have the following warning (emphasis is mine):
This method is designed for troubleshooting use, but not for synchronization control. It might be an expensive operation.
Due to that it might make more sense to put these in a separate class so users can more easily separately choose to enable these potentially expensive metrics. What do you think? Do you have any practical experience using these in production that you can share in terms of the expense of regularly calling these methods?
Thank you for your feedback, @shakuzen! I agree it's a good idea to let the users enable these metrics when they need them. The APIs used by the deadlock metrics have some overhead in the JVM implementation that I use, calling the When you suggest putting these in a separate class, do you mean put them in a separate metric binder? It would be great if you have an example of a metric that's disabled by default. Thanks, |
Yes. By doing that, users can bind |
6d01826
to
cab21ef
Compare
Thanks! I refactored the code and put the new metrics in a class called Let me know if there's anything else that I could do to improve this PR 😃 |
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.
Thank you for the changes. I left some review comments.
...er-core/src/main/java/io/micrometer/core/instrument/binder/jvm/JvmThreadDeadlockMetrics.java
Outdated
Show resolved
Hide resolved
...er-core/src/main/java/io/micrometer/core/instrument/binder/jvm/JvmThreadDeadlockMetrics.java
Outdated
Show resolved
Hide resolved
...er-core/src/main/java/io/micrometer/core/instrument/binder/jvm/JvmThreadDeadlockMetrics.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
private void createTemporarilyDeadlockedThread() { | ||
// create two threads that are deadlocked for about 5 seconds |
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.
Could we control this with something like CountDownLatch so we can have the same effect without the test always taking multiple seconds?
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 changed the test to use CountDownLatch
. Unfortunately I have to use ReentrantLock
instead of the monitor lock, so the the jvm.threads.deadlocked
is non-zero but jvm.threads.deadlocked.monitor
is zero
05173e1
to
41b28f2
Compare
It looks like the CI job failed due to a flaky test (##5296). I'm going to try to rebase so that it will trigger CI (and hopefully pass the test next time) |
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.
Thank you for the quick updates. One more thing and then this is ready to go I think.
...er-core/src/main/java/io/micrometer/core/instrument/binder/jvm/JvmThreadDeadlockMetrics.java
Outdated
Show resolved
Hide resolved
2c05bcd
to
6f473c3
Compare
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.
Thank you for the pull request and the patience on review.
public void bindTo(MeterRegistry registry) { | ||
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); | ||
|
||
if (threadBean.isObjectMonitorUsageSupported()) { |
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.
This should be isSynchronizerUsageSupported
. I'll fix it in a polish commit.
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.
Oops! Thanks for taking care of it!
Hello,
I was wondering if you would consider accepting the changes in this PR so that we will have these two deadlock-related metrics in a future version of Micrometer?
This PR adds the following JVM thread deadlock-related metrics:
jvm.threads.deadlocked
: The current number of threads that are deadlockedjvm.threads.deadlocked.monitor
: The current number of threads that are deadlocked on object monitorsThanks,
Ruth
Ruth Kurniawati