geoffreyclaude commented on code in PR #26242:
URL: https://github.com/apache/datafusion/pull/26242#discussion_r4279853822
##########
datafusion/physical-plan/src/sorts/sort.rs:
##########
@@ -690,16 +704,38 @@ impl ExternalSorter {
batches
};
- let streams = runs
- .into_iter()
- .map(|batch| {
- let reservation = self
- .reservation
- .split(get_reserved_bytes_for_record_batch(&batch)?);
- let input = self.sort_batch_stream(batch, reservation)?;
- Ok(spawn_buffered(input, 1))
- })
- .collect::<Result<_>>()?;
+ let sort_concurrency = Arc::clone(&self.sort_concurrency);
+ let concurrency = Handle::try_current()
+ .ok()
+ .filter(|handle| handle.runtime_flavor() ==
RuntimeFlavor::MultiThread)
+ .map(|handle| {
+ sort_concurrency.get_or_init(|| {
+ let limit = handle.metrics().num_workers();
+ SortConcurrency {
+ limit,
+ permits: Arc::new(Semaphore::new(limit)),
+ }
+ })
+ });
+ let streams = if let Some(concurrency) = concurrency {
+ // Exclude scheduling waits from elapsed compute.
+ timer.stop();
+ let streams = self
+ .prepare_sort_runs(runs, concurrency)
+ .with_elapsed_compute(elapsed_compute.clone())
+ .await?;
+ timer.restart();
Review Comment:
Fixed: `sort_run` now measures sorting and memory accounting on the task
doing the work, for both inline and spawned execution. Scheduling waits remain
excluded.
--
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]