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.

ColumnWhat it measuresFromTo
Inputbytes the stage's tasks read from storagefiles or tables in storageexecutor memory
Outputbytes the stage wrote through a write actionexecutor memoryfiles or tables in storage
Shuffle Writebytes the stage's tasks wrote for the next stageexecutor memoryshuffle files on that executor's local disk
Shuffle Readbytes the stage's tasks fetched from earlier shuffle fileslocal disks of every executor, mostly over the networkexecutor memory
Input is counted on the arrows out of views (118.4 GiB) and profiles (1.9 GiB), Shuffle Write on the arrows into the shuffle files (21.6 GiB and 1.1 GiB), Shuffle Read on the arrow out of them (22.7 GiB), and Output on the final write (4.3 GiB).
  • 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

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?

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()
views
view_idprofile_idwatch_seconds
1p1340
2p295
3p11210
4p375
5p4640
6p22280
7p3130
8p4415
profiles
profile_idcountry
p1US
p2BR
p3IN
p4DE

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?

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.