Avoid NaN values causing problems in metrics output #2812
Merged
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.
Resolves #464
Long-running but very low (i.e., no) traffic servers would report problems when formatting timer output in JSON because there would be cases in which a
double
would be computed by dividing 0 by 0, yieldingDouble.NaN
.This 0-by-0 division can occur when an underlying data structure used by the timer (and histogram) accumulates samples with zero weight and then attempts to compute the relative weight of one of those samples. That weight is zero, the total weight is zero, and the relative weight division results in
NaN
.JSON formats a double value by converting it to a string and then converting the string as a
BigDecimal
.BigDecimal
rejects this when the string isNaN
, and that's the exception at the root of the stack trace.The changes in this PR avoid storing samples in the underlying data structure that have no weight (and would not factor in any statistics anyway).
In the course of working on this, I found and fixed a bug unrelated to the problem. (The timer implementation accepts a clock, as does the histogram implementation. The timer delegates some work to a histogram but was not initializing the histogram with the same clock the timer itself uses. This caused several minutes of frustration in trying to create a timer-based test using a clock which the test artificially advances over several hours.)
Signed-off-by: tim.quinn@oracle.com tim.quinn@oracle.com