Distributed execution
Distributed execution runs an optimized Daft query across a Ray cluster. The driver coordinates the query and its data layout, while Ray actors run local physical plans on worker nodes. The path streams partition references and execution data back to the caller without copying all table data through the driver. See Execution engines for the shared runner model, Local execution for the single-process path, and UDFs and aggregations for the user-defined computation model.
Runner orchestration
The Ray runner is the query entry point for distributed work. It connects to an existing Ray context or starts one, freezes the query context, optimizes the plan, and gives a distributed physical plan to the Flotilla coordinator. Flotilla is Daft's Ray-based plan coordinator; it turns distributed pipeline stages into tasks and streams completed results to the runner.
This diagram shows the main control and data path from a query to distributed results.
flowchart LR
A[Optimized logical plan] --> B[Distributed physical plan]
B --> C[Flotilla plan coordinator]
C --> D[Task scheduler]
D --> E[Ray worker actors]
E --> F[Local physical plans]
F --> G[Ray or Flight partition references]
G --> C
C --> H[Driver result stream]
C --> I[Task and operator statistics]
The runner keeps partition sets in a Ray-aware cache. A result can remain in Ray's object store as a RayPartitionRef until a caller asks for table data. This lets downstream queries reuse partition references and lets the driver collect results by reference rather than by value. daft/…/ray_runner.py• L296-394 src/…/ray.rs• L11-69
Query lifecycle
When a Ray query starts, the runner assigns a query ID and creates query metadata. It reports the unoptimized plan, optimized plan, physical plan, and terminal query state through the context. The physical plan includes the current partition references so plan nodes and execution statistics use the same node layout. A heartbeat runs while the query is active, so external views can distinguish active work from a stalled or finished query. daft/…/ray_runner.py• L574-660 daft/…/ray_runner.py• L683-717
The coordinator uses a named Flotilla actor whose name is scoped to the Ray job. That actor retains the active plan and result stream, while the driver asks for the next completed partition. The final item carries execution statistics, so result delivery and query accounting finish together. If the caller stops consuming the stream early, the runner still closes the query lifecycle and stops the heartbeat. daft/…/flotilla.py• L671-717 daft/…/flotilla.py• L731-816 daft/…/ray_runner.py• L669-716
References: daft/…/ray_runner.py• L538-567 daft/…/ray_runner.py• L574-717 daft/…/flotilla.py• L582-668 daft/…/flotilla.py• L671-816
Ray deployment modes
The runner supports a local Ray cluster, a remote Ray cluster, Ray Client, and Ray Jobs. In a Ray Job, the query code runs in the cluster environment, so the worker environment must provide the same Daft and Python support needed by the submitted job. Ray Client also requires matching Python minor versions between the client and server. docs/…/ray.md• L3-5 docs/…/ray.md• L57-75 docs/…/ray.md• L114-147
References: docs/…/ray.md• L3-5 docs/…/ray.md• L57-75 docs/…/ray.md• L114-147
Ray compatibility
Daft keeps Ray-specific differences at the boundary between the distributed engine and Ray. The compatibility layer detects whether the installed Ray version accepts label_selector; when it does not, it converts Daft's selector into a NodeLabelSchedulingStrategy. It validates runtime_env and currently permits only a Conda environment. daft/…/ray_compat.py• L14-29 daft/…/ray_compat.py• L32-57 daft/…/ray_compat.py• L60-99
Data crosses the boundary as Arrow tables, Python row data, or Ray object references. The adapter maps Daft tensor types to the Ray Data tensor extensions available in the installed Ray version and maps them back when data returns to Daft. It also handles Ray Data schema, block-reference, and tensor attribute changes across Ray versions. daft/…/ray_runner.py• L81-127 daft/…/ray_runner.py• L151-186 daft/…/ray_runner.py• L195-268 daft/…/ray_runner.py• L421-473
Worker environment
Every Flotilla worker receives the query's relevant runtime settings. These settings include dashboard and task-event routing, loaded Daft extension paths, and the resources that Ray assigned to the actor. Workers load the same native extensions as the driver before they deserialize plans that use those extensions. daft/…/flotilla.py• L102-136 daft/…/flotilla.py• L139-186 daft/…/flotilla.py• L430-482
References: daft/…/ray_compat.py• L60-99 daft/…/flotilla.py• L102-136 daft/…/flotilla.py• L139-186 daft/…/flotilla.py• L430-482
Actor pools
Distributed actor pools serve stateful or costly user-defined functions. A pool creates Ray actors with a shared expression and resource request, then uses those actors to evaluate input batches inside distributed tasks. This keeps actor state and setup work separate from the short-lived task that carries each input partition. See UDFs and aggregations for the wider UDF and aggregation model.
Flotilla worker actors
Each eligible Ray node gets one RaySwordfishActor. The actor owns a local Daft executor and can run several local plans concurrently. The scheduler treats the actor as a worker with CPU, GPU, memory, active-task, and node-location information. daft/…/flotilla.py• L139-191 src/…/worker.rs• L18-61
The actor resolves source inputs and partition references, runs the local physical plan, and returns either Ray object references or Flight references. It coalesces ordinary small outputs where this does not change a fixed shuffle output layout. This makes the worker boundary useful for both normal task results and shuffle stages. daft/…/flotilla.py• L193-289
References: daft/…/flotilla.py• L139-191 daft/…/flotilla.py• L193-289 src/…/worker.rs• L66-117
UDF actor pools
An actor-pool UDF creates the requested number of actors and applies the requested CPU, GPU, memory, placement, and Ray options to each actor. Daft checks that at least one Ray node can satisfy one actor and waits for actors to become ready. The pool can use the actors that become ready before the configured timeout when the cluster cannot host the full request. Each actor can restart or retry Ray work within the pool's configured fault limits. daft/…/ray_actor_pool_udf.py• L24-40 daft/…/ray_actor_pool_udf.py• L79-165
The distributed actor-UDF stage initializes its pool once for the stream of input tasks. It adds the actor evaluation to each task plan, waits for all tasks that use the pool, and tears the actors down only after that work ends. This order prevents actor cleanup from racing with in-flight UDF calls. src/…/actor_udf.rs• L32-119 src/…/actor_udf.rs• L175-205
References: daft/…/ray_actor_pool_udf.py• L24-76 daft/…/ray_actor_pool_udf.py• L79-165 src/…/actor_udf.rs• L175-205
UDF worker processes
Regular UDF evaluation can run in a dedicated worker process inside the task's execution environment. The parent sends the expression once, then exchanges input and output batches through authenticated local control messages and shared memory. The worker returns both the evaluated batch and its operator metrics, so the distributed task can report normal execution data without moving large batches through the control channel. daft/…/udf.py• L33-55 daft/…/udf.py• L58-113 daft/…/udf_worker.py• L26-72
The worker uses one compute thread and reports UDF errors or process failures back to the parent. The parent drains worker output while it waits for a result, which keeps user output and large batch results from blocking each other. daft/…/udf_worker.py• L38-101 daft/…/udf.py• L134-193
References: daft/…/udf.py• L33-55 daft/…/udf.py• L83-113 daft/…/udf.py• L134-193 daft/…/udf_worker.py• L26-101
Task and resource management
The distributed pipeline produces task builders instead of executing data on the driver. A task builder combines a local physical plan with its source inputs, upstream partition references, resource request, placement preference, cancellation state, and query context. When the scheduler builds it, the task receives a unique ID and context used by result handling and metrics. src/…/task.rs• L319-358 src/…/task.rs• L482-533
Scheduling policy
The scheduler maintains pending tasks until a worker snapshot shows enough capacity. Its normal placement policy spreads a task to a worker with the most available capacity. A task may instead require a specific worker or prefer that worker while allowing a fallback. Task priority keeps earlier queries ahead of later queries and preserves a stable order within a query. src/…/default.rs• L46-85 src/…/task.rs• L194-239
The scheduler and dispatcher form a loop. The scheduler refreshes worker state and assigns tasks. The dispatcher submits them in worker groups, awaits any completed result, reports its outcome, and returns retryable failures to the pending queue. A dead worker is removed from the worker set; an unavailable worker remains known but its task can still be retried. src/…/scheduler_actor.rs• L101-230 src/…/dispatcher.rs• L36-149
References: src/…/task.rs• L24-44 src/…/task.rs• L194-239 src/…/default.rs• L46-109 src/…/dispatcher.rs• L36-149
Autoscaling policy
Pending demand can cause the Ray worker manager to request CPU, GPU, or memory bundles from the Ray autoscaler. Daft exposes two request strategies through set_runner_ray: gradual scaling grows the request by one bundle per autoscaler cycle, while bisect scaling requests all pending demand and halves the request when the cluster does not grow within its timeout. The bisect strategy uses worker identity and total resource growth to tell a real scale-up from a same-capacity worker replacement. daft/…/__init__.py• L67-109 src/…/worker_manager.rs• L25-89 src/…/worker_manager.rs• L292-302 src/…/worker_manager.rs• L507-780
Worker discovery is rate-limited, so newly provisioned nodes enter scheduling through a later refresh. Autoscaler requests are also rate-limited to match Ray's reconciliation cycle because a new request replaces the current demand rather than adding to it. src/…/worker_manager.rs• L18-23 src/…/worker_manager.rs• L104-151 src/…/worker_manager.rs• L534-617
Scale-in is separate and opt-in. When enabled, idle workers can be retired after an idle period while a minimum survivor count and the Ray head worker remain protected. The manager clears stale autoscaler demand and briefly excludes released workers so the next refresh does not immediately recreate them. docs/…/ray.md• L149-169 src/…/worker_manager.rs• L304-476
References: daft/…/__init__.py• L67-136 src/…/worker_manager.rs• L91-151 src/…/worker_manager.rs• L206-302 src/…/worker_manager.rs• L304-476 src/…/worker_manager.rs• L480-780 docs/…/ray.md• L149-169
Task outcomes
Task results carry output references and execution stats, or a worker-death or worker-unavailable state. Cancellation reaches the Ray task handle and the scheduler's cancellation token. A normal task error is returned to the query, while a worker failure returns the task for another scheduling attempt. src/…/task.rs• L17-49 src/…/task.rs• L84-143 src/…/task.rs• L536-580
References: src/…/task.rs• L17-49 src/…/task.rs• L84-143 src/…/dispatcher.rs• L101-149
Cross-worker shuffles
A distributed shuffle changes the partition layout so later tasks can read the rows required by a hash, range, random, or gather operation. The default Ray backend keeps partition references in Ray's object store. An optional Flight backend writes shuffle data to worker-local storage and serves it through a shuffle server, which reduces pressure on the Ray object store and head node for large shuffles. src/…/translate_shuffle.rs• L22-35 src/…/mod.rs• L81-123
This diagram shows the map and read sides of a Ray-backed repartition.
flowchart LR
A[Upstream task outputs] --> B[Shuffle write]
B --> C[Partition references by output slot]
C --> D[Reference transpose]
D --> E[One read task per output partition]
E --> F[Downstream local plan]
The repartition stage first materializes upstream write outputs. It then groups references by destination partition and emits read tasks. Each read task receives the references for one destination, so all rows for that partition meet at the same downstream task. src/…/repartition.rs• L76-91 src/…/mod.rs• L125-171 src/…/ray.rs• L12-39
Shuffle sizing
Large Ray shuffles can create high object-store or head-node pressure because the number of input-to-output partition pieces grows with both partition counts. The translator can insert a pre-shuffle merge that combines outputs on their producing workers before the shuffle read. It emits a hint to use flight_shuffle when the input size or partition product is large. src/…/translate_shuffle.rs• L70-132 src/…/pre_shuffle_merge.rs• L103-179
The pre-shuffle merge preserves worker locality for its merge tasks. It groups materialized outputs by worker, flushes a group when it reaches the configured size, and sends the merge task back to that same worker. This reduces the number of small objects without changing the destination partition contract. src/…/pre_shuffle_merge.rs• L111-169
References: src/…/translate_shuffle.rs• L70-203 src/…/pre_shuffle_merge.rs• L103-179
Gather behavior
Gather is the single-partition form of a shuffle. The stage materializes all upstream outputs, combines their references, and emits one read task that consumes the full input. The translator avoids this boundary when the input already has one partition. src/…/translate_shuffle.rs• L134-159 src/…/gather.rs• L63-89
Ray shuffle references live until the plan no longer needs them. Flight shuffle directories are registered with the plan and cleared from all Ray nodes when the plan completes. Cleanup is therefore part of query completion rather than a separate operator concern. src/…/runner.rs• L191-219 src/…/mod.rs• L12-27 daft/…/flotilla.py• L79-99
References: src/…/gather.rs• L63-89 src/…/runner.rs• L191-219 src/…/mod.rs• L12-27
Progress and query coordination
The distributed engine turns task state and worker execution stats into query-level progress. A statistics manager tracks the distributed nodes touched by each task, combines worker measurements by node origin, and sends task lifecycle events to subscribers. This separates scheduler state from the views that show progress or operator metrics. src/…/mod.rs• L33-59 src/…/mod.rs• L176-230
Task lifecycle
Task events describe submission, scheduling, completion, failure, and cancellation. Worker death and temporary worker unavailability are marked as retryable, so they do not appear as final query failures while the dispatcher resubmits the task. Non-retryable errors produce a terminal task event. src/…/mod.rs• L61-110 src/…/task_lifecycle.rs• L48-119
References: src/…/mod.rs• L33-110 src/…/task_lifecycle.rs• L48-119
Operator statistics
Each distributed pipeline node has a runtime manager with active, completed, failed, and canceled task counters. On completion, worker stats are attributed to the distributed node that originated the local operator work. The manager also emits operator start and end events only after task production and in-flight task completion agree, which prevents early or missing end events. src/…/stats.rs• L62-105 src/…/stats.rs• L111-168 src/…/mod.rs• L185-255
References: src/…/stats.rs• L62-105 src/…/stats.rs• L111-168 src/…/mod.rs• L185-255
Progress views
The progress bar groups task submissions and completions by query and distributed node. It treats cancellation as finished work and ignores retryable failures so a retry does not advance the bar twice. The distributed runner always installs the progress bar, while task-event and dashboard subscribers are enabled according to their runtime settings. src/…/progress_bar.rs• L9-89 src/…/mod.rs• L278-295
Workers receive dashboard and task-event settings through their Ray runtime environment. This allows task and operator events to be sent from the actor process where the work runs, while the driver still owns the query's final result and execution metadata. When a result stream ends, the binding flushes any operator that started but did not drain normally before it exports final metrics. daft/…/flotilla.py• L430-447 src/…/mod.rs• L65-97 src/…/mod.rs• L278-325
References: src/…/progress_bar.rs• L18-89 src/…/dashboard.rs• L19-151 src/…/mod.rs• L278-325 daft/…/flotilla.py• L430-447
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the task input variants, Ray task wrapper, worker input resolution, and local physical source nodes aligned. A mismatch can fail only after a task reaches a worker.
- Keep
RayPartitionRefmetadata aligned with result conversion and partition-set cache behavior. Row or byte metadata drives progress, planning hints, and result inspection. - When changing actor resources or Ray options, check both the actor creation path and the scheduler's worker-capacity view. The requested resource shape must be schedulable on one Ray node.
- When changing actor-pool startup or retries, check resource validation, readiness timeout behavior, partial-pool handling, actor restart and task retry limits, and teardown after all users finish.
- When changing the UDF worker protocol, keep the parent and child message states, shared-memory ownership, output-divider handling, and metrics return contract aligned. The parent must continue to drain child output while waiting for a result.
- When changing runner configuration, keep the public
set_runner_rayoptions aligned with the Flotilla actor and the Rust worker manager. Invalid autoscale strategies and zero bisect timeouts must remain rejected. - When changing Ray option compatibility, keep supported option detection, label-selector conversion, scheduling-strategy precedence, and runtime-environment validation aligned with the Ray versions Daft supports.
- When changing Ray Data conversion, check Arrow schema normalization, tensor extension names and attributes, block-reference APIs, and both Ray Dataset and Dask input paths.
- When changing task status handling, preserve the difference between retryable worker failure and terminal task failure. Statistics and progress subscribers must receive the same lifecycle meaning.
- When changing repartition output count or order, check the reference transpose and every shuffle read task. Fixed output slots are part of the downstream contract.
- When changing shuffle backends or directories, update backend selection, worker read and write behavior, plan cleanup, and large-shuffle guidance together.
- When changing worker startup or autoscaling, preserve refresh rate limits, released-worker exclusion, head-worker protection, and the distinction between scale-up and scale-in.
- When changing the named Flotilla actor or extension runtime environment, check Ray job isolation and the rule that extensions must load before the first query.
- When changing query teardown or early result consumption, check heartbeat shutdown, operator end events, task cancellation, result-stream closure, Flight directory cleanup, and UDF worker teardown.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Ray is not installed or the Ray version lacks a required Data or scheduling API | The distributed runner or a compatibility path fails before query work can start | Install the Ray extra and keep Ray option, schema, block-reference, and Arrow conversion changes behind capability or version checks. daft/…/ray_runner.py• L40-45 daft/…/ray_compat.py• L14-29 daft/…/ray_runner.py• L421-473 |
A Ray version does not accept label_selector | A placement request can fail before its task or actor starts | Detect the option and convert the selector to a NodeLabelSchedulingStrategy for older Ray versions. daft/…/ray_compat.py• L19-57 |
runtime_env contains a setting other than conda | Ray option validation rejects the runner configuration | Pass a dictionary with only the supported conda key. daft/…/ray_compat.py• L87-99 |
| No single Ray node can satisfy one actor-UDF resource request | The actor pool cannot start and the query raises before UDF processing | Check per-node CPU and GPU capacity before creating the pool. daft/…/ray_actor_pool_udf.py• L105-118 |
| The autoscale strategy is invalid or its bisect timeout is zero | The distributed runner rejects its worker manager configuration | Use gradual or bisect and a positive bisect timeout. daft/…/__init__.py• L98-103 src/…/worker_manager.rs• L160-183 |
| The requested actor pool is larger than current cluster capacity | Only a partial pool may become ready before the timeout, which lowers UDF parallelism | Treat the ready-actor count as the active pool and size resources or the readiness timeout for the workload. daft/…/ray_actor_pool_udf.py• L120-165 |
| A UDF actor or task reaches its restart or retry limit | The actor-UDF stage loses the failed actor's work and can fail the task or query | Keep actor resources valid and allow the distributed dispatcher to retry worker failures. daft/…/ray_actor_pool_udf.py• L24-31 src/…/dispatcher.rs• L101-137 |
| A UDF child process exits, breaks its control connection, or cannot serialize its error | The parent reports a process or UDF failure instead of returning a batch | Keep the parent-child message contract and error fallback intact. daft/…/udf_worker.py• L73-101 daft/…/udf.py• L164-193 |
| A UDF floods its output pipe while the parent waits for a result | The child can block before it sends the result, so the task hangs | Drain child output and the result connection at the same time. daft/…/udf.py• L134-164 |
| A worker actor is unschedulable, unreachable, or slow during startup | That node is skipped; an initial cluster with no ready workers fails, while an existing fleet continues and retries discovery later | Use a valid startup timeout and keep capacity available for at least one worker. daft/…/flotilla.py• L485-566 |
| A task's worker dies during execution | Its output is lost, the worker leaves the manager, and the task returns to pending work | Do not treat a worker-death result as success; allow the dispatcher to retry it on another worker. src/…/dispatcher.rs• L101-137 |
| Pending demand exceeds available Ray capacity or a cluster limit blocks the autoscaler request | Tasks remain pending and the query may wait for workers that cannot be provisioned | Monitor pending tasks and cluster limits; choose gradual or bisect scaling based on how quickly the cluster should approach its limit. src/…/worker_manager.rs• L507-780 |
| A Ray-backed shuffle creates too many partition pieces or stores too much data in the object store | Head-node or object-store memory pressure can slow or fail the shuffle | Reduce partition counts, enable pre-shuffle merging, or use flight_shuffle with usable worker-local disk. src/…/translate_shuffle.rs• L161-203 |
| A Flight shuffle directory is unavailable or stale | The next stage cannot read its partition references, or old data consumes worker disk | Use valid local directories and rely on plan cleanup across all Ray nodes. src/…/runner.rs• L191-219 daft/…/flotilla.py• L79-99 |
| A worker starts after the Flotilla coordinator was created with a different extension set | Plans that use a later-loaded extension cannot deserialize or run on existing actors | Load extensions before the first Ray query. daft/…/flotilla.py• L731-816 |
Key files
| File | Why to read it |
|---|---|
| daft/…/__init__.py | Defines the public Ray runner and autoscaling configuration boundary. |
| daft/…/ray_runner.py | Defines the Ray runner entry point, query lifecycle, Ray Data and Dask conversion, partition cache, and result stream. |
| daft/…/ray_compat.py | Defines the compatibility boundary for Ray options, placement selectors, and runtime environments. |
| daft/…/flotilla.py | Defines the Flotilla coordinator, Ray worker actors, worker startup, result conversion, per-job actor identity, and autoscaler hooks. |
| src/…/mod.rs | Exposes distributed plans and result streams to Python and connects execution to progress and query statistics. |
| src/…/runner.rs | Connects distributed pipeline task production, scheduling, result materialization, and shuffle cleanup. |
| src/…/task.rs | Defines task identity, inputs, resource requests, placement choices, cancellation, and task status. |
| src/…/default.rs | Shows worker-capacity placement, affinity behavior, priority, and autoscaling demand. |
| src/…/dispatcher.rs | Shows task submission, result handling, cancellation, worker death, and retry flow. |
| src/…/worker_manager.rs | Connects scheduler worker state to Ray actor discovery, gradual or bisect autoscaling, and idle-worker retirement. |
| src/…/actor_udf.rs | Shows how actor-pool UDFs become part of distributed task plans and how their lifetime is coordinated. |
| daft/…/ray_actor_pool_udf.py | Defines Ray actor-pool creation, resource checks, readiness, actor locality, and per-actor UDF evaluation. |
| daft/…/udf.py | Defines the parent side of process-isolated UDF execution and its shared-memory result path. |
| daft/…/udf_worker.py | Defines the child process that evaluates UDF batches and returns metrics or errors. |
| src/…/translate_shuffle.rs | Selects shuffle backends, sizes shuffle boundaries, and chooses pre-shuffle merging. |
| src/…/mod.rs | Defines the common shuffle reference flow for Ray and Flight backends. |
| src/…/pre_shuffle_merge.rs | Shows worker-local merging before a large repartition. |
| src/…/mod.rs | Coordinates task events, operator lifecycle, subscribers, and final execution metrics. |
| src/…/dashboard.rs | Connects distributed task events to live dashboard operator statistics. |
| src/…/ray.rs | Defines the Ray partition reference and the metadata carried with object-store data. |