PySpark / PerformanceFig_12 · Lesson 12 / 14
Fig_12 · Debugging · v1.0Spark UI + EXPLAIN

Spark UI Debugging

PLAN NODES · STAGE METRICS · ROOT CAUSE

A slow Spark job is not a mystery. Read the physical plan to see the shape of the work, then use the Spark UI to measure where that work became expensive.

Spark 3.2+DBR LTSverified Jun 2026

01 · What it is

Plan first, metrics second

df.explain(mode="formatted") tells you the operators Spark planned. The Spark UI tells you how those operators behaved at runtime: shuffle, spill, skew, GC, retries, cache, and executor health.

The one rule to rememberExplain shows the shape; Spark UI shows the cost. Use both before changing code, memory, or cluster size.
Plan clue

Exchange, join strategy, scan filters, cache scans, and AQE nodes.

Runtime clue

Task spread, shuffle read/write, spill, GC time, failed tasks, executor health.

Healthy pattern

The plan changed and the matching UI metric improved after your fix.

02 · How it works

The diagnostic loop

analogyThe plan is a blueprint; the UI is the construction bill. A big room on the blueprint is not bad by itself, but the bill tells you which room consumed all the time and material.

query.explain(mode="formatted")
# Look for: Exchange, BroadcastHashJoin, SortMergeJoin, HashAggregate,
# InMemoryTableScan, AdaptiveSparkPlan, AQEShuffleRead.

spark.sparkContext.setJobGroup("L12: slow join", "L12: slow join", True)
query.write.format("noop").mode("overwrite").save()
# VERIFY: Spark UI -> SQL tab for the DAG; Stages tab for task metrics.
TabUse it forSignal
SQL/DataFrameConnect plan nodes to the runtime DAGExchange, BroadcastExchange, AQEShuffleRead
StagesFind the expensive stageMax vs Median task time, shuffle, spill, GC
ExecutorsSeparate cluster issue from one bad nodeFailed tasks, task time, GC, driver row
StorageConfirm cache actually materializedCached partitions, memory, disk, eviction
EnvironmentConfirm configs really appliedAQE, shuffle partitions, memory flags

03 · Interactive diagnosis

Pick the signal, then choose the next check

Spark UI signal mapper

Choose the symptom you see in the UI and watch the likely root cause and next evidence update.

Shuffle-heavy plan
likely cause
SQL DAG
next check
Look for Exchange nodes and high Shuffle Read/Write. Try pruning, broadcast, bucketing, or AQE before sizing memory.

04 · Runbook

If you see X, check Y

SymptomCheck firstLikely fix
Slow joinJoin node + Exchange countBroadcast, AQE, bucketing
One stragglerMax vs Median + shuffle sizeAQE skew split or salting
Slow but succeedsSpill memory/diskSmaller partitions or memory
High GCGC Time and executor logsLess object churn, cache, G1/off-heap
Driver OOMDriver row and action typeAvoid collect, reduce metadata

05 · Uses and gotchas

Use evidence, not guesses