Why Skew Wastes the Cluster
Concepts covered: Data Skew
The plays join runs on 50 executors with 4 cores each, which gives 200 slots. Each of the stage's 200 tasks takes a slot at minute 0. From there, the cluster's time splits like this:
| minutes | busy slots | idle slots |
|---|---|---|
| 0 to 2 | 200 | 0 |
| 2 to 46 | 1 | 199 |
Count cost in slot-minutes, 1 slot held for 1 minute. On a fixed-size cluster, which this job runs on, the executors stay allocated for all 46 minutes, so the job pays for 200 slots times 46 minutes, or 9,200 slot-minutes. The work actually done is 199 tasks at 2 minutes plus 1 task at 46, which comes to 444 slot-minutes. Spread evenly over 200 slots, those 444 slot-minutes would take roughly 2.2 minutes of wall-clock time.
- 95%
- 21x
An idle slot costs the same per minute as a busy one, so the bill follows the 46 minutes of wall-clock time and ignores how little work filled them. On a shared cluster, the jobs queued behind this one wait out the extra 44 minutes as well.
Why more hardware leaves the stage at 46 minutes
A task runs on a single core and works through its partition's rows in sequence. Task 87's 12,540,000 rows go through 1 core whether the cluster has 200 slots or 2,000. Double the executors to 100 and the stage still has 200 tasks: 200 new slots sit idle from minute 0, task 87 still finishes at minute 46, and the bill doubles. Doubling the cores per executor does the same. Giving executors more memory can keep task 87 from failing, but its rows still pass through a single core at the same pace.
| cluster | slots | stage time | slot-minutes paid |
|---|---|---|---|
| 50 executors x 4 cores | 200 | 46 min | 9,200 |
| 100 executors x 4 cores | 400 | 46 min | 18,400 |
| 50 executors x 8 cores | 400 | 46 min | 18,400 |
| 50 executors x 4 cores, balanced keys | 200 | about 2.2 min | about 444 |
Only the last row changes the stage time, and it changes how rows are distributed across tasks while leaving the hardware alone. Every remedy for skew works on that distribution by stopping the hot key's rows from landing on a single task. The intermediate skew lesson covers how.
- Do
- Count rows per key before shuffling a new table by that key
- Compare the slowest task's input rows with a typical task's before tuning
- Broadcast the small side of a join whenever it fits under the threshold
- Treat placeholder values like 0 and 'unknown' as suspects in every key column
- Avoid
- Add executors to speed up a stage that is waiting on a single task
- Read 199 of 200 tasks done as a stage that is almost finished
- Rerun a skew failure and expect the retry to succeed
- Assume a balanced input read stays balanced after a shuffle
To bring the 46-minute join stage under 10 minutes, a teammate proposes moving the job from 50 executors to 150, each with 4 cores. What happens?
- The stage drops to about 15 minutes, since 3 times the slots cuts every task's time to a third.
- The stage drops below 10 minutes because the new executors take over part of task 87's rows.
- The stage still takes about 46 minutes, and the slot-minutes paid roughly triple to about 27,600.
- The stage still takes about 46 minutes, but the cost stays flat because idle executors are not billed.
About this lesson
This section is part of the Data Skew: 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.