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

   ## Which issue does this PR close?
   
   - Closes #27872.
   
   ## Rationale for this change
   
   `elapsed_compute` records wall-clock time. When a host runs more busy 
threads than it has cores, a large part of a timed section can be time the 
thread spent waiting to be scheduled, and the metric charges that wait to 
whichever operator happened to be descheduled. Recording the thread's CPU time 
instead makes the metric a measure of the work an operator did, which is what 
profiling a busy system needs.
   
   ## What changes are included in this PR?
   
   - New option `datafusion.execution.cpu_time_metrics` (default `false`), with 
`SessionConfig::cpu_time_metrics` and `SessionConfig::with_cpu_time_metrics`.
   - `Time::with_cpu_time` / `Time::cpu_time`: the timers of such a `Time` 
(`Time::timer`, `ElapsedComputeFuture`) read the thread CPU clock 
(`CLOCK_THREAD_CPUTIME_ID`, Unix only). A timer stopped on a different thread 
than the one that started it records wall-clock time; other platforms always 
record wall-clock time.
   - `BaselineMetrics::with_cpu_time`, and `with_cpu_time` on the operator 
metrics structs that wrap it. Operators apply the session setting in `execute`.
   - `FileSource::with_cpu_time_metrics` (provided method returning `None`), 
implemented by `ParquetSource` and `CsvSource`, and 
`FileStreamBuilder::with_cpu_time`.
   - `datafusion-physical-expr-common` depends on `libc` (already a dependency 
of `datafusion-common`).
   - Only `elapsed_compute` is affected; other timing metrics (for example a 
hash join's build time) still record wall-clock time.
   
   ## What is the testing strategy for this PR?
   
   - Unit tests: a CPU-time `Time` leaves out a sleep that a wall-clock `Time` 
includes; a CPU clock reading taken on another thread falls back to wall-clock 
time; `BaselineMetrics::with_cpu_time` carries over to `intermediate()` and the 
registered metric still reports the recorded time.
   - `information_schema.slt` lists the new option.
   - Overhead: TPC-H SF10 (`dfbench tpch`, Parquet, 8 cores, 5 iterations; off 
and on interleaved twice, the median of iterations 2-5 summed over the 22 
queries): 9,415 ms off, 9,421 ms on (+0.1%), within the 3-5% the same setting 
varied between rounds. The clock is read per timed section (usually per batch), 
not per row.
   
   ## Are there any user-facing changes?
   
   A new configuration option, off by default, and new public methods. No 
breaking API changes: the new `FileSource` method has a default implementation.
   


-- 
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