Sub topic 2
Picking a Starting Size for a Fixed Cluster
Assume you know Spark jobs, stages, tasks, partitions, and shuffles, and can run a Databricks notebook or job. This chapter uses worker for a cluster VM that runs Spark executors. The driver coordinates the job.
Picking a starting size for a fixed cluster
Start with the workload, not the largest available machine. For a batch job, estimate input size, shuffle volume, run-time target, and concurrency. A practical first choice is a small fixed cluster: one driver and two to four workers. Choose worker size from the bottleneck:
| Workload | Starting choice |
|---|---|
| Compute-bound | More cores per worker |
| Memory-bound | More memory per worker |
| Storage-bound | Local SSD or fast attached storage |
| GPU workload | GPU worker family |
Use enough partitions to keep task slots busy. As a rough starting point, target at least two to three tasks per available core for a batch stage, then verify in the Spark UI.
{
"cluster_name": "etl-fixed",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"num_workers": 3,
"autotermination_minutes": 30
}How autoscaling works
Autoscaling changes the number of workers between configured bounds. Databricks adds workers when tasks queue or utilization stays high, and removes workers when demand falls. It helps variable batch workloads, but scaling takes time and does not repair a poor partitioning strategy.
{
"cluster_name": "etl-autoscale",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"autoscale": {
"min_workers": 2,
"max_workers": 8
},
"autotermination_minutes": 30
}Setting minimum and maximum workers
Set min_workers high enough for normal traffic and max_workers high enough for the largest expected batch. A low minimum saves money but increases warm-up time. A high maximum can increase cost without helping a single-threaded or shuffle-limited job.
When not to autoscale
Prefer fixed sizing for steady streaming workloads. A streaming query needs stable capacity, and worker removal or startup can cause processing delay. Autoscaling also cannot solve driver memory pressure, data skew, or too few partitions. Test scaling behavior before using it for latency-sensitive jobs.
Autoscaling changes capacity, not application logic. Check skew, failed tasks, partition sizes, and executor memory before raising the maximum.Stopping idle clusters automatically
Set auto-termination for interactive clusters and short-lived jobs. It stops a cluster after the configured idle period and limits charges from forgotten sessions. Choose a delay that does not repeatedly discard a cluster between notebook commands.
Exercise
A batch job normally uses three workers but occasionally has a large monthly run. Which configuration is a reasonable starting point?
Show answer
Use autoscaling with minworkers set to 3 and maxworkers set to the tested peak, then confirm the Spark UI shows useful parallelism.