Sub topic 2
Matching the cluster to the workload
A cluster that suits one job can be slow or wasteful for another. This chapter covers the four common workload profiles (ETL, interactive, machine learning, and BI), what each one asks of a cluster, and how that shapes your first sizing decision. It assumes you know Spark jobs, stages, tasks, and partitions, and that you can run notebooks and jobs in a Databricks workspace. It also assumes you have read the previous chapter on the driver, workers, and executors.
Why the workload comes first
Sizing questions such as "how many workers?" have no answer until you know how the cluster will be used. Four properties of the workload decide most of the answer:
- Duration and schedule. A nightly job runs for an hour and is then done. A notebook session stays open all day.
- Concurrency. One job uses the cluster alone. A dashboard may have 40 people querying at once.
- Resource shape. Some work is limited by CPU, some by memory, some by disk or GPU. The next chapter covers choosing instance families for these.
- Tolerance for delay. A batch job can wait several minutes for a cluster to start. An analyst cannot.
The four profiles
| Profile | Typical compute | Main pressure | Sizing tendency |
|---|---|---|---|
| ETL (batch pipelines) | Job cluster, created per run | Throughput over large data | Size for the data volume; autoscaling is often useful |
| Interactive (exploration) | All-purpose cluster | Responsiveness and idle time | Small or autoscaling, with short auto-termination |
| Machine learning | All-purpose or job cluster, ML runtime | Memory, driver capacity, sometimes GPU | Often single node or driver-heavy |
| BI and SQL | SQL warehouse | Many concurrent short queries | Scale by concurrency, not by data volume alone |
ETL: batch pipelines
ETL work reads a large amount of data, transforms it with joins and aggregations, and writes the result. It runs on a schedule, so the cluster only needs to exist while the job runs. Run it on a job cluster, which Databricks creates when the run starts and terminates when the run ends. Job clusters also bill at a lower DBU rate than all-purpose clusters (the cost chapter covers DBUs).
The workload is throughput-bound. More cores shorten the run until you run out of useful parallelism, meaning partitions to process. Shuffle-heavy jobs also need memory and local disk, because shuffle data that does not fit in memory spills to disk. A good starting point is a size that finishes inside your time window with a margin.
Interactive: exploration and development
Interactive work is bursty. A person runs a cell, reads the result, thinks, and runs another. The cluster is idle for most of the session, so idle time is the main cost. Choose a small cluster or a modest autoscaling range, and set auto-termination so a forgotten cluster does not run overnight.
Several people often share one all-purpose cluster. Shared use raises concurrency on the driver and the workers, so a cluster that is fine for one user may be slow for five. Heavy, long-running work does not belong on a shared interactive cluster. Move it to a job cluster.
Machine learning
ML workloads differ from ETL because much of the work may not run on the workers at all. Libraries such as scikit-learn, pandas, and many plotting tools run on the driver only. A cluster with ten large workers does nothing for that code, and you pay for the idle workers. For single-machine training, a single-node cluster (a driver with zero workers) is often the right choice.
Distributed training, hyperparameter search with Spark-aware tools, and deep learning change this. Deep learning typically needs GPU instance types and the ML runtime. Memory per node matters, because a model and its training data may need to fit on one machine.
BI and SQL
Dashboards and SQL editors send many short queries from many users. For this profile, use a SQL warehouse instead of a general cluster. You choose a warehouse size (a "t-shirt size" such as Small or Large), which sets the compute for each query. You also set a minimum and maximum number of clusters, which controls how many queries can run at once. Query speed depends on the size. Concurrency depends on the cluster count. Treat them as separate settings.
Choosing a profile
The diagram is a starting heuristic. Real workloads mix profiles. A pipeline might do ETL in the first stages and train a model in the last. In that case, split the work into separate tasks, each with its own cluster.
Turning a profile into a starting spec
The function below maps a profile name to a starting cluster specification in the Clusters API format. The values are starting points to be measured and adjusted, not recommendations. Node types and the Spark version are examples and depend on your cloud and workspace.
import json
BASE = {
"spark_version": "15.4.x-scala2.12",
}
def starting_spec(profile: str) -> dict:
"""Return a first-guess cluster spec for a workload profile."""
if profile == "etl":
return {
**BASE,
"cluster_name": "etl-starting-point",
"node_type_id": "i3.xlarge",
"autoscale": {"min_workers": 2, "max_workers": 8},
}
if profile == "interactive":
return {
**BASE,
"cluster_name": "dev-shared",
"node_type_id": "i3.xlarge",
"autoscale": {"min_workers": 1, "max_workers": 4},
"autotermination_minutes": 30,
}
if profile == "ml_single_node":
return {
**BASE,
"cluster_name": "ml-single-node",
"node_type_id": "r5.4xlarge",
"num_workers": 0,
"spark_conf": {
"spark.databricks.cluster.profile": "singleNode",
"spark.master": "local[*]",
},
"custom_tags": {"ResourceClass": "SingleNode"},
"autotermination_minutes": 60,
}
raise ValueError(f"No cluster spec for profile: {profile!r}. "
"BI workloads use a SQL warehouse instead.")
if __name__ == "__main__":
print(json.dumps(starting_spec("ml_single_node"), indent=2))The function raises an error for BI on purpose. A SQL warehouse is configured through a different API with sizes and cluster counts, not through a Spark cluster spec.
Common mistakes
- Running scheduled jobs on an all-purpose cluster. This costs more per DBU and lets other users' work compete with the job. Use a job cluster.
- Adding workers for driver-bound code. If the time is spent in pandas or scikit-learn on the driver, more workers change nothing. Check where the time goes before scaling out.
- Sizing a shared interactive cluster for one user. Concurrency raises memory and scheduling load. Size for the typical number of active users.
- Using one large cluster for a whole mixed pipeline. The ETL stage and the training stage need different resources. Separate them.
- Sizing BI for data volume only. A warehouse that is large enough for one query can still queue queries when many users arrive. Raise the maximum cluster count for concurrency.
What to carry forward
Choose the compute type first: job cluster, all-purpose cluster, single node, or SQL warehouse. Then choose node types and counts inside that type. The following chapters take each of those decisions in turn, starting with instance families.
Exercise
A team runs a nightly pipeline on a shared all-purpose cluster that stays up all day, and an analyst complains that the cluster is slow at 2 a.m. when the pipeline runs. Which profile does the pipeline belong to, what should the team change, and why?
Show answer
The pipeline is an ETL workload: scheduled, unattended, and throughput-bound. The team should move it to a job cluster that is created for each run and terminated afterward. This removes competition with interactive users, avoids paying for an idle cluster between runs, and uses the lower job-compute DBU rate. The team can then size the job cluster for the pipeline alone.
Exercise
A data scientist trains a model with scikit-learn on a cluster with 1 driver and 10 workers, and the training is not faster than on a laptop. What is the likely cause, and what cluster shape fits better?
Show answer
scikit-learn runs on the driver only, so the 10 workers sit idle. A single-node cluster (zero workers) with a large-memory instance type for the driver fits better. If the model needs distributed training, switch to a Spark-aware or distributed library, or to GPU nodes for deep learning.