Measure Before You Tune

The on-call proposal is to double the executors from 8 to 16. It is a guess about the cause, and a test run either backs it with numbers or rules it out. Skipping the test means paying for 16 executors every night for a gain nobody measured.

Write down the baseline

Before changing anything, copy the numbers that describe the run into a note. A finished run's pages last only as long as its event log is kept, and the comparison needs both runs side by side. The median and max task come from the stage page's Summary Metrics table, which the next section reads in full.

NumberWhere it livesBaseline
Total runtimeSQL / DataFrame tab, query Duration59 min
Slowest stageStages tab, sorted by Durationstage 2, 52 min
Stage 2 median taskstage page, Summary Metrics40 s
Stage 2 max taskstage page, Summary Metrics50 min
Stage 2 Shuffle ReadStages tab22.7 GiB
Executors and coresEnvironment tab8 x 4
import time

spark.sparkContext.setJobDescription("continue watching: 16 executors")
start = time.time()
result.write.mode("overwrite").parquet("/scratch/continue_watching_test")
print(f"total runtime: {time.time() - start:.0f} s")

The printed figure includes planning and file commit, so it should land within a few seconds of the query's Duration in the UI. Writing to a scratch path keeps the experiment away from the table other teams read.

One change, same input, more than one run

Do
  • Rerun on the same input date, so both runs read the same 118.4 GiB
  • Change a single setting per run, so the difference has a single cause
  • Run the baseline twice to learn how much runs vary on their own
  • Compare the stage that owned the runtime as well as the total
  • Confirm the new value in the Environment tab before reading results
Avoid
  • Compare a Monday run with a Friday run that read 30% more data
  • Ship 3 tweaks together and credit the one you liked best
  • Trust a 2-minute gain when 2 baseline runs differ by 2 minutes
  • Judge a change by the total when the slow stage did not move
  • Assume a setting applied because the code set it

The doubling experiment

Write the prediction down before the run. If the cluster were too small, every stage should run close to twice as fast once slots double from 32 to 64.

Stage 0 nearly halved, as predicted: 960 tasks of steady work spread over twice the slots. Stage 2 dropped by 1 minute. Its median and max task did not change, because a task runs on 1 core however many cores the cluster has, and stage 2 cannot finish before its 50-minute task does. A second baseline run on the same input took 61 minutes, so runs vary by about 2 minutes on their own, and a 4-minute gain sits barely outside that noise.

The measurement rejects the change and still tells you something: a stage whose slowest task stays fixed while slots double is waiting on that task, and the stage page can say which task and why.

A teammate reports that adding cache() to a shared lookup cut their job from 30 to 24 minutes. The 30-minute run read Tuesday's input; the 24-minute run read Wednesday's, which was 20% smaller. What does the comparison show?

About this lesson

This section is part of the The Spark UI: Beginner lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.