Reading the Spark UI: Stages, Tasks, Spill and Skew
A practical route through the Spark UI: map a slow query to its stage, read the summary metrics, and recognise skew, spill, tiny files and GC pressure.
TL;DR
- An action starts a job. Spark cuts the job into stages at every shuffle. Each stage runs one task per partition. Time goes wherever the slowest stage's slowest tasks are.
- Start in the SQL / DataFrame tab to find the slow query and its final plan, then jump to the stage that dominates its time.
- In the stage, read Summary Metrics: compare Max to Median. Big gap = skew. Non-zero Spill = not enough memory per task. High GC Time = memory pressure.
- The Event Timeline tells you whether the cluster was busy or waiting on one task.
- Serverless compute and SQL warehouses have no Spark UI. The query profile shows the same operators and metrics.
The problem
A NorthBridge engineer pinged the team channel: "The weekly margin job went from 18 to 52 minutes. Should I double the cluster?"
Doubling the cluster would have doubled the bill and fixed nothing. Ten minutes in the Spark UI showed one stage where a single task read 9.8 GB and spilled 31 GB to memory and 8.7 GB to disk, while the median task read 60 MB. A new supplier code 'MISC' had become a hot key.
The Spark UI answers "where did the time go?" precisely. Most people open it, see a wall of tables, and close it again. This is the route through it.
Key concepts
| Concept | What it means | Why it matters here |
|---|---|---|
| Job | The work triggered by one action (write, count, collect, display) |
One query can trigger several jobs |
| Stage | A set of tasks that run without a shuffle in between | Stage boundaries = shuffles = expensive |
| Task | One unit of work on one partition, on one core | The thing that's slow or fast |
| Shuffle read / write | Bytes moved between stages | The size of the expensive bit |
| Spill | Data written out because it didn't fit in execution memory | Slow; a sign of oversized partitions or tight memory |
| GC time | Time the JVM spent collecting garbage | High = memory pressure |
Compare Max with Median, not with Min.
Step 0 — Open the right UI
| Where the code runs | How to get there |
|---|---|
| Databricks classic compute, notebook | Expand the Spark Jobs link under the cell, or Compute → cluster → Spark UI |
| Databricks job run | Job run page → task → Spark UI (cluster metrics and logs are there too) |
| Databricks serverless / SQL warehouse | Query profile from the query history or the cell output; no Spark UI |
| Open-source Spark | http://<driver>:4040 while running; Spark History Server afterwards |
For finished jobs on open-source Spark you need event logs (spark.eventLog.enabled=true) and a History Server. On Databricks, the Spark UI of a terminated cluster stays available for a while; for long-term analysis, set up cluster log delivery.
Step 1 — SQL / DataFrame tab: find the slow query
This tab lists every query with its duration and the job IDs it ran. Click the slowest one. You get the plan graph with metrics on every node:
| Node | Metrics to read |
|---|---|
Scan parquet / PhotonScan / Delta scan |
files read, files pruned, size of files read, rows output |
Filter |
rows output (compare with the scan: is the filter selective?) |
Exchange |
data size, shuffle records written: how much you shuffled |
AQEShuffleRead |
number of partitions, coalesced partitions, skewed partitions |
SortMergeJoin / BroadcastHashJoin / ShuffledHashJoin |
rows output; isSkewJoin=true when AQE split skew |
Sort / HashAggregate |
spill size, peak memory |
Two things to check straight away:
- Is this the final plan? The header says
AdaptiveSparkPlan isFinalPlan=trueonce AQE is done. That's the plan that actually ran. See Why AQE Coalesces Shuffle Partitions. - Rows in vs rows out. A scan reading 2 billion rows into a filter that outputs 4 million means the filter isn't being pushed down to the files. Check data skipping and clustering.
Each node also shows which stage it belongs to. Note the stage with the biggest Exchange or the most time and go there.
Step 2 — Jobs tab: the shape of the run
The Jobs tab is a quick sanity check:
- How many jobs? One
writeusually runs a few. Dozens for one notebook cell often means a loop calling actions (count()inside afor), orinferSchemareading the data twice. - Gaps between jobs. If jobs end at 10:02 and the next starts at 10:09, the time went on the driver: query planning over millions of files, Python code, or
collect(). - Skipped stages are good: Spark reused shuffle output it already had.
Step 3 — Stage page: Summary Metrics
This is the most useful table in the UI. For the slow stage of the margin job:
| Metric | Min | 25th | Median | 75th | Max |
|---|---|---|---|---|---|
| Duration | 41 s | 52 s | 58 s | 1.1 min | 24 min |
| GC Time | 0.4 s | 0.6 s | 0.8 s | 1 s | 3.2 min |
| Shuffle Read Size / Records | 48 MB | 55 MB | 60 MB | 63 MB | 9.8 GB |
| Spill (Memory) | 0 | 0 | 0 | 0 | 31 GB |
| Spill (Disk) | 0 | 0 | 0 | 0 | 8.7 GB |
How to read it:
- Duration: max vs median. 24 min vs 58 s. One task is 25× slower. The stage takes 24 minutes.
- Shuffle read: max vs median. 9.8 GB vs 60 MB. The slow task has more data, not slower code. That's skew.
- Spill. Only the max task spills.
Spill (Memory)is the size of the data in its deserialized in-memory form when it was spilled;Spill (Disk)is the same data serialized and compressed on disk. That's why memory spill is always the bigger number. Any non-zero value means a task couldn't hold its working set in execution memory. - GC. 3.2 minutes of GC on the big task is a side effect of the same oversized partition.
If max and median were close but everything was slow, the problem would be different: too few partitions, too little memory per core, or expensive per-row work.
Below the summary, Aggregated Metrics by Executor shows whether one executor did badly (a bad node, or data locality), and the Tasks table lets you sort by duration or shuffle read to find the exact task and its executor.
Step 4 — The Event Timeline
Expand Event Timeline on the stage page. Each bar is a task, coloured by phase:
| Colour (phase) | Large means |
|---|---|
| Scheduler delay | The driver is overloaded or there are too many tiny tasks |
| Task deserialization | Large closures (big Python objects captured in a UDF) |
| Shuffle read time | Network or remote disk is slow, or the partition is huge |
| Executor computing time | The actual work. Normal to dominate |
| Shuffle write time | Lots of shuffle output; check if you need that shuffle |
| Result serialization / getting result | Big results going back to the driver (collect) |
The pattern matters more than the colours. A wall of short bars that ends in one long bar is skew. A staircase of small bars with gaps between them is too many tiny tasks. Bars that are all long and all green is a heavy, balanced stage that might simply need more cores or less work.
Step 5 — Executors tab: the cluster's health
| Column | What to look for |
|---|---|
| Task Time (GC Time) | GC shown in red when it's above ~10% of task time |
| Failed Tasks | Any, with the reason in the stage's failed task list |
| Storage Memory | How much is used by cached data |
| Shuffle Read / Write | Even across executors, or one doing everything |
Failed tasks with ExecutorLostFailure or exit code 137 mean an executor was killed, usually for memory. See Spark Memory Management.
The Storage tab shows cached DataFrames and what fraction is actually in memory. If a cache is 30% in memory, it's mostly being recomputed or read from disk. The Environment tab confirms which configs actually applied, which settles "did my spark.conf.set take effect?" arguments.
Diagnosis table
| What you see | Likely cause | Where to fix it |
|---|---|---|
| Max duration and shuffle read ≫ median | Skew on a join, group or window key | Data Skew in Spark |
| Spill on most tasks | Partitions too big for memory per task | More partitions, smaller advisory size, memory-optimized nodes |
| Spill only on max task | Skew | Fix the skew, not the memory |
| Thousands of tasks taking milliseconds | Too many partitions or tiny input files | AQE coalescing, compaction |
| One task in a stage that reads a lot | coalesce(1), window without partitionBy, global sort |
repartition vs coalesce |
| High GC everywhere | Too little heap per core, huge rows, caching too much | Spark Memory Management |
| Big gaps between jobs | Driver work: planning, Python, collect() |
Reduce file count, move logic into Spark |
| Huge shuffle write for a join with a small table | Broadcast didn't happen | Join strategies |
| Same stage repeated in several jobs | Recomputation; DataFrame used by several actions | Cache, or restructure to one action |
The result
The margin job's slow stage was a sort-merge join on supplier_code. The team mapped 'MISC' to a real supplier group in silver (the code had been a temporary workaround in the source system), and AQE's skew handling took care of the rest. Stage time went from 24 minutes to 1.3 minutes; the job ran in 17 minutes on the same cluster. No resize.
From production: gotchas and lessons
-
Symptom: The notebook cell took 12 minutes but the Spark jobs only added up to 3. Cause: Driver-side time: a Python loop building 400 DataFrames and unioning them, plus planning over 1.2 million files. Fix: Build one DataFrame with a single read and a filter; compact the table. The gaps in the Jobs tab were the clue.
-
Symptom: "Spill (Memory) 31 GB" on an executor with 16 GB of heap caused confusion. Cause: The metric is cumulative over the task's spills and measured in deserialized size. Fix: Read it as "this task spilled a lot", not as a memory usage figure.
-
Symptom: The plan in the notebook's
explain()showed a sort-merge join; the job had actually run a broadcast join. Cause:explain()before running shows the initial plan; AQE switched the strategy at runtime. Fix: Always read the final plan in the SQL tab. -
Symptom: A stage with 1 task processed 300 GB. Cause:
coalesce(1)before writing a "single file" extract was pulled into the upstream stage. Fix:repartition(1)(or better, don't write one file of 300 GB).
Performance and cost notes
The Spark UI turns "make it faster" into a specific question: which stage, which tasks, which bytes. That's the difference between a config change and a cluster resize. In practice, most slow jobs NorthBridge investigated were one of four things: skew, a missing broadcast, tiny files, or recomputation. All four are visible in under ten minutes once you know where to look.
When not to use this
For serverless notebooks, jobs and SQL warehouses, use the query profile instead; the concepts (operators, rows, spill, time per operator) carry over directly. For continuous monitoring across hundreds of jobs, the Spark UI doesn't scale; use system tables and job run history to find which jobs to open in the first place.
Checklist
- Found the slow query in SQL / DataFrame and read its final plan
- Identified the stage that dominates the time
- Compared max and median for duration and shuffle read
- Checked spill and GC
- Looked at the event timeline shape
- Checked executors for failures and the environment for config
- Wrote down the numbers before changing anything
Practice
- Try: PySpark Interview Questions: 50 Coding and Scenario Problems
- Build it yourself: run a join with a deliberate hot key, then a
coalesce(1)write, then acount()in a loop. Find each problem in the UI without looking at the code.
Further reading
Keep going
Data Skew in Spark: Detect It and Fix It
Find the hot key behind a stage that never finishes, then fix it with AQE skew joins, key cleanup, hot-key isolation or salting, in that order.
Spark Memory Management: Executors, Spills and OOM Fixes
How executor and driver memory is actually divided, why tasks spill, and how to diagnose and fix each kind of out-of-memory error instead of just adding RAM.
Why AQE Coalesces Shuffle Partitions (and When It Can't Help)
How Adaptive Query Execution merges small shuffle partitions at runtime, the settings that control it, and the cases where you still have to tune.
One practical note a week
Get new articles, problems and guides in your inbox.
Thanks! You're on the list. (Local demo — no email provider is wired up yet.)