Sub topic 8
Setting minimum and maximum workers
This chapter assumes you know how autoscaling adds and removes workers, and that you can read a cluster specification in JSON. The two bounds you set decide how much the cluster costs at idle and at peak. They also decide how quickly it reacts to load.
What each bound controls
min_workers is the floor. The cluster never shrinks below it while it is running. max_workers is the ceiling. The cluster never grows beyond it, however many tasks are queued.
{
"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
}The driver is not counted in either number. It always runs, and you pay for it in addition to the workers.
Choosing the minimum
Set the minimum to the smallest cluster that runs your lightest stages without strain. Look at the early stages of a typical run, such as reading and filtering. If two workers handle them well, use two.
- Too low: every run starts small and waits while the cluster adds nodes. Short jobs may finish before scaling helps.
- Too high: you pay for idle capacity between bursts, which defeats the purpose of autoscaling.
Choosing the maximum
Start from your fixed-size estimate. If a job needs about 64 cores to meet its target runtime and each node has 4 cores, the ceiling is about 16 workers. Round down at first and raise the ceiling only if measurements show tasks queuing.
The maximum is also a cost limit. A runaway query on an unbounded cluster spends money quickly. Other limits can sit below your setting:
- Your cloud account's instance quota.
- A cluster policy, which can cap
autoscale.max_workers.
{
"autoscale.max_workers": {
"type": "range",
"maxValue": 8,
"defaultValue": 4
}
}With this policy, a user cannot request more than 8 workers, whatever they type in the cluster form.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Very wide range, such as 1 to 100 | Slow, uneven scaling and unpredictable cost | Narrow the range using measured peak demand |
| Minimum equal to maximum | The cluster is effectively fixed size | Use this on purpose, for example for streaming |
| Maximum far above the data's parallelism | Extra workers sit idle because there are too few partitions to use them | Compare the maximum's total cores with partition counts |
| Never revisiting the bounds | Bounds drift out of step as data grows | Re-measure on a schedule |
Exercise
Exercise
A nightly job peaks at about 96 cores of useful work. Its first stages run fine on 8 cores. Workers have 8 cores each. What minworkers and maxworkers would you start with, and why?
Show answer
Start with minworkers 1 and maxworkers 12. The maximum is 96 cores divided by 8 cores per node, which gives 12. The minimum is 1 because 8 cores cover the light stages. Raise the minimum if startup delays hurt, and lower the maximum if the Spark UI shows workers sitting idle.