Sub topic 3
Compute for Job Tasks
This chapter assumes you can create a Databricks job with notebook tasks and know what a cluster is. It covers where a task runs and how to choose that compute.
Compute options for a task
Every task needs compute. You pick one of these options per task:
| Option | Lifecycle | Typical use |
|---|---|---|
| Job cluster | Created when the run starts, terminated when the run ends | Scheduled production pipelines |
| All-purpose cluster | Exists independently, shared with interactive users | Development and debugging |
| Serverless compute | Managed by Databricks, no cluster settings to tune | Workloads where you want fast startup and no sizing |
| SQL warehouse | Managed warehouse for SQL tasks | SQL, dashboard, and alert tasks |
Job clusters cost less than all-purpose clusters for the same work, because jobs compute is billed at a lower rate. Use all-purpose clusters for production jobs only when you have a specific reason, such as a very short startup requirement.
Sharing a job cluster across tasks
A job cluster is defined once in the job_clusters array and given a job_cluster_key. Each task refers to that key. All tasks that share the key run on one cluster during a run, so you pay for one startup instead of one per task.
{
"job_clusters": [
{
"job_cluster_key": "etl_cluster",
"new_cluster": {
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"num_workers": 2
}
}
],
"tasks": [
{
"task_key": "ingest",
"job_cluster_key": "etl_cluster",
"notebook_task": {"notebook_path": "/Workspace/Shared/ingest"}
}
]
}The node_type_id value i3.xlarge is an AWS instance type. Azure and Google Cloud use different names, so change it for your cloud.
Choosing between options
Use these questions to decide:
- Is the job production and scheduled? Prefer a job cluster or serverless compute.
- Do tasks need different libraries or hardware? Give them separate job clusters. A GPU task and a lightweight SQL task should not share one.
- Do you need no cluster management at all? Choose serverless, and accept that you control fewer Spark settings.
- Is the task a SQL task? Point it at a SQL warehouse.
Common errors
- Slow runs from repeated startup. Giving each task its own
new_clusterstarts a cluster per task. Share one withjob_cluster_keywhen the tasks have compatible needs. - Wrong cluster size. A shared cluster is sized for the whole run. If one task needs far more memory than the rest, split it onto its own job cluster.
- Cloud-specific values. Node types and some Spark settings differ by cloud. A definition copied from another workspace can fail at cluster creation.
- Running production on an all-purpose cluster. Another user can restart it, change its libraries, or load it with interactive work, which makes runs unpredictable.
Exercise
A job has an ingest task that needs 2 small workers and a training task that needs GPU nodes. Should they share one job cluster? Explain.
Show answer
No. A shared job cluster has one hardware definition for the whole run. Define two job clusters, for example "etlcluster" and "gpucluster", and set each task's jobclusterkey to the one it needs. This avoids paying for GPU nodes during ingest.