Dynamic allocation
| Also known as | Dynamic resource allocation, spark.dynamicAllocation
|
|---|---|
| Field | Distributed data processing |
| Introduced | Apache Spark 1.2.0; shuffle tracking (no external shuffle service needed) in 3.0.0 |
| Key parts | Request policy (backlog timeouts, exponential ramp-up), remove policy (idle timeouts), shuffle data preservation |
| Open source implementations | Apache Spark on standalone, YARN and Kubernetes |
| Related | Executor, External shuffle service, Shuffle, Caching and persistence |
Dynamic allocation is an Apache Spark feature that adds executors to an application when tasks are waiting and removes executors that sit idle, so that an application holds only the resources its current work needs. It is off by default (spark.dynamicAllocation.enabled=false) and works on the standalone, YARN and Kubernetes cluster managers.[1] Because removing an executor would also remove the shuffle files it wrote, dynamic allocation needs a way to keep shuffle data available: an external shuffle service, shuffle tracking, shuffle block migration or a shuffle storage plugin.[1]
How does dynamic allocation scale executors?
Adding executors. When tasks have been pending for spark.dynamicAllocation.schedulerBacklogTimeout (default 1s), Spark requests more executors, and it requests again every spark.dynamicAllocation.sustainedSchedulerBacklogTimeout (default: the same value) while the backlog lasts. Each round asks for twice as many as the last: 1, then 2, 4, 8 and so on. The Spark docs compare this to TCP slow start: cautious at first, but able to ramp up quickly.[1][2]
Removing executors. An executor that has been idle for spark.dynamicAllocation.executorIdleTimeout (default 60s) is removed. Executors that hold cached data are kept by default, because spark.dynamicAllocation.cachedExecutorIdleTimeout is infinite.[1][2]
| Setting | Default |
|---|---|
spark.dynamicAllocation.enabled |
false |
spark.dynamicAllocation.minExecutors |
0 |
spark.dynamicAllocation.maxExecutors |
infinity |
spark.dynamicAllocation.initialExecutors |
minExecutors (or spark.executor.instances if larger)
|
spark.dynamicAllocation.executorAllocationRatio |
1 (request enough executors for full parallelism) |
spark.dynamicAllocation.schedulerBacklogTimeout |
1s |
spark.dynamicAllocation.executorIdleTimeout |
60s |
spark.dynamicAllocation.cachedExecutorIdleTimeout |
infinity |
spark.dynamicAllocation.shuffleTracking.enabled |
true |
spark.dynamicAllocation.shuffleTracking.timeout |
infinity |
Source: Spark 4.3.0 configuration reference.[2]
How is shuffle data kept when executors are removed?
During a shuffle, each executor writes its map output to local disk and serves those files to other executors. If dynamic allocation removed that executor, the files would have to be recomputed.[1] Spark 4.3.0 accepts four ways to avoid this; one of them must be configured with dynamic allocation:[1][2]
| Approach | Setting | How it works |
|---|---|---|
| Shuffle tracking | spark.dynamicAllocation.shuffleTracking.enabled (default true, since 3.0.0)
|
Spark keeps executors alive while they store shuffle data for active jobs, so no external service is needed[2][3] |
| External shuffle service | spark.shuffle.service.enabled=true
|
A long-running process on each node serves shuffle files after the executor that wrote them is gone[1] |
| Decommissioning with shuffle migration | spark.decommission.enabled and spark.storage.decommission.shuffleBlocks.enabled
|
Before an executor is removed, its shuffle blocks are copied to other executors[2] |
| Shuffle storage plugin | spark.shuffle.sort.io.plugin.class (experimental)
|
A custom ShuffleDataIO stores shuffle data in reliable storage[2]
|
Shuffle tracking is the simplest because it needs no extra service. Its trade-off is that an executor holding shuffle data is not released until the shuffle is garbage collected, unless spark.dynamicAllocation.shuffleTracking.timeout sets a limit.[2]
How does dynamic allocation behave on Kubernetes?
Spark on Kubernetes does not support the external shuffle service, so spark.shuffle.service.enabled=true cannot be used there.[1] Kubernetes deployments use shuffle tracking (on by default), decommissioning with shuffle block migration, or a shuffle storage plugin.[1] With spark.decommission.enabled, Spark decommissions an executor instead of killing it when dynamic allocation removes it; when block manager decommissioning (spark.storage.decommission.enabled) is also on, Spark tries to migrate the executor's RDD and shuffle blocks to other executors first.[2] spark.storage.decommission.fallbackStorage.path can name a storage location, for example an S3 path, for blocks that cannot be moved to another executor; Spark does not clean it up.[2]
On Kubernetes, spark.kubernetes.dynamicAllocation.deleteGracePeriod (default 5s) is how long Spark waits for an executor pod to shut down before a forceful kill.[4] Shuffle and spill files go to emptyDir volumes by default, which do not outlive the pod; persistent volume claims created on demand per executor (claimName=OnDemand) are one way to give executors larger local storage when they are created dynamically.[4]
Caveats
- Standalone mode cores. Without
spark.executor.cores, each standalone executor takes all cores of a worker, and dynamic allocation can acquire many more executors than expected. The docs recommend setting cores explicitly (see SPARK-30299).[1] - Cached data. Executors with cached blocks are never removed by default. With
spark.shuffle.service.fetch.rdd.enabled, executors that hold only disk-persisted RDD blocks can be released, and the blocks are served by the external shuffle service.[1] - Local checkpoints. The Spark source warns that local checkpointing is not safe with dynamic allocation, which removes executors together with their cached blocks. See Checkpointing (Spark).[5]
Example
spark.dynamicAllocation.enabled true
spark.dynamicAllocation.shuffleTracking.enabled true
spark.dynamicAllocation.minExecutors 2
spark.dynamicAllocation.maxExecutors 50
spark.dynamicAllocation.executorIdleTimeout 120s
spark.executor.cores 4
See also
References
- ↑ 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 Job Scheduling: Dynamic Resource Allocation (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 2.00 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 Spark Configuration: Dynamic Allocation (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SPARK-27963: Allow dynamic allocation without an external shuffle service. Apache Software Foundation JIRA.Retrieved 2026-11-23.
- ↑ 4.0 4.1 Running Spark on Kubernetes (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ RDD.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.