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

   > [!NOTE]
   > Draft. Benchmark results from one machine (AMD Ryzen 9 7950X, 16 cores / 
32 threads). Results from other hardware, especially Intel and ARM servers with 
SMT, would be very welcome.
   
   ## Which issue does this PR close?
   
   - Part of #26169.
   
   ## Rationale for this change
   
   On Linux machines with simultaneous multithreading (SMT, or 
hyper-threading), `target_partitions` defaults to the number of hardware 
threads, so two partitions share each physical core. They compete for that 
core's L1/L2 cache and execution units. Hash aggregation and hash join are 
sensitive to cache misses, so CPU-bound queries get slower with the extra 
partitions, not faster.
   
   On a Ryzen 9 7950X (16 cores, 32 threads), TPC-H SF100 total time drops from 
133.5 s to 117.7 s (12%) when going from 32 to 16 partitions. TPC-H q1 drops 
from 6.2 s to 3.2 s, and at 32 partitions it uses twice the user CPU time.
   
   ## What changes are included in this PR?
   
   - `target_partitions` now defaults to the number of physical cores the 
process may run on, instead of `available_parallelism()`.
   - The physical core count comes from the CPUs in `Cpus_allowed_list` 
(`/proc/self/status`) and their `physical_package_id` / `core_id` in 
`/sys/devices/system/cpu`. This respects `taskset` and cpusets: a process 
pinned to 4 CPUs on separate cores gets 4 partitions, and a process pinned to 8 
CPUs that are SMT siblings of 4 cores gets 4.
   - The default is unchanged:
     - on other operating systems;
     - when SMT is off;
     - when the topology cannot be read;
     - when the process is limited by a CPU quota (`available_parallelism()` is 
then smaller than the allowed CPU count, and the quota does not say which cores 
are used).
   - New option `datafusion.execution.target_partitions_physical_cores` 
(default `true`). Setting it to `false` restores the previous default of one 
partition per hardware thread. Like `enable_dynamic_filter_pushdown`, it is 
handled in `ConfigOptions::set`: it changes `target_partitions` only while that 
still equals its default. An explicit `target_partitions` that differs from the 
default is kept, whichever of the two is set first. The config system does not 
record whether a value was set explicitly, so an explicit value equal to the 
default is treated as the default.
   - `planning_concurrency` keeps its current default.
   - Updated the config docs and added an upgrade guide entry.
   
   ## What is the testing strategy for this PR?
   
   - Unit tests for the CPU list parser, a check that the result is between 1 
and `available_parallelism()`, and a test that 
`target_partitions_physical_cores` switches the default and keeps an explicit 
`target_partitions`.
   - Checked on Linux that the default is 16 on a 16-core / 32-thread machine, 
and 4 under `taskset -c 0-3` and `taskset -c 0-3,16-19`.
   - Benchmarks below.
   
   ### Benchmarks
   
   `bench.sh` suites, main vs this PR, on a Ryzen 9 7950X (16 cores / 32 
threads, 128 GB RAM, Ubuntu). `bench.sh` does not pass `--partitions` for these 
suites, so they use the default.
   
   RESULTS_PLACEHOLDER
   
   ## Are there any user-facing changes?
   
   Yes. On Linux with SMT, the default `datafusion.execution.target_partitions` 
is now the number of physical cores rather than the number of hardware threads, 
so plans have fewer partitions by default. Users who want the old behavior can 
set `datafusion.execution.target_partitions_physical_cores = false`, or set 
`target_partitions` explicitly. New config option, no other public API changes.
   
   ## AI usage disclosure
   
   This change and the benchmarks were done with Claude Code (Claude Opus) 
under my direction. I have not reviewed the code yet.
   
   🤖 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