Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public TimeWindowPercentileHistogram(Clock clock, DistributionStatisticConfig di
protected TimeWindowPercentileHistogram(Clock clock, DistributionStatisticConfig distributionStatisticConfig,
boolean supportsAggregablePercentiles, boolean isCumulativeBucketCounts, boolean includeInfinityBucket) {
super(clock, distributionStatisticConfig, DoubleRecorder.class);
intervalHistogram = new DoubleHistogram(percentilePrecision(distributionStatisticConfig));
intervalHistogram = new DoubleHistogram(computeHighestToLowestValueRatio(distributionStatisticConfig),
percentilePrecision(distributionStatisticConfig));
intervalHistogram.setAutoResize(true);

this.isCumulativeBucketCounts = isCumulativeBucketCounts;

Set<Double> monitoredBuckets = distributionStatisticConfig.getHistogramBuckets(supportsAggregablePercentiles);
Expand All @@ -80,7 +83,8 @@ protected TimeWindowPercentileHistogram(Clock clock, DistributionStatisticConfig

@Override
DoubleRecorder newBucket() {
return new DoubleRecorder(percentilePrecision(distributionStatisticConfig));
return new DoubleRecorder(computeHighestToLowestValueRatio(distributionStatisticConfig),
percentilePrecision(distributionStatisticConfig));
}

@Override
Expand All @@ -100,7 +104,8 @@ void resetBucket(DoubleRecorder bucket) {

@Override
DoubleHistogram newAccumulatedHistogram(DoubleRecorder[] ringBuffer) {
return new DoubleHistogram(percentilePrecision(distributionStatisticConfig));
return new DoubleHistogram(computeHighestToLowestValueRatio(distributionStatisticConfig),
percentilePrecision(distributionStatisticConfig));
}

@Override
Expand Down Expand Up @@ -143,6 +148,27 @@ private int percentilePrecision(DistributionStatisticConfig config) {
return config.getPercentilePrecision() == null ? 1 : config.getPercentilePrecision();
}

/**
* Compute the highestToLowestValueRatio based on the configured min/max expected
* values. This allows HdrHistogram to cover the expected range without frequent
* resizing.
* @param config The distribution statistic configuration
* @return The computed ratio, or 2 if not enough information is available
*/
private long computeHighestToLowestValueRatio(DistributionStatisticConfig config) {
Double min = config.getMinimumExpectedValueAsDouble();
Double max = config.getMaximumExpectedValueAsDouble();

// Only compute ratio if both min and max are explicitly set and finite
if (min != null && max != null && min > 0 && max > min && !Double.isInfinite(max)) {
// Compute the ratio, ensuring it's at least 2
long ratio = (long) Math.ceil(max / min);
return Math.max(ratio, 2L);
}

return 2L;
}

@Override
void outputSummary(PrintStream out, double bucketScaling) {
accumulatedHistogram().outputPercentileDistribution(out, bucketScaling);
Expand Down