Rescale threshold calculation#5169
Open
nickbar01234 wants to merge 1 commit into
Open
Conversation
d620bd2 to
57497d8
Compare
There was a problem hiding this comment.
Pull request overview
This PR adjusts ExponentiallyDecayingReservoir’s rescaling interval to account for custom alpha values, aiming to prevent weight/priority overflow (leading to Double.Infinity priorities and skipped updates) after long runtimes. It also adds a regression test that reproduces the overflow scenario for high alpha.
Changes:
- Compute a per-instance
rescaleThresholdbased onalpha(falling back to the previous default threshold for typicalalphavalues). - Update rescale triggering to use the computed threshold.
- Add a test verifying updates still register after enough time has passed to otherwise overflow at higher
alpha.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| metrics-core/src/main/java/com/codahale/metrics/ExponentiallyDecayingReservoir.java | Introduces an alpha-aware rescale threshold to avoid overflow/infinite priorities. |
| metrics-core/src/test/java/com/codahale/metrics/ExponentiallyDecayingReservoirTest.java | Adds a regression test for the overflow scenario and adjusts an existing timing assertion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+210
to
+216
| private long calculateRescaleThreshold(double alpha) { | ||
| long upperbound = (long) Math.floor(Math.log(Double.MAX_VALUE) / alpha); | ||
| if (upperbound == 0) { | ||
| throw new IllegalStateException("Alpha value resulted in a rescale threshold of 0 seconds"); | ||
| } | ||
| return upperbound >= DEFAULT_RESCALE_THRESHOLD ? DEFAULT_RESCALE_THRESHOLD : TimeUnit.SECONDS.toNanos(upperbound / 2); | ||
| } |
Comment on lines
+210
to
+216
| private long calculateRescaleThreshold(double alpha) { | ||
| long upperbound = (long) Math.floor(Math.log(Double.MAX_VALUE) / alpha); | ||
| if (upperbound == 0) { | ||
| throw new IllegalStateException("Alpha value resulted in a rescale threshold of 0 seconds"); | ||
| } | ||
| return upperbound >= DEFAULT_RESCALE_THRESHOLD ? DEFAULT_RESCALE_THRESHOLD : TimeUnit.SECONDS.toNanos(upperbound / 2); | ||
| } |
Comment on lines
410
to
+413
| // wait for 10 millis and take snapshot. | ||
| // this should not trigger a rescale. Note that the number of samples will be reduced to 0 | ||
| // because scaling factor equal to zero will remove all existing entries after rescale. | ||
| clock.addSeconds(20 * 60); | ||
| clock.addSeconds(5 * 60); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As noted in #793, no new samples are recorded after ~13 hours as new priority returns infinity. This behavior is solved in #793 . However, it's probably an unwanted behavior that we expose
alpha, but do not automatically calculate a rescale threshold.I've added a rescale threshold calculation if the upperbound is less than the
DEFAULT_RESCALE_THRESHOLDof 1 hour; otherwise, the old threshold is used to avoid any surprising behavioral change. If you're open to this change, I'll make the corresponding modifications inLockFreeExponentiallyDecayingReservoir.cc @arteam as you looked over the original issue