Let’s Get Certified
Module 09 / 13 · Troubleshooting and tuning

Diagnose Spark stages before tuning

Read the physical plan, stage metrics and logs to distinguish skew, underutilization and memory pressure.

Diagnose Spark stages before tuning

Work through the decision

A shuffle stage finishes 199 tasks in seconds. One task takes eight minutes, spills heavily and processes half the partitioned data. Should the team double the cluster or collapse the final output to one partition?

Check your reasoning

Compare task input and shuffle-read distributions. One oversized reduce partition suggests a hot key or uneven partitioning. Inspect key frequency, upstream grain and the join plan. Consider an eligible broadcast join, selective hot-key handling or adaptive skew optimization. Additional executors may sit idle while the one large task continues.

Watch the source lesson at 1:48:51

Compare the choices

Skew diagnosis
Compare partition size and task duration distributions, then examine key frequencies and join cardinality. Averages can conceal a straggler.
Repartition
Redistribute data to a new partition count or key, introducing a shuffle. Evaluate the downstream gain against the cost of the exchange.
Coalesce
Reduce partition count while avoiding a full shuffle where possible. Measure skew and avoid a single bottleneck when reducing too aggressively.
Adaptive Query Execution
Use runtime statistics to adjust eligible physical strategies, such as post-shuffle partition coalescing or skewed join handling. Inspect the final plan.
Driver and executor logs
Identify which process failed and correlate its error with Spark UI stages, memory, spills and code actions. Configure log collection for later review.

Test the decision

Repartition performs a redistribution and can improve balance or increase parallelism. Coalesce can reduce partitions with less data movement but can concentrate work. Inspect the final adaptive plan and actual stage metrics. A driver out-of-memory during collect has a different remedy from an executor spilling an oversized partition.

Practice the guide skills

  1. Compare task input sizes before deciding to repartition, coalesce or address a skewed join key. Watch 1:48:51 · Continue at 1:50:23 · Continue at 1:51:00
  2. Compare an initial plan with its adaptive final plan and identify a runtime change supported by statistics. Watch 1:52:16
  3. Use the stage timeline, task spill and executor or driver logs to locate the constrained process. Watch 1:54:49 · Continue at 1:56:35 · Continue at 1:57:00 · Continue at 1:58:30

Official objectives for this lesson

Related lesson · Troubleshooting and optimization

Knowledge check

Diagnose Spark stages before tuning quiz

Answer 3 questions. Check each answer for an explanation.

Worked example · Diagnose Spark stages before tuning