Let me help to clarify about shuffle in depth and how Spark uses shuffle managers. I report some very helpful resources:
https://trongkhoanguyenblog.wordpress.com/
https://0x0fff.com/spark-architecture-shuffle/
https://github.com/JerryLead/SparkInternals/blob/master/markdown/english/4-shuffleDetails.md
Reading them, I understood there are different shuffle managers. I want to focus about two of them: hash manager
and sort manager
(which is the default manager).
For expose my question, I want to start from a very common transformation:
val rdd = reduceByKey(_ + _)
This transformation causes map-side aggregation and then shuffle for bringing all the same keys into the same partition.
My questions are:
Is Map-Side aggregation implemented using internally a mapPartition transformation and thus aggregating all the same keys using the combiner function or is it implemented with a
AppendOnlyMap
orExternalAppendOnlyMap
?If
AppendOnlyMap
orExternalAppendOnlyMap
maps are used for aggregating, are they used also for reduce side aggregation that happens into theResultTask
?What exaclty the purpose about these two kind of maps (
AppendOnlyMap
orExternalAppendOnlyMap
)?Are
AppendOnlyMap
orExternalAppendOnlyMap
used from all shuffle managers or just from the sortManager?I read that after
AppendOnlyMap
orExternalAppendOnlyMap
are full, are spilled into a file, how exactly does this steps happen?Using the Sort shuffle manager, we use an appendOnlyMap for aggregating and combine partition records, right? Then when execution memory is fill up, we start sorting map, spilling it to disk and then clean up the map, my question is : what is the difference between spill to disk and shuffle write? They consist basically in creating file on local file system, but they are treat differently, Shuffle write records, are not put into the appendOnlyMap.
Can you explain in depth what happen when reduceByKey being executed, explaining me all the steps involved for to accomplish that? Like for example all the steps for map side aggregation, shuffling and so on.