adriangb opened a new pull request, #27932:
URL: https://github.com/apache/datafusion/pull/27932

   ## Which issue does this PR close?
   
   - None. Follow-up to 
[#27811](https://github.com/apache/datafusion/pull/27811).
   
   ## Rationale for this change
   
   mimalloc keeps freed memory for reuse. `dfbench` runs every query in one 
process, so the time of an iteration depends on what ran before it. A benchmark 
of a PR must not depend on that.
   
   In an A/A experiment on a `c4a-standard-16` VM, with 6 ClickBench queries, 
running another query first made an iteration slower:
   
   | Memory setting | Mean slowdown after another query | Between-process CV |
   |---|---|---|
   | default | 7.2% | 1.8% |
   | reset before each iteration | 0.6% | 1.3% |
   
   This experiment used an earlier prototype of the reset. A larger run on 
three VMs (43 queries, forward and reversed order, injected regressions) is in 
progress. This PR stays a draft until its results are in.
   
   ## What changes are included in this PR?
   
   Two commits, best reviewed in order:
   
   1. **Build the Tokio runtime in one place.** This is a refactor and does not 
change behavior.
   2. **Add `--reset-memory`.** It returns free memory to the OS before each 
iteration, outside the timed part. It is off by default.
   
   ```text
   interleave.py
      ├── dfbench (main)                  ├── dfbench (PR)
      │     reset memory   (not timed)    │     reset memory   (not timed)
      │     send `ready`, wait for `run`  │     send `ready`, wait for `run`
      │     run the query  (timed)        │     run the query  (timed)
   ```
   
   `mi_collect` empties only the heap of the calling thread. So the reset 
blocks one task on each runtime thread at a barrier, and then collects twice:
   
   ```text
   each thread: arrive ── collect ── arrive ── collect ── arrive
                   │                    └ frees memory that another thread 
released in round one
                   └ holds the thread, so no thread runs two of the tasks
   ```
   
   | Case | Behavior |
   |---|---|
   | A thread stays busy | The reset gives up after 2 seconds and prints a 
warning |
   | A worker blocks while it holds the task of a parked worker | The main 
thread spawns an empty task every 1 ms, which wakes workers |
   | The build does not have `mimalloc_extended`, or uses `snmalloc` | The 
process stops with an error |
   
   Not in this PR: `interleave.py` does not pass the flag yet, and 
`mimalloc_extended` is not a default feature.
   
   ## What is the testing strategy for this PR?
   
   - A unit test asserts that the reset visits every thread exactly twice, and 
that a busy thread does not hang it.
   - I ran that unit test in 3000 processes (50 resets each), with no failures. 
Before the 1 ms wakeup, about 1 process in 400 failed. The reset's barrier code 
did not change after that run.
   - I ran the flag end to end through `interleave.py` on a small dataset, and 
in a build without `mimalloc_extended` to check the error.
   - `./dev/rust_lint.sh` passes, except `check_docs_html.sh`, which needs 
tools that I do not have locally. This PR does not change `docs/`.
   
   ## Are there any user-facing changes?
   
   No change for DataFusion users. The benchmark binaries have a new 
`--reset-memory` flag.
   
   New public items in the unpublished `datafusion-benchmarks` crate: 
`util::build_runtime`, `CommonOpt::reset_memory`, and 
`Sampler::with_reset_memory`.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to