CertSafari
    Databricks Certified Associate Developer for Apache Spark· Lessons

    Domain 4 · Lesson 24/32

    Spark driver and executor logs: diagnosing out-of-memory errors and idle clusters

    Perform logging and monitoring of Spark applications - publish, customize, and analyze Driver logs and Executor logs to diagnose out-of-memory errors, cluster underutilization, etc.

    20 min read
    3.33% of exam
    13 sources
    Published 21 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Say what a Spark driver log, executor (worker) log and compute event log each contain, and which one to open for a given failure
    • Follow a failed task from its job and stage to the executor whose log4j output explains it
    • Set up log delivery to a Volumes, S3 or DBFS path, and export metrics to outside tools
    • Tell an executor out-of-memory error from a driver out-of-memory error, and choose a fix for each
    • Spot an underused cluster from CPU, task and timeline metrics: idle cores, too few tasks, or work stuck on the driver

    Key concept

    The log follows the process — A Spark application runs as one driver process and many executor processes, and each one writes its own log. Your print statements, exception stack traces and scheduling messages go to the driver log. A task's own output and failures go to the log of the executor that ran it. To diagnose a failure, first work out which process failed, then read that process's log.

    1.What driver logs and executor logs contain

    Spark writes one log for the driver and one for each executor because they are separate processes. Driver, worker nodes, executors and the cluster manager covers what those roles do. When something fails, the first question is which process failed, because only that process's log has the evidence.

    The driver log records the application's control flow. Print and log statements from notebooks, jobs and libraries all land there, in three outputs: standard output, standard error and Log4j logs. If a query never starts, or a streaming job dies during startup, open the driver log to find the exception's stack trace. You open driver logs from the Driver logs tab on the compute details page, and you can download each file.

    The executor log, also called the worker log, is narrower. It is what you read when particular tasks misbehave and you want the output from those tasks, because that output was written on the worker that ran them. You reach worker logs through the Spark UI, not the Driver logs tab.

    A third log covers different ground. The compute event log records lifecycle events for the cluster as a whole: creation, termination, configuration edits and resizing. It keeps events for 60 days. Autoscaling history and node provisioning live here, not in the driver or executor logs.

    Three kinds of compute logging and what each one answers
    LogWhat it capturesWhere you open it
    Compute event logLifecycle events: creation, termination, configuration edits, resizingEvent log tab on the compute details page
    Spark driver logprint and log statements from notebooks, jobs and libraries; exception stack traces (standard output, standard error, Log4j)Driver logs tab on the compute details page
    Spark worker (executor) logLog4j output for the tasks that ran on that workerSpark UI tab, from the Executors table or the worker page

    Who can read these logs depends on the compute's access mode. On Standard access mode, only workspace admins can see driver logs, and executor logs are not available at all. On Dedicated access mode, the assigned user or group and workspace admins can read both.

    Checkpoint 1 of 9· Match them up

    A Spark job on classic compute is misbehaving. Match each log to the evidence you would go there to find.

    Tap a term, then the definition that fits it.

    Checkpoint 2 of 9· Exam question

    In a Databricks cluster, which statement correctly distinguishes the purpose of driver logs from executor logs when diagnosing a failed Spark application?

    Sources12

    2.Following a failed task to its executor's log

    A failure that happens inside a task is recorded on whichever executor ran it, so you trace it down the Application → job → stage → task hierarchy until you have an executor ID. In the Spark UI, the path goes like this:

    1. Open the Jobs tab and click the failed job's description.
    2. In that job's stages table, click the failing stage. The failure reason appears there, and further down the page shows why each task failed.
    3. In the stage's task list, note the Task ID and Executor ID of the task you care about.
    4. Open the Executors tab, find the row with that Executor ID, and open its logs or its thread dump.

    A thread dump is a snapshot of every thread's state in a JVM. Use one when a task hangs or runs slowly, not when it has failed. In the executor's thread dump, the task's thread is the one whose name contains TID followed by the task ID. A finished task has no thread left to match. The driver row in the Executors table has its own Thread Dump link. Use it when the driver seems to hang, for example when no Spark progress bars appear or they sit at 100%.

    Checkpoint 3 of 9· Check yourself

    Your notebook query has shown its Spark progress bars stuck at 100% for ten minutes, and the query never returns. Which Spark UI view should you open first to see what is blocking?

    Sources23

    3.Publishing logs and exporting metrics

    Driver and worker logs in the UI belong to the running compute. After you restart a terminated cluster, the Spark UI shows the restarted compute, not the run you were trying to debug. To keep logs after a cluster is gone, set up cluster log delivery when you create or edit the compute. Under Advanced, open the Logging tab, choose a destination type, and enter a log path. Delivery covers the Spark driver logs, the worker node logs and the event logs.

    Three destinations are available. Volumes (a Unity Catalog volume path) is the recommended and most secure choice on Unity Catalog-enabled compute. S3 writes to a bucket path. DBFS is legacy, and you can only use it if DBFS root and mounts are not disabled for the workspace. Logs are delivered every five minutes and archived hourly. Each cluster gets its own subfolder named after its cluster_id, so a log path of /Volumes/catalog/schema/volume receives files under /Volumes/catalog/schema/volume/06308418893214. Delivering to a volume requires the compute owner or assigned user to have READ VOLUME and WRITE VOLUME on it. It does not work with Dedicated access mode assigned to a group.

    What appears in the driver log is partly up to you. Every print and log statement in your code ends up there, which makes it the natural place to record row counts, parameters and checkpoints from your own logic. For centralized observability, Spark metrics can be exported to external monitoring systems. One documented route is to install a Datadog agent on every node with a compute-scoped init script, and to manage that script through a compute policy so it reaches all compute. For quick analysis without an agent, each chart in the compute Metrics tab has a Download CSV or Download Excel option. The By node view is the exception.

    Checkpoint 4 of 9· Check yourself

    Nightly runs use job compute that terminates when each run ends. The team wants to read the driver and executor logs from any run days later. What should they set up?

    Sources451

    4.Diagnosing executor out-of-memory errors

    An executor that runs out of memory doesn't fail cleanly. Spark removes it and retries its tasks on other executors. The job slows down, and once the same task has failed enough times, the stage and then the job fail. In the driver log, the message usually looks like this:

    A typical stage failure after an executor is lost, as reported to the drivertext
    SparkException: Job aborted due to stage failure: Task 3 in stage 0.0 failed 4 times, most recent failure: Lost task 3.3 in stage 0.0 (TID 30) (10.139.64.114 executor 4): ExecutorLostFailure (executor 4 exited caused by one of the running tasks) Reason: Remote RPC client disassociated. Likely due to containers exceeding thresholds, or network issues. Check driver logs for WARN messages.

    The error message alone does not prove a memory problem. The three most common reasons executors are removed are autoscaling (expected, not an error), spot instance losses, and running out of memory. Rule out the first two in the compute event log. If it explains nothing, open the Executors tab in the Spark UI and read the failed executors' logs. By then, memory is the most likely explanation.

    To confirm, double the memory per core and run the job again. For example, swap a 4-core, 16 GB worker for a 4-core, 32 GB worker, which gives 8 GB per core instead of 4. A worker with twice the cores and twice the memory tests nothing, because the ratio stays the same. If the job fails later or not at all, memory was the cause. This is the practical form of Executor and driver memory, spill and cluster sizing: you raise executor memory relative to cores, not the cluster's total. While the job runs, the JVM heap usage chart on the Metrics tab shows heap use against its configured maximum. Heap that stays close to the limit is an early warning, and the long pauses it causes are covered in JVM garbage collection in executors.

    If more memory doesn't help, or costs too much, look in the code. The common causes are:

    • too few shuffle partitions (set spark.sql.shuffle.partitions to auto)
    • a broadcast join hint on a large table
    • UDFs that load a whole partition into memory
    • a window function with no PARTITION BY
    • skew
    • unbounded streaming state

    Skew deserves particular attention because adding cluster memory does not fix it. When a few key values hold most of the rows, the one task that receives them has to process its whole partition while the others finish in seconds. A stage where one task reads 40 GB of shuffle data and the rest read 200 MB each will run that task out of memory however much RAM the other executors have. You confirm skew in the stage's Summary Metrics: if the Max duration exceeds the 75th percentile by 50% or more, the stage might be skewed. For an aggregation, the fix is to salt the hot keys, which means adding a random bucket suffix, then group and aggregate in two stages. For sort-merge and shuffle-hash joins, adaptive query execution can split skewed partitions automatically. Identifying and reducing data skew and Adaptive Query Execution cover those fixes in detail.

    Checkpoint 5 of 9· Put it in order

    Executors keep disappearing and stages fail with ExecutorLostFailure. Put these diagnostic steps in the order the lesson recommends.

    1. 1.If more memory doesn't help or costs too much, look in the code for causes such as too few shuffle partitions, a broadcast hint on a large table, or skew
    2. 2.Open the Executors tab in the Spark UI and read the logs of the failed executors
    3. 3.Rerun the job on a worker type with double the memory per core, for example 4 cores and 32 GB instead of 4 cores and 16 GB
    4. 4.Check the compute event log for autoscaling resizes or spot instance losses that explain the removed executors

    Checkpoint 6 of 9· Exam question

    A PySpark job aggregates web clickstream data and consistently fails with executor OutOfMemoryError exceptions, even though the cluster has ample total memory. The Spark UI's Stages tab shows one task in the failing stage processing 40 GB of shuffle data while the other 199 tasks in the same stage each process under 200 MB: clicks = spark.read.parquet("/mnt/clickstream/events") sessions = clicks.groupBy("session_id").agg(collect_list("page").alias("pages")) sessions.write.format("delta").mode("overwrite").save("/mnt/gold/sessions") What is the most likely root cause, and which change addresses it?

    Sources6378

    5.Diagnosing driver out-of-memory errors and hangs

    A driver out-of-memory error shows up in the driver log, not in an executor log, and the usual cause is code that pulls a large result into the driver. collect() returns every row as a list, and its documentation warns that all the data is loaded into the driver's memory. toPandas() does the same, with or without Arrow. As Bringing rows to the driver (collect, take, toLocalIterator, toPandas) explains, these calls are safe only when the result is small.

    Consider a groupBy("region").agg(...) that produces two million rows, followed by collect() on an 8 GB driver. The aggregation runs fine on the executors. It is the last step, sending all two million rows to one process, that fills the driver heap. Steps taken on the executors before that point leave the amount collected unchanged:

    • repartition(200) splits the same rows into more pieces, and they all still reach the driver.
    • Persisting the DataFrame changes where executors keep it, and the driver still receives every row.
    • Rewriting the aggregation as reduceByKey(...).collect() still collects one row per region.

    The fix that works is to keep the full result off the driver: write it out with the DataFrame writer, then look at a small sample with limit(...) and show().

    Raising driver memory is a reasonable first step when the driver is short of resources in general. When many concurrent streams or jobs crash the driver, check its CPU, memory and disk in the metrics. Adjust driver sizing, then make sure your code isn't running memory-intensive work or UDFs on the driver. If you can't scale the driver up any further, split the work across clusters. A bigger heap does not help when the result to be collected keeps growing with the data.

    Not every driver failure produces an exception. If the driver appears hung, for example with no progress bars or bars stuck at 100%, open the driver row's thread dump in the Executors tab. It shows what each driver thread is doing at that moment.

    Checkpoint 7 of 9· Check yourself

    Twelve streaming queries run on one classic cluster, and its driver keeps crashing. The metrics show the driver's CPU and memory maxed out while the workers are mostly idle. The driver is already the largest node type available. What should you do next?

    Checkpoint 8 of 9· Exam question

    A data engineer runs the following PySpark job on a Databricks all-purpose cluster and the driver fails with java.lang.OutOfMemoryError: Java heap space. The transactions table produces roughly two million distinct region values after the aggregation below, and the driver is provisioned with 8 GB of memory: df = spark.read.parquet("/mnt/sales/transactions") results = df.groupBy("region").agg(sum("amount").alias("total")) rows = results.collect() for row in rows: print(row) Which change most directly resolves the driver OutOfMemoryError while still letting the engineer inspect the aggregated totals?

    Sources910112

    6.Diagnosing an underused cluster

    An underused cluster is one where you pay for executors that sit idle. The metrics show it before any error appears. Each core runs one task at a time, as covered in CPU cores as task slots (parallelism). So underutilization always means there are more free task slots than runnable tasks. It has three common causes, and each leaves a different signature.

    Work stuck on the driver. When the driver is overloaded, it cannot hand out tasks fast enough, so the executors sit idle. The sign is long gaps in the Spark UI jobs timeline, with heavy driver load and lightly loaded workers in the cluster metrics. Non-Spark code, such as a Python loop calling native Python functions, runs entirely on the driver. Too many concurrent streams or threaded jobs, and many attached notebooks, also add to the driver's load.

    Too few tasks. Sort a long job's stages by duration and check the task count of the longest one. A single task means the stage runs with no parallelism: one core works while the rest of the cluster waits. A common example is a window function with no PARTITION BY.

    Uneven tasks. With skew, one or a few tasks run far longer than the rest, and the other cores go idle while those tasks finish. Even when tasks are evenly sized, check which executors ran them. A single receiver can leave one executor doing all the work on a cluster that has several.

    The Metrics tab of the compute gives the numbers behind these patterns. The CPU utilization chart splits CPU time by mode, and idle is time the CPU had nothing to do. Active tasks counts the tasks running at any moment. Compare it with the cluster's total cores to see how many slots are empty. Server load distribution shows each node's CPU over the last minute, and the By node view puts every node on one page so outliers stand out. Spark metrics are not available per node, so check the hardware charts to see whether one node is busy and the others idle. For an overloaded driver, start by doubling the driver size, reduce concurrency, or spread the work across clusters. If the cause is non-Spark code, rewrite that code to use Spark.

    Checkpoint 9 of 9· Match them up

    Each of these clusters is underused: executors sit idle while you pay for them. Match each signature you find in the Spark UI or metrics to the cause it points to.

    Tap a term, then the definition that fits it.

    Sources1213782

    Sources

    (13)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “The direct print and log statements from your notebooks, jobs, and libraries go to the Spark driver logs.”
      ↩︎ What driver logs and executor logs contain
      “Compute event logs, which capture compute lifecycle events like creation, termination, and configuration edits.”
      ↩︎ What driver logs and executor logs contain
      “You can install Datadog agents on compute nodes to send Datadog metrics to your Datadog account.”
      ↩︎ Publishing logs and exporting metrics
      “If you restart a terminated compute, the Spark UI displays information for the restarted compute, not the historical information for the terminated compute.”
      ↩︎ Publishing logs and exporting metrics
      “The direct print and log statements from your notebooks, jobs, and libraries go to the Spark driver logs.”
      ↩︎ Key concept
      “Compute event logs, which capture compute lifecycle events like creation, termination, and configuration edits.”
      ↩︎ Exam trap 1
      “You can also configure a log delivery location for the compute. Both worker and compute logs are delivered to the location you specify.”
      ↩︎ Checkpoint
    2. 2.
      “You can drill into the Driver logs to look at the stack trace of the exception.”
      ↩︎ What driver logs and executor logs contain
      “Executor logs are helpful if you see certain tasks are misbehaving and would like to see the logs for specific tasks.”
      ↩︎ What driver logs and executor logs contain
      “Executor logs are not available for compute with Standard access mode.”
      ↩︎ What driver logs and executor logs contain
      “find the target task that corresponds to the thread dump you want to see, and note its Task ID and Executor ID values”
      ↩︎ Following a failed task to its executor's log
      “Thread dumps are useful in debugging a specific hanging or slow-running task.”
      ↩︎ Following a failed task to its executor's log
      “Thread dumps are also useful for debugging issues where the driver appears to be hanging”
      ↩︎ Diagnosing driver out-of-memory errors and hangs
      “Ensure that the tasks are executed on multiple executors (nodes) in your compute to have enough parallelism while processing.”
      ↩︎ Diagnosing an underused cluster
      “making no progress on queries (for example, Spark progress bars are stuck at 100%). To view the driver's thread dump in the Spark UI:”
      ↩︎ Checkpoint
    3. 3.
      “Here you can get the logs from the failed executors:”
      ↩︎ Following a failed task to its executor's log
      “Autoscaling: In this case it's expected and not an error.”
      ↩︎ Diagnosing executor out-of-memory errors
      “first check the compute's Event log to see whether there's an explanation for the executor failures”
      ↩︎ Prediction
      “To find out why your executors are failing, first check the compute's Event log to see whether there's an explanation for the executor failures.”
      ↩︎ Checkpoint
    4. 4.
      “Logs are delivered every five minutes and archived hourly in your selected destination.”
      ↩︎ Publishing logs and exporting metrics
      “Databricks creates a subfolder in your chosen log path named after the compute's cluster_id.”
      ↩︎ Publishing logs and exporting metrics
    5. 5.
      “Configure Spark metrics to export to external monitoring systems for centralized observability.”
      ↩︎ Publishing logs and exporting metrics
    6. 6.
      “When executors run out of memory, Spark removes them and retries their tasks.”
      ↩︎ Diagnosing executor out-of-memory errors
      “The ratio of memory to cores matters, not the total memory.”
      ↩︎ Diagnosing executor out-of-memory errors
      “These errors are often generic, and other issues might cause them.”
      ↩︎ Exam trap 2
      “The ratio of memory to cores matters, not the total memory.”
      ↩︎ Exam trap 3
    7. 7.
      “If the Max duration exceeds the 75th percentile by 50% or more, the stage might have skew.”
      ↩︎ Diagnosing executor out-of-memory errors
      “append a random bucket suffix to the skewed keys, and then group and aggregate in two stages”
      ↩︎ Diagnosing executor out-of-memory errors
      “Skew happens when one or a few tasks take much longer than the rest.”
      ↩︎ Diagnosing an underused cluster
    8. 8.
      “JVM heap usage: The JVM heap memory usage, averaged across all applicable nodes.”
      ↩︎ Diagnosing executor out-of-memory errors
      “Active tasks: The total number of tasks executing at any given time.”
      ↩︎ Diagnosing an underused cluster
    9. 9.
      “all the data is loaded into the driver's memory”
      ↩︎ Diagnosing driver out-of-memory errors and hangs
      “all the data is loaded into the driver's memory”
      ↩︎ Exam trap 4
    10. 10.
      “toPandas() results in the collection of all records in the DataFrame to the driver program”
      ↩︎ Diagnosing driver out-of-memory errors and hangs
    11. 11.
      “Avoid calling collect() or other expensive DataFrame operations on the driver unless absolutely necessary”
      ↩︎ Diagnosing driver out-of-memory errors and hangs
    12. 12.
      “When the driver is overloaded, it can't hand out work fast enough, so the executors sit idle while you still pay for them.”
      ↩︎ Diagnosing an underused cluster
      “Spread the load over multiple clusters. Move some of the concurrent workloads to separate compute so that each driver coordinates less work.”
      ↩︎ Checkpoint
      “If the driver is busy running non-Spark code, a larger driver doesn't help the idle workers.”
      ↩︎ Prediction

    Spotted a mistake, or was something unclear? Tell us.