Sub topic 14
Monitoring clusters and troubleshooting common problems
This chapter assumes you know the driver and worker structure of a cluster, the difference between all-purpose, job, and serverless compute, and how autoscaling and auto termination work. It covers where to look when a cluster misbehaves and how to read the most common failure signals.
Where to look
Databricks exposes cluster state in several places. Start with the one that matches your question.
| Question | Where to look |
|---|---|
| Did the cluster start, resize, or terminate, and why? | Event log on the cluster page |
| Is the cluster short of CPU, memory, or disk? | Metrics tab on the cluster page |
| Which stage or task is slow? | Spark UI |
| What did my code print or fail with? | Driver logs (stdout, stderr, log4j) |
| Which libraries or init scripts failed? | Event log and driver logs |
The event log is the best first stop. It records starting, running, resizing, and terminating events, and each termination carries a reason code. The Metrics tab charts CPU, memory, and network use per node, so you can tell whether the driver or the workers are under pressure.
A troubleshooting flow
Most problems fall into three groups: the cluster would not start, the cluster stopped unexpectedly, or the work ran but was slow or failed.
Cluster will not start
Open the event log and read the termination reason. Typical causes:
- Cloud quota or capacity. The cloud provider cannot supply the requested instances. Try a different node type, a smaller size, or ask for a quota increase.
- Permissions or network. The workspace cannot create instances or reach required endpoints. This usually needs a cloud administrator.
- Init script failure. A script that exits with a non-zero code stops the cluster. Check the script logs, and test the script on a small cluster.
- Incompatible configuration. For example, a runtime version that is no longer supported, or an access mode that a library or feature does not support.
Cluster stops unexpectedly
If the termination reason is inactivity, auto termination did what you configured. Raise autotermination_minutes if the idle window is too short for your workflow, or accept it as the cost control it is.
Other causes are different:
- Spot instance loss. If workers use spot capacity, the provider can reclaim them. Spark retries tasks, but repeated loss can fail a job. Keep the driver on on-demand capacity and consider on-demand workers for critical jobs.
- Driver out of memory. Collecting a large result to the driver, such as with
collect()ortoPandas(), can exhaust driver memory. The driver then becomes unresponsive and the cluster may restart. Filter or aggregate first, or write results to storage instead.
Work is slow or failing
Look at the Metrics tab, then the Spark UI.
- Memory pressure and spill. Tasks that spill to disk run slowly. Use larger nodes or more workers, or reduce the data each task handles.
- Data skew. A few tasks run far longer than the rest in the stage view. Repartition on a better key or let adaptive query execution handle the skew.
- Autoscaling lag. Scale-up takes time because new instances must start. For a short, bursty job, a fixed size can be faster.
- Library conflicts. A cluster-installed library that clashes with the runtime can raise import errors. Prefer the versions bundled with the runtime unless you need a change.
Serverless compute removes node-level tuning, so the Metrics tab and node choices do not apply. For serverless, rely on the query profile and the run output, and open a support case for platform-side faults.
Reading cluster state from the API
You can fetch the same events the UI shows. This helps when you need to check many clusters or log failures.
import os
import requests
host = os.environ["DATABRICKS_HOST"]
token = os.environ["DATABRICKS_TOKEN"]
resp = requests.post(
f"{host}/api/2.1/clusters/events",
headers={"Authorization": f"Bearer {token}"},
json={
"cluster_id": "0123-456789-abcdefgh",
"event_types": ["TERMINATING", "RESIZING"],
"limit": 10,
},
timeout=30,
)
resp.raise_for_status()
for event in resp.json().get("events", []):
print(event["timestamp"], event["type"], event.get("details", {}))Replace the cluster ID with your own. The details field of a TERMINATING event holds the reason code.
Exercise
A nightly job on a job cluster fails twice a week. The event log shows workers lost, and the workers use spot instances. Which two changes reduce the failures?
Show answer
Run the workers (or at least the critical ones) on on-demand capacity, and keep the driver on on-demand capacity. Because job clusters are recreated each run, make the change in the job definition.
Exercise
A notebook on an all-purpose cluster becomes unresponsive after calling toPandas() on a large table. Which node is likely the problem, and what is a better approach?
Show answer
The driver ran out of memory. Filter or aggregate the data in Spark before converting it, or write the result to storage and read only what you need.