Commit f398301
Report peak MemoryPool reservation per query in benchmarks (#23985)
## Which issue does this PR close?
Part of #22758. Doesn't close an issue.
## Rationale for this change
DataFusion's `MemoryPool` deliberately accounts for only the "large"
allocations that scale with input size; intermediate batches flowing
between operators are assumed to be small and left untracked. The
`MemoryPool` docs therefore advise reserving "some overhead (e.g. 10%)"
on top of the configured limit.
Nothing measures what that overhead actually is.
`MemoryPool::reserved()` is a live value that has usually fallen back to
zero by the time a query finishes, so the peak is never observed, and
benchmarks report peak RSS with nothing to compare it against.
This adds the missing number so the two can be compared. It is
measurement only — nothing enforces a relationship between the pool's
accounting and actual allocation, and no threshold or CI check is added.
This is complementary to the accounting work discussed in #22898. That
issue proposes changing *what* gets accounted (Arrow `claim()` / builder
`with_pool()`); because `ArrowMemoryPool` grows a DataFusion
`MemoryReservation` against the pool it wraps, `reserved()` is where
both models converge. This PR just makes the peak of that value
observable per query, so the effect of any such change — or of a
regression — is visible as a number rather than inferred.
Concretely, that means the peak follows the accounting instead of being
pinned to the current set of manually tracked consumers: nothing claims
buffers today, but if #22898 lands in either form, those bytes show up
here without further changes. There is a test covering that path.
## What changes are included in this PR?
- `PeakRecordingPool`, a delegating `MemoryPool` wrapper recording the
high-water mark of `reserved()`. Every method delegates; wrapping does
not change how memory is granted, limited, or reported.
- `CommonOpt::runtime_env_builder` installs it around the pool it
already builds, so every benchmark run with a memory limit reports the
peak without further changes.
- `BenchQuery` gains `pool_peak_bytes`, reset per case by
`start_new_case`, so each query gets its own reading rather than
inheriting the high-water mark of the queries before it.
- `print_memory_stats` prints the run-wide peak after the existing
mimalloc line, leaving `mem_profile`'s output parser untouched.
Everything is confined to the `benchmarks` crate. No trait changes.
`arrow-buffer/pool` and `datafusion-execution/arrow_buffer_pool` are
enabled as **dev-dependencies only**, so the benchmark binaries build
with exactly the features they had before — confirmed absent from `cargo
tree --no-dev-dependencies`.
## Are these changes tested?
Yes — 5 unit tests plus a doctest, and verified end-to-end with `dfbench
nlj --query 1 -i 2 --memory-limit 512M`, which emits `"pool_peak_bytes":
262528` per query.
One of those tests builds an `ArrowMemoryPool` over the recording pool
and asserts an Arrow-side reservation both raises the peak and releases
on drop, pinning the interaction described above.
The pre-existing `test_runtime_env_builder_reads_env_var` still asserts
`MemoryLimit::Finite(2G)` *through* the wrapper, which is direct
evidence the delegation is transparent.
The wrapper is installed only when a memory limit is configured, since
without one there is no pool to wrap. `pool_peak_bytes` is omitted from
the results JSON in that case, leaving output byte-identical to before
for runs without a limit — confirmed `compare.py` parses both old and
new files.
## Are there any user-facing changes?
No. Confined to the benchmarks crate; adds one optional field to the
benchmark results JSON.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 833e501 commit f398301
22 files changed
Lines changed: 631 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
486 | 494 | | |
487 | 495 | | |
488 | 496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
302 | 305 | | |
303 | 306 | | |
304 | 307 | | |
| |||
312 | 315 | | |
313 | 316 | | |
314 | 317 | | |
315 | | - | |
| 318 | + | |
316 | 319 | | |
317 | 320 | | |
318 | 321 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
169 | 171 | | |
170 | 172 | | |
171 | 173 | | |
172 | | - | |
| 174 | + | |
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
| |||
182 | 184 | | |
183 | 185 | | |
184 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
188 | 193 | | |
189 | 194 | | |
| 195 | + | |
190 | 196 | | |
191 | 197 | | |
192 | 198 | | |
| |||
198 | 204 | | |
199 | 205 | | |
200 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
201 | 213 | | |
202 | 214 | | |
203 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
216 | 217 | | |
217 | 218 | | |
218 | 219 | | |
| |||
278 | 279 | | |
279 | 280 | | |
280 | 281 | | |
281 | | - | |
| 282 | + | |
282 | 283 | | |
283 | 284 | | |
284 | 285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
| 336 | + | |
336 | 337 | | |
337 | 338 | | |
338 | 339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
| 567 | + | |
567 | 568 | | |
568 | 569 | | |
569 | 570 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
| 298 | + | |
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
308 | 314 | | |
309 | 315 | | |
310 | 316 | | |
| |||
314 | 320 | | |
315 | 321 | | |
316 | 322 | | |
| 323 | + | |
317 | 324 | | |
318 | 325 | | |
319 | 326 | | |
| |||
348 | 355 | | |
349 | 356 | | |
350 | 357 | | |
351 | | - | |
| 358 | + | |
352 | 359 | | |
353 | 360 | | |
354 | 361 | | |
| |||
0 commit comments