Input, Output, and Shuffle
Concepts covered: Spark UI Diagnosis
The 4 data columns on the Stages tab each measure bytes crossing a boundary. Read together, they say what physically moved: off which disk, over which link, into which machine's memory.
| Column | What it measures | From | To |
|---|---|---|---|
| Input | bytes the stage's tasks read from storage | files or tables in storage | executor memory |
| Output | bytes the stage wrote through a write action | executor memory | files or tables in storage |
| Shuffle Write | bytes the stage's tasks wrote for the next stage | executor memory | shuffle files on that executor's local disk |
| Shuffle Read | bytes the stage's tasks fetched from earlier shuffle files | local disks of every executor, mostly over the network | executor memory |
- views (source, Parquet, /warehouse/views)
- profiles (source, Parquet, /warehouse/profiles)
- Stage 0 (transform, scan, filter, select); parallelism: 960 partitions
- Stage 1 (transform, scan); parallelism: 16 partitions
- Shuffle files (storage, executor local disks)
- Stage 2 (transform, join, aggregate, write); parallelism: 200 partitions
- continue_watching (storage, Parquet, /warehouse/continue_watching)
- views -> Stage 0
- profiles -> Stage 1
- Stage 0 -> Shuffle files
- Stage 1 -> Shuffle files
- Shuffle files -> Stage 2
- Stage 2 -> continue_watching
- Storage: views, profiles
- Map stages: Stage 0, Stage 1
- Shuffle: Shuffle files
- Join stage: Stage 2
- Output: continue_watching
Reading the example's columns
Stage 0 read 118.4 GiB from /warehouse/views and wrote 21.6 GiB of shuffle files. The data shrank twice before that write. The select meant Parquet read only 3 columns, so Input counts those columns' bytes alone. The filter then discarded every view of a minute or less inside the stage, before any row reached a shuffle file.
Stage 1 read 1.9 GiB of profiles and wrote 1.1 GiB. Stage 2's Shuffle Read of 22.7 GiB is the sum of those 2 writes: each of its 200 tasks fetched its partition's slice from the shuffle files on all 8 executors, 1 of them local and 7 across the network. Its 4.3 GiB of Output is the Parquet written to /warehouse/continue_watching.
Patterns the columns reveal
What a stage's filled-in columns say about it
- Input and Shuffle Write on a stage: it read from storage and handed off to a later stage.
- Shuffle Read and Output on a stage: the last stage of a write. Its Shuffle Read should match the Shuffle Write of the stages feeding it.
- Shuffle Read and Shuffle Write on a stage: it received a shuffle and produced another, as a join followed by a groupBy on a different key does.
- No Output on a job that ends in collect(): the result travels to the driver, a trip none of the 4 columns counts.
- A broadcast join leaves the small table out of both Shuffle columns: the driver collects it and sends every executor a copy.
A stage shows no Input and no Output, a Shuffle Read of 14.2 GiB and a Shuffle Write of 13.8 GiB. What did it do?
- It read an earlier stage's shuffle files and wrote new ones for a stage after it.
- It read 14.2 GiB from storage and wrote 13.8 GiB of results to a table.
- It read an earlier stage's shuffle files and sent 13.8 GiB to the driver.
- It cached 14.2 GiB in memory and saved 13.8 GiB of it to local disk.
Watch the bytes move
This animation joins 8 views to 4 profiles with broadcasting turned off. The scan tasks read 12 rows from the 2 tables, the stages' Input. They write all 12 into shuffle partitions, the Shuffle Write, and the join tasks fetch the same 12 back, the Shuffle Read. The 8 joined rows go to the driver through collect(), so Output stays empty. Delete the first line and Spark would broadcast profiles, and the run would have no shuffle at all.
spark.conf.set("spark.sql.autoBroadcastJoinThreshold", -1)
views.join(profiles, "profile_id").collect()| view_id | profile_id | watch_seconds |
|---|---|---|
| 1 | p1 | 340 |
| 2 | p2 | 95 |
| 3 | p1 | 1210 |
| 4 | p3 | 75 |
| 5 | p4 | 640 |
| 6 | p2 | 2280 |
| 7 | p3 | 130 |
| 8 | p4 | 415 |
| profile_id | country |
|---|---|
| p1 | US |
| p2 | BR |
| p3 | IN |
| p4 | DE |
A job joins a 9.6 GiB orders table to a 4 MiB regions table with default settings and ends with collect(). What does the stage that runs the join show?
- Input near 9.6 GiB, a Shuffle Read near 4 MiB for regions, and no Output.
- Input near 9.6 GiB and a Shuffle Write near 9.6 GiB, ready for the join stage.
- Input near 9.6 GiB, with no Shuffle Read, no Shuffle Write and no Output.
- Input near 9.6 GiB and an Output equal to the rows that collect() returned.
The threshold decides from Spark's estimate of a table's size, and the code can decide instead. Wrap the small side in F.broadcast(), as in orders.join(F.broadcast(regions), "region"), and Spark ships regions to every executor whatever its estimate says. The join then runs inside the stage that scans orders, so neither table adds to Shuffle Read or Shuffle Write.
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.