Apache Spark中的混洗与非混洗合并 [英] Shuffled vs non-shuffled coalesce in Apache Spark

查看:81
本文介绍了Apache Spark中的混洗与非混洗合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将RDD写入文件之前立即执行以下转换时,它们之间有什么区别?

What is the difference between the following transformations when they are executed right before writing RDD to a file?

  1. coalesce(1,shuffle = true)
  2. coalesce(1,shuffle = false)

代码示例:

val input = sc.textFile(inputFile)
val filtered = input.filter(doSomeFiltering)
val mapped = filtered.map(doSomeMapping)

mapped.coalesce(1, shuffle = true).saveAsTextFile(outputFile)
vs
mapped.coalesce(1, shuffle = false).saveAsTextFile(outputFile)

它与collect()相比如何?我完全知道,Spark保存方法将以HDFS样式的结构存储它,但是我对collect()和改组/未改组/非改组的coalesce()的数据分区方面更感兴趣.

And how does it compare with collect()? I'm fully aware that Spark save methods will store it with HDFS-style structure, however I'm more interested in data partitioning aspects of collect() and shuffled/non-shuffled coalesce().

推荐答案

shuffle = true和shuffle = false在结果输出中不会有任何实际差异,因为它们都将下降到单个分区.但是,将其设置为true时,将进行无用的随机播放.使用shuffle = true时,输出均匀地分布在各个分区之间(如果需要,您还可以增加分区的数量),但是由于目标是1个分区,因此无论如何,所有结果都将集中在一个分区中.

shuffle=true and shuffle=false aren't going to have any practical differences in the resulting output since they are both going down to a single partition. However, when you set it to true you will do a shuffle which isn't of any use. With shuffle=true the output is evenly distributed amongst the partitions (and your also able to increase the # of partitions if you wanted), but since your target is 1 partition, everything is ending up in one partition regardless.

至于与collect()的比较,区别在于所有数据都存储在单个执行程序上,而不是存储在驱动程序上.

As for comparision with collect(), the difference is all of the data is stored on a single executor rather than on the driver.

这篇关于Apache Spark中的混洗与非混洗合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆