Monday
I’m currently working with Databricks autoscaling configurations and trying to better understand how Spark decides when to spin up additional worker nodes. My cluster has a minimum of one worker and can scale up to five. I know that tasks are assigned to cores and that if more tasks are queued than available cores, Spark may consider adding a new worker—assuming autoscaling is enabled. But what specific conditions or metrics does Spark use to trigger the autoscaling event?
For example:
A practical scenario: If I have a single worker with 8 cores and I have more tasks than cores for a prolonged period, will Spark immediately add another worker or does it wait for some threshold of sustained load?
I’d appreciate insights from anyone who has worked with Databricks autoscaling in production. Any reference to official documentation or real-world examples of how Spark conditions must be met before a new worker is allocated would be very helpful.
Wednesday
Hi @h_h_ak ,
Thank you for your follow-up questions!
While Databricks’ autoscaling implementation is proprietary and functions as a black box, we can gain a clearer understanding by examining Apache Spark’s open-source dynamic resource allocation mechanism.
Here are the files to investigate:
ExecutorAllocationManager: ExecutorAllocationManager.scala
ExecutorAllocationClient: ExecutorAllocationClient.scala
ExecutorMonitor:ExecutorMonitor.scala
1. Number of Pending Tasks as the Primary Trigger
Dynamic resource allocation in Spark primarily relies on the number of pending tasks in the scheduler’s queue. If the number of tasks waiting to be assigned exceeds the current executor capacity (i.e., more tasks than available cores), Spark considers adding new executor nodes. This mechanism ensures that the cluster can handle increased workloads by scaling out when necessary.
2. Scheduler Backlog Timeout (spark.dynamicAllocation.schedulerBacklogTimeout)
The key configuration parameter here is parameter: spark.dynamicAllocation.schedulerBacklogTimeout. This parameter defines how long Spark should wait while there is a sustained backlog of pending tasks before deciding to add new executors.
3. Absence of Direct CPU Utilization Thresholds
Spark’s dynamic allocation does not directly use CPU utilization metrics as triggers for scaling. Instead, it focuses on task backlog and executor idle times. While high CPU usage can indirectly lead to a task backlog (since tasks may take longer to complete), there are no explicit CPU utilization thresholds that Spark monitors to decide on scaling actions
Summary
Scaling Triggers: Primarily based on a sustained backlog of pending tasks rather than direct CPU or memory utilization metrics.
Key Parameter: spark.dynamicAllocation.schedulerBacklogTimeout defines how long Spark waits with a sustained backlog before scaling up.
Open-Source Insight: While Databricks’ implementation may add proprietary enhancements, understanding Spark’s dynamic allocation provides a solid foundation for anticipating and configuring autoscaling behavior
Hope it helps
Monday
Databricks autoscaling is designed to dynamically adjust the number of worker nodes in a cluster based on workload demand, optimizing resource utilization and cost. Understanding the conditions under which Spark triggers autoscaling requires insight into how Databricks monitors and interprets the workload.
Monday
Hi @h_h_ak ,
Short Answer:
Long Answer:
Databricks autoscaling responds mainly to sustained backlogs of unscheduled tasks rather than CPU or memory usage alone. If the number of pending tasks consistently exceeds your current cluster capacity—meaning more tasks are queued than available cores can handle—Databricks will consider adding a new worker node.
Key Points:
Useful Links:
Tuesday
Hi @filipniziol,
Great summary, thanks!
It would interest me to know what the limits are in more detail. For example:
Are there specific thresholds or configurable parameters that influence these decisions?
Thanks again for the clarification!
Wednesday
Hi @h_h_ak ,
Thank you for your follow-up questions!
While Databricks’ autoscaling implementation is proprietary and functions as a black box, we can gain a clearer understanding by examining Apache Spark’s open-source dynamic resource allocation mechanism.
Here are the files to investigate:
ExecutorAllocationManager: ExecutorAllocationManager.scala
ExecutorAllocationClient: ExecutorAllocationClient.scala
ExecutorMonitor:ExecutorMonitor.scala
1. Number of Pending Tasks as the Primary Trigger
Dynamic resource allocation in Spark primarily relies on the number of pending tasks in the scheduler’s queue. If the number of tasks waiting to be assigned exceeds the current executor capacity (i.e., more tasks than available cores), Spark considers adding new executor nodes. This mechanism ensures that the cluster can handle increased workloads by scaling out when necessary.
2. Scheduler Backlog Timeout (spark.dynamicAllocation.schedulerBacklogTimeout)
The key configuration parameter here is parameter: spark.dynamicAllocation.schedulerBacklogTimeout. This parameter defines how long Spark should wait while there is a sustained backlog of pending tasks before deciding to add new executors.
3. Absence of Direct CPU Utilization Thresholds
Spark’s dynamic allocation does not directly use CPU utilization metrics as triggers for scaling. Instead, it focuses on task backlog and executor idle times. While high CPU usage can indirectly lead to a task backlog (since tasks may take longer to complete), there are no explicit CPU utilization thresholds that Spark monitors to decide on scaling actions
Summary
Scaling Triggers: Primarily based on a sustained backlog of pending tasks rather than direct CPU or memory utilization metrics.
Key Parameter: spark.dynamicAllocation.schedulerBacklogTimeout defines how long Spark waits with a sustained backlog before scaling up.
Open-Source Insight: While Databricks’ implementation may add proprietary enhancements, understanding Spark’s dynamic allocation provides a solid foundation for anticipating and configuring autoscaling behavior
Hope it helps
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group