Skip to content

Rescale threshold calculation#5169

Open
nickbar01234 wants to merge 1 commit into
dropwizard:release/4.2.xfrom
nickbar01234:nickbar01234/rescale-threshold-calculation
Open

Rescale threshold calculation#5169
nickbar01234 wants to merge 1 commit into
dropwizard:release/4.2.xfrom
nickbar01234:nickbar01234/rescale-threshold-calculation

Conversation

@nickbar01234

@nickbar01234 nickbar01234 commented Feb 28, 2026

Copy link
Copy Markdown

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_THRESHOLD of 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 in LockFreeExponentiallyDecayingReservoir.

cc @arteam as you looked over the original issue

@nickbar01234 nickbar01234 requested review from a team as code owners February 28, 2026 04:25
@nickbar01234 nickbar01234 changed the title Infer rescale threshold Rescale threshold calculation Feb 28, 2026
@github-actions github-actions Bot added this to the 4.2.39 milestone Feb 28, 2026
@joschi joschi force-pushed the nickbar01234/rescale-threshold-calculation branch from d620bd2 to 57497d8 Compare May 24, 2026 19:16
@joschi joschi requested a review from Copilot May 24, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 rescaleThreshold based on alpha (falling back to the previous default threshold for typical alpha values).
  • 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);
@joschi joschi modified the milestones: 4.2.39, 4.2.40 May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants