feat: Add mergeBuffer/maxSpillProximity metric for groupBy spill diagnosis #19627
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 627 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.385
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #19627"
general
weight: 0.35
abhishekrb19
Description
When a groupBy query runs,
ConcurrentGrouperdivides the single acquired merge buffer intodruid.processing.numThreadsequal slices (sliceSize = capacity / numThreads) and gives one slice to each processing thread. A query spills to disk as soon as its fullest single slice fills — at roughlysizeBytes / numThreads, which can be far below the configureddruid.processing.buffer.sizeBytes.The existing metrics do not let an operator see this.
mergeBuffer/maxBytesUsedis a per-query sum across slices, further discounted by the hash-table load factor, so it never approachessizeByteseven while queries are actively spilling — making it impossible to compare againstdruid.processing.buffer.sizeBytesor to reason about spill pressure.Concretely, an operator with
sizeBytes = 125 MiBandnumThreads = 240(slices ≈ 546 KiB) sawgroupBy/spilledQueriesclimbing whilemergeBuffer/maxBytesUsedsat around ~60 MB, which looks contradictory until you account for slicing.Change
This PR adds
mergeBuffer/maxSpillProximity, a dimensionless gauge in[0.0, 1.0]that reports how close a groupBy query came to spilling to disk:BufferHashGrouperspills on: it can no longer allocate a new bucket. The denominator is the terminal-levelregrowthThreshold— the bucket-count ceiling of the largest table the slice can grow to before it must spill. Because the table grows by doubling andsizeonly grows (preserved across rehash), the ratio is monotonic and rises smoothly to exactly1.0at the real spill point (a bucket allocation is rejected, or the table is parked at its terminal threshold). Dividing by the current level's threshold instead produces a sawtooth — it resets to ~0.5 on every doubling and climbs back to ~1.0 before the next — which would pin the lifetime max near(N-1)/Nfor any query that grows even once, regardless of remaining headroom.0.0. ALIMITquery without an aggregator-dependent sort usesLimitedBufferHashGrouper, whose two-sub-bufferAlternatingByteBufferHashTableheap-trims to the top-limitentries and never disk-spills via that path. Its sub-buffer refills to the threshold on every swap, so it is deliberately excluded from fill-proximity recording (it would otherwise saturate near(T-1)/T ≈ 1.0and read as a perpetual near-spill). Only a genuine bucket rejection on that table would report1.0.Operators can read
mergeBuffer/maxSpillProximityalongsidegroupBy/spilledQueries: a value near1.0means slices are saturating, and the fix is to widen each slice by raisingdruid.processing.buffer.sizeBytesor loweringdruid.processing.numThreads.Changed files
ByteBufferHashTable— track the lifetime-maxsize / terminalRegrowthThresholdratio (getMaxSpillProximity()), pinned to1.0at the real spill trigger and preserved acrossreset().computeSpillRegrowthThreshold()derives the fixed terminal denominator by replaying the arena geometry (no allocation, memoized); arecordsFillProximity()hook lets heap-trim tables opt out of fill recording.LimitedBufferHashGrouper— itsAlternatingByteBufferHashTableoverridesrecordsFillProximity()tofalseso heap-trim swaps are not misreported as spills; a genuine bucket rejection still pins1.0.AbstractBufferHashGrouper— exposegetMaxSpillProximity()(0.0 when the grouper was never initialized).GroupByStatsProvider— keep the per-slice maxgetSpillProximity()(clamped to[0,1],NaNignored), aggregated as a max across queries.SpillingGrouper— report each slice's peak proximity inclose()(only when initialized).GroupByStatsMonitor— emitmergeBuffer/maxSpillProximity.docs/operations/metrics.md— document the new metric and clarify the slicing semantics ofmergeBuffer/bytesUsedandmergeBuffer/maxBytesUsed.<hr>
This PR has:
mergeBuffer/maxSpillProximity; no behavior or config changes.)