Apache Spark 是如何实现 shuffle 阶段的?
How does Apache Spark implement the shuffle phase?
我想知道 Apache Spark 是如何实现 shuffle 阶段的。它使用与 MapReduce 相同的技术吗?例如:
rddB = rddA.map1.groupByKey();
rddX = rddB.map2.map3.saveAsTextFile();
rddY = rddB.map4.map5.saveAsTextFile();
是否执行map1然后key分区,中间数据保存到磁盘(内存)?
然后读取中间文件 2 次,一次用于 map2 map3 分支,第二次用于 map4 map5 即使我们没有在 rddB 上进行隐式缓存,也没有再次计算 rddB ?
不,Spark 的行为方式略有不同。首先,当遇到你写的行时,Spark 并不实际执行操作,而是创建一个 DAG 来表示要执行的操作以获得给定的 RDD 或结果。事实上,Spark 的操作分为两大类:转换和动作;它仅在遇到操作时执行它们。
此外,Spark 仅在您告诉它这样做时才存储中间结果,即当您在 RDD 上调用 persist
或 cache
时。如果您不这样做,它将执行所有操作以获得给定结果直到 DAG 的根(即从文件中读取它们)。
前面的说法不是真的。事实上,手册上说 here
Spark also automatically persists some intermediate data in shuffle
operations (e.g. reduceByKey), even without users calling persist.
This is done to avoid recomputing the entire input if a node fails
during the shuffle. We still recommend users call persist on the
resulting RDD if they plan to reuse it.
我想知道 Apache Spark 是如何实现 shuffle 阶段的。它使用与 MapReduce 相同的技术吗?例如:
rddB = rddA.map1.groupByKey();
rddX = rddB.map2.map3.saveAsTextFile();
rddY = rddB.map4.map5.saveAsTextFile();
是否执行map1然后key分区,中间数据保存到磁盘(内存)?
然后读取中间文件 2 次,一次用于 map2 map3 分支,第二次用于 map4 map5 即使我们没有在 rddB 上进行隐式缓存,也没有再次计算 rddB ?
不,Spark 的行为方式略有不同。首先,当遇到你写的行时,Spark 并不实际执行操作,而是创建一个 DAG 来表示要执行的操作以获得给定的 RDD 或结果。事实上,Spark 的操作分为两大类:转换和动作;它仅在遇到操作时执行它们。
此外,Spark 仅在您告诉它这样做时才存储中间结果,即当您在 RDD 上调用 persist
或 cache
时。如果您不这样做,它将执行所有操作以获得给定结果直到 DAG 的根(即从文件中读取它们)。
前面的说法不是真的。事实上,手册上说 here
Spark also automatically persists some intermediate data in shuffle operations (e.g. reduceByKey), even without users calling persist. This is done to avoid recomputing the entire input if a node fails during the shuffle. We still recommend users call persist on the resulting RDD if they plan to reuse it.