15 / 35 · Distributed Computation
The cost of distributed execution
Estimate the bytes a shuffle carries, locate the slowest task and decide when caching pays for its setup cost.
Four workers have equally sized input files. After a shuffle, one task receives half of the data and finishes long after the others. Balance before the exchange says little about balance after it. The next stage waits for the inputs it actually needs.
Measure the stage that moves data#
Suppose an exchange emits three billion records. At 80 bytes of payload per record, it produces 240 GB in decimal units. The next operator uses only three fields. If projection can keep just those fields and reduce each record to 24 bytes, the same row count produces 72 GB. That comparison excludes headers, compression and temporary files. It isolates the effect of width. A filter before the exchange can independently reduce the row count. (Spark 3.5.8, Tuning Guide)
A balanced destination layout for 240 GB gives four tasks 60 GB each. If a skewed key sends 120 GB to one task and 40 GB to each of the others, the slowest task has twice the balanced payload. Assume the payloads must each be consumed at a ceiling of 1 GB/s per task, with no shared bottleneck. The consumption stage has a lower bound of 120 seconds in the skewed case, compared with 60 seconds in the balanced case. It can take longer. These are bounds on one stage, not predictions for the whole job.
Equal total bytes and unequal tasks
Splitting a large partition can help when the operator can combine independent pieces. A single hot key may require changing how work is split. More partitions alone will not divide that key under ordinary hash partitioning. A second attempt on another worker can help a straggler caused by a slow host, as in MapReduce backup tasks. Both attempts still have the same large input if skew is the cause. (Dean and Ghemawat, 2004, §§3.6 and 5.4)
Account for working memory and reuse#
A sort or a join can keep intermediate state. If its state exceeds the memory budget, the implementation can spill part of it to disk and read it back later. One stage can then write and read temporary bytes in addition to transferring its shuffle blocks. Raising the memory budget for one task reduces the capacity available to other concurrent tasks. Look at records and bytes per partition, shuffle read and write, spill and the distribution of task durations together. (Spark 3.5.8, Tuning Guide)
Caching can help when later actions reuse the same expensive intermediate result. Suppose every uncached run takes 60 seconds. Materializing a cache costs 90 seconds up front, and each run after materialization takes 25 seconds. For runs, caching pays when , so the first whole number that helps is . Three runs take 165 seconds with the cache and 180 without. This model assumes the cached data stays available and does not slow other work. Eviction, recomputation and competing memory change the comparison. (Zaharia et al., 2012, §§1–2)
Next#
A fast stage can still compute a report from an inconsistent copy of the data. DWH, data lake and lakehouse follows the path from operational sources to an analytical result and identifies where the report’s meaning is defined.
References#
- Apache Software Foundation. Tuning Guide. Spark 3.5.8 documentation on serialization, memory and shuffle working sets.
- Jeffrey Dean and Sanjay Ghemawat. MapReduce: Simplified Data Processing on Large Clusters. OSDI, 2004, §§3.6 and 5.4 on backup tasks and stragglers.
- Matei Zaharia et al. Resilient Distributed Datasets. NSDI, 2012, §§1–2 on data reuse and persistence.