-
Notifications
You must be signed in to change notification settings - Fork 3.5k
metric: improve accuracy of timer metric under contention #18219
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
metric: improve accuracy of timer metric under contention #18219
Conversation
excludes contention for recording timing from the timing by locking in the completion time before attempting to record it
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
|
This pull request does not have a backport label. Could you fix it @yaauie? 🙏
|
| public <T, E extends Throwable> T time(ExceptionalSupplier<T, E> exceptionalSupplier) throws E { | ||
| try { | ||
| trackedMillisState.getAndUpdate(TrackedMillisState::withIncrementedConcurrency); | ||
| trackedMillisState.getAndUpdate(existing -> existing.withIncrementedConcurrency(nanoTimeSupplier.getAsLong())); |
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.
Note: the nanoTimeSupplier.getAsLong() for recording the start time still occurs inside the UnaryConsumer because if this thread loses and is retried, we don't want to record an old start time.
robbavey
left a comment
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.
Other than the unused imports, LGTM
...tash-core/src/main/java/org/logstash/instrument/metrics/timer/ConcurrentLiveTimerMetric.java
Outdated
Show resolved
Hide resolved
...tash-core/src/main/java/org/logstash/instrument/metrics/timer/ConcurrentLiveTimerMetric.java
Outdated
Show resolved
Hide resolved
...tash-core/src/main/java/org/logstash/instrument/metrics/timer/ConcurrentLiveTimerMetric.java
Outdated
Show resolved
Hide resolved
...tash-core/src/main/java/org/logstash/instrument/metrics/timer/ConcurrentLiveTimerMetric.java
Outdated
Show resolved
Hide resolved
|
💛 Build succeeded, but was flaky
Failed CI Steps
History
|
* metric: improve accuracy of timer metric excludes contention for recording timing from the timing by locking in the completion time before attempting to record it * remove unused imports





Release notes
[rn: skip]
What does this PR do?
Improves the accuracy of
ConcurrentLiveTimerMetricin cases where many threads are contending to record their timings.When using
AtomicReference#getAndUpdate(UnaryOperator), the provided operator may be run multiple times in cases where another thread has "won" the update. By moving the capture of the timestamp out of this block, we ensure an accurate recording for the completion time of the measurement and prevent it from including the time contending to write the measurement.Why is it important/What is the impact to the user?
No major user impact, but slightly improves the accuracy of timer-type metrics.
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files (and/or docker env variables)[ ] I have added tests that prove my fix is effective or that my feature worksAuthor's Checklist
How to test this PR locally
Verification relies on the existing test coverage for
ConcurrentLiveTimerMetric, along with an understanding of what bringing the call toLongSupplier#getAsLongout of block means when the block needs to be re-run.