Add memory accounting to exponential histogram library. #132580
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.
Implements memory accounting (
Accountable
) and circuit breaker support for the exponential histogram library added in #131220. Just like the T-Digest library, the circuit breaker is abstracted away through an interface, so that no direct dependency on it is required for the lib.This PR now defines for the
ExponentialHistogramMerger
that if the result is queried, the merger is cleared and the caller takes ownership of the returned histogram. Therefore the caller is then responsible for correctly callingclose()
on the returned histogram.I was hesitant of doing it this way, because when implementing the ES|QL support this might cause unnecessary allocations:
E.g. for a query like
| STATS PERCENTILE(MERGE(responseTime), 0.9) by service.name, TBUCKET(1m)
it might be more efficient if we can reuse theExponentialHistogramMerger
across the aggregation groups. In this case this would mean merging all histograms for the firstservice.name
, query the percentile and then continue with the next group. It would be ideal if thePERCENTILE
could operate on a histogram instance "lent" from the merger, so that it can be reused then for the next group instead of requiring a new allocation.However, if this is actually useful we can add this behaviour later when we get to the ES|QL implementation.