Spark UI, Logs, and Out of Memory Errors
Databricks Spark Developer Associate · Lesson 14 of 18 · 1:54:19
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Databricks Certified Associate Developer for Apache Spark exam. In this lesson: the Spark UI and the History Server, driver and executor logs, log levels, out of memory errors on the driver and on executors, and underused clusters. Includes three original practice questions.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
A crash at three in the morning
Coralpeak's job fails at three in the morning with an out of memory error, and nobody knows whether the driver or an executor ran out. Another job finishes, but uses only a small part of the cluster it runs on. This lesson covers the Spark UI, driver and executor logs, out of memory errors, and underused clusters.
The Spark UI
The driver serves the Spark UI, on port four zero four zero by default, for as long as the application runs. The Jobs and Stages tabs show each job, its stages, and the metrics of their tasks: duration, garbage collection time, shuffle read and write, and spill to disk. The Executors tab lists each executor with its memory, cores, active and failed tasks, garbage collection time, and links to its standard output and standard error logs. The SQL tab shows the plan of each query, with the rows and the time of each operator, and the Storage tab lists the cached data. After the application ends, event logs, turned on with spark.eventLog.enabled, let the History Server show the same pages.
Driver and executor logs
The driver log holds what runs on the driver: your main program, the planning of queries, and any error that stops the application. Executor logs hold what runs inside tasks, so a print in a UDF, or the error behind a failed task, appears in the log of the executor that ran it, not in the driver log. You customize logging with a log4j2 properties file, or change the log level of a running application with setLogLevel on the SparkContext, for example to WARN, to cut the noise. On Databricks, the compute page shows the driver logs, with standard output, standard error, and log4j output, the Spark UI links to the logs of each executor, and logs can also be delivered to a storage location.
Out of memory errors
The first question is where the error happened: in the driver log, or in the log of an executor, often with a lost executor in the Executors tab. The driver runs out of memory when too much data comes back to it, through collect or toPandas on a large result, or when it builds a large broadcast table. spark.driver.maxResultSize caps the total size of the results sent to the driver, and stops the job with a clear error, instead of a crash. An executor runs out of memory when a task holds too much data at once: partitions that are too large, a skewed key, or a huge group in a single aggregation. The fixes are more and smaller partitions, fixing the skew, more executor memory, and keeping large results off the driver.
Underused clusters
A cluster is underused when most of its cores sit idle while a job runs, which wastes both money and time. In the Executors tab, idle executors show few or no active tasks, and in the Stages tab, a stage runs fewer tasks than there are cores. Common causes are too few partitions, a coalesce to a single partition, a few skewed tasks that run long after the others, or work done on the driver, such as a Python loop over collected rows. The fixes follow: repartition to two or three tasks per core, remove needless coalesce calls, fix the skew, and keep the work in Spark, rather than on the driver.
Recap
Let's recap. The Spark UI shows jobs, stages with task metrics, executors, SQL plans, and storage, and the History Server replays it from event logs. The driver log holds your main program and its errors, while the output and errors of tasks, including a print in a UDF, go to the executor logs. setLogLevel, or a log4j2 properties file, controls how much gets logged. A driver out of memory error comes from large results or broadcasts, while an executor one comes from large partitions, skew, or huge groups. And an underused cluster needs more partitions, no needless coalesce, and the work kept in Spark.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
A developer adds print statements inside a UDF, but nothing appears in the driver log. Where is the output?
- In the SQL tab of the Spark UI
- Nowhere: print is ignored in a UDF
- In the logs of the executors that ran the tasks
- In the History Server, once the job ends
Show the answer
In the logs of the executors that ran the tasks
A UDF runs inside tasks on the executors, so its output lands in their logs. “In the SQL tab of the Spark UI” is wrong, since the SQL tab shows plans and metrics, not output. “Nowhere: print is ignored in a UDF” is wrong, since the output is written, just on the executors. And “In the History Server, once the job ends” is wrong, since the History Server replays the pages of the UI, not the output of print.
A job fails with an out of memory error in the driver log, right after toPandas() on 50 million rows. What fixes it?
- Aggregate or filter first, so a small result reaches the driver
- Add more executors to the cluster
- Increase the number of shuffle partitions
- Cache the table before the call
Show the answer
Aggregate or filter first, so a small result reaches the driver
ToPandas brings the whole result to the driver, so the result must shrink before the call. “Add more executors to the cluster” would add executor memory, while the driver is the one that runs out. “Increase the number of shuffle partitions” only changes the shuffles, not the size of the result. And “Cache the table before the call” would keep the data on the executors, and the driver would still receive all of it.
A cluster with 64 cores shows a single active task for most of a job, and the code calls coalesce(1) before the write. What should the developer do?
- Add executors to the cluster
- Raise the driver memory
- Turn off adaptive query execution
- Write with more partitions, or repartition before writing
Show the answer
Write with more partitions, or repartition before writing
A coalesce to one partition can run the whole stage as one task, so writing with more partitions puts the other cores to work. “Add executors to the cluster” would only add more idle cores. “Raise the driver memory” would not change the number of tasks. And “Turn off adaptive query execution” would not add any tasks either.