Github user ilganeli commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5074#discussion_r27054643
  
    --- Diff: docs/programming-guide.md ---
    @@ -1086,6 +1086,62 @@ for details.
     </tr>
     </table>
     
    +### Shuffle operations
    +
    +Certain operations within Spark trigger an event known as the shuffle. The 
shuffle is Spark's 
    +mechanism for re-distributing data so that is grouped differently across 
partitions. This typically 
    +involves re-arranging and copying data across executors and machines, 
making shuffle a complex and 
    +costly operation.
    +
    +#### Background
    +
    +To understand what happens during the shuffle we can consider the example 
of the 
    +[`reduceByKey`](#ReduceByLink) operation. The `reduceByKey` operation 
generates a new RDD where all 
    +values for a single key are combined into a tuple - the key and the result 
of executing a reduce 
    +function against all values associated with that key. The challenge is 
that not all values for a 
    +single key necessarily reside on the same partition, or even the same 
machine, but they must be 
    +co-located to present a single array per key.
    +
    +In Spark, data is generally not distributed across partitions to be in the 
necessary place for a 
    +specific operation. During computations, a single task will operate on a 
single partition - thus, to
    +organize all the data for a single `reduceByKey` reduce task to execute, 
Spark needs to perform an 
    +all-to-all operation. It must read from all partitions to find all the 
values for all keys, and then
    +organize those such that all values for any key lie within the same 
partition - this is called the 
    +**shuffle**.
    +
    +Although the set of elements in each partition of newly shuffled data will 
be deterministic, the 
    +ordering of these elements is not. If one desires predictably ordered data 
following shuffle 
    +operations, [`mapPartitions`](#MapPartLink) can be used to sort each 
partition or `sortBy` can be
    +used to perform a global sort. A similar operation, 
    +[`repartitionAndSortWithinPartitions`](#Repartition2Link`) coupled with 
`mapPartitions`, 
    +may be used to enact a Hadoop style shuffle.
    +
    +Operations which can cause a shuffle include **repartition** operations 
like 
    +[`repartition`](#RepartitionLink), and [`coalesce`](#CoalesceLink), 
**'byKey** operations
    +(except for counting) like [`groupByKey`](#GroupByLink) and 
[`reduceByKey`](#ReduceByLink), and 
    +**join** operations like [`cogroup`](#CogroupLink) and [`join`](#JoinLink).
    +
    +#### Performance Impact
    +**Shuffle** is an expensive operation since it involves disk I/O, data 
serialization, and 
    +network I/O. To organize data for the shuffle, Spark generates two sets of 
tasks - map tasks to 
    --- End diff --
    
    Sandy - could you elaborate on that first issue? Is this due to the fact 
that subsequent shuffles will get coalesced via the DAGScheduler? Is that worth 
mentioning here and if so, what would be the best way to phrase it?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to