Sub topic 3
Choosing node types and instance families
This chapter assumes you know what a driver, worker, and executor are, and that you can read basic Spark UI output. You should also know the difference between on-demand and spot instances. Here you will pick a node type by matching an instance family to what limits your workload.
What a node type decides
A node type is a cloud virtual machine shape. It fixes the number of cores, the memory, the local storage, and whether a GPU is attached. Each worker gets one node type, and you set it with node_type_id. The driver can use a different type through driver_node_type_id. If you leave it unset, the driver uses the worker type.
Cores set how many tasks run at once. Memory sets how much data each task can hold before it spills to disk. A node type is a ratio of these resources, so you choose the ratio that fits your bottleneck.
Instance families
Cloud providers group their machines into families. The names below are AWS examples. Azure and GCP have equivalent families.
| Family | Typical AWS examples | Best for | Watch out for |
|---|---|---|---|
| General purpose | m5, m6i | Mixed ETL, a safe default | Not the cheapest for any single bottleneck |
| Memory optimized | r5, r6i | Wide joins, large aggregations, caching, spill-heavy jobs | Paying for memory you do not use |
| Compute optimized | c5, c6i | CPU-heavy transforms, UDFs, compression | Low memory per core causes spill |
| Storage optimized | i3, i4i | Shuffle-heavy jobs, repeated reads using disk cache | Higher price per core |
| GPU | g5, p3 | Deep learning, GPU-accelerated ML libraries | Idle GPUs are expensive, and most Spark SQL work cannot use them |
Storage optimized nodes have fast local NVMe disks. Databricks uses them for shuffle files, spill, and the disk cache. This is why the examples in this tutorial use i3.xlarge.
Match the family to the bottleneck
Decide what limits the job before you pick a family.
Start with general purpose if you have no measurements yet. Then check the Spark UI. Large "Spill (disk)" values on a stage point to a memory-bound job. CPU near 100% with no spill points to a compute-bound job.
Fewer large nodes or many small ones
Total cores can come from either. Larger nodes reduce the shuffle traffic that crosses the network, because more data stays on one machine. They also give each task more memory headroom. But losing one large node, for example to a spot reclaim, loses more work. Many small nodes spread that risk, but they add network shuffle and run more executor overhead. A mid-sized node, such as 8 to 16 cores, is a reasonable starting point.
Size the driver separately
The driver holds the query plan and collects results. Increase its size if you call collect() on large results, broadcast big tables, or run many concurrent notebooks on one cluster. Otherwise the worker type is usually enough.
{
"cluster_name": "etl-split-driver",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"driver_node_type_id": "r5.2xlarge",
"autoscale": { "min_workers": 2, "max_workers": 8 },
"autotermination_minutes": 30
}Exercise
A stage in the Spark UI shows 40 GB of "Spill (disk)", and CPU use on the workers is only 35%. Which family should you try first, and why?
Show answer
A memory optimized family such as r5 or r6i. The spill shows tasks do not have enough memory per core, and the low CPU shows cores are not the limit. More memory per core lets tasks keep data in memory.