Skip to content

Local worker allocations - #559

Merged
gabotechs merged 1 commit into
mainfrom
gabrielmusat/local-worker-allocations
Jul 24, 2026
Merged

Local worker allocations#559
gabotechs merged 1 commit into
mainfrom
gabrielmusat/local-worker-allocations

Conversation

@gabotechs

@gabotechs gabotechs commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Small optimization that allows the dynamic planner to collocate single-tasked stages into the same machine that is acting as coordinator.

During dynamic planning, if all stages are small, they will just use 1 task, and before this PR, there was already some logic for co-locating all stages in a single worker. The challenge:

The single worker was a random worker in the cluster.

This means that if the coordinating context also happens to be in the scope of a worker, there's a missed chance for running everything locally, almost as if it was just single-node DataFusion.

This PRs unlocks this scenario by allowing users to inject their own LocalWorkerContext into the coordinating SessionContext. That way, the coordinator itself can recognize it's also a worker, and can send to itself all these single-tasked stages, avoiding network hops and data serialization.

Benchmarks

TPCH-SF1: 1.12 faster ✔
TPCH-SF10: 1.06 faster ✔
TPCH-SF100: 1.01 faster ✔
TPC-DS: 1.08 faster ✔
ClickBench: 1.01 faster ✔

@gabotechs
gabotechs force-pushed the gabrielmusat/local-worker-allocations branch 2 times, most recently from f6799a0 to 2dbf1fb Compare July 20, 2026 09:45
@gabotechs
gabotechs marked this pull request as ready for review July 20, 2026 10:36
@gabotechs
gabotechs force-pushed the gabrielmusat/local-worker-allocations branch 2 times, most recently from af42530 to 2183672 Compare July 21, 2026 10:12
@gabotechs
gabotechs force-pushed the gabrielmusat/local-worker-allocations branch from 2183672 to 407fbeb Compare July 21, 2026 12:17
collect(Arc::clone(&plan), ctx.task_ctx()).await?;
let format = DistributedMetricsFormat::Aggregated;
let plan = rewrite_distributed_plan_with_metrics(plan, format).await?;
println!("{}", display_plan_ascii(plan.as_ref(), true));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stray println

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this one is on purpose, like the ones we have on metrics_collection.rs, for local iteration is nice to see the plan in the output.

.with_default_features()
.with_config(SessionConfig::new().with_target_partitions(3))
.with_distributed_planner()
.with_distributed_local_worker_context(workers[0].to_local_worker_context(first_worker_url))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Do you think CoordinatorContext is more clear than LocalWorkerContext because it only exists on the coordinator?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also exists on workers actually, during a query, in each remote worker, we populate the SessionContext with this same information:

.with_extension(Arc::new(LocalWorkerContext {
task_data_entries: Arc::clone(&self.task_data_entries),
self_url: request.target_worker_url,
}))
.with_distributed_option_extension_from_headers::<DistributedConfig>(&headers)?;

This way, workers can recognize when they need to reach themselves, and fallback to a local connection, rather than a remote one. This is the same, but in the coordinator, in case it also happens to be a worker.

@gabotechs
gabotechs merged commit 9524a5a into main Jul 24, 2026
31 checks passed
@gabotechs
gabotechs deleted the gabrielmusat/local-worker-allocations branch July 24, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants