apache-spark - Spark - 重新分区()与合并()

标签 apache-spark distributed-computing rdd

根据学习Spark

Keep in mind that repartitioning your data is a fairly expensive operation. Spark also has an optimized version of repartition() called coalesce() that allows avoiding data movement, but only if you are decreasing the number of RDD partitions.

我得到的一个区别是,使用repartition()可以增加/减少分区数量,但使用coalesce()只能减少分区数量.

如果分区分布在多台机器上并且运行coalesce(),它如何避免数据移动?

最佳答案

它避免了完全洗牌。如果知道数量正在减少,那么执行器可以安全地将数据保留在最小数量的分区上,只需将数据从额外的节点移至我们保留的节点上。

所以,事情会是这样的:

Node 1 = 1,2,3
Node 2 = 4,5,6
Node 3 = 7,8,9
Node 4 = 10,11,12

然后合并为 2 个分区:

Node 1 = 1,2,3 + (10,11,12)
Node 3 = 7,8,9 + (4,5,6)

请注意,节点 1 和节点 3 不需要移动其原始数据。

关于apache-spark - Spark - 重新分区()与合并(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31610971/

相关文章:

scala - Spark 2逻辑回归删除阈值

ubuntu - 在Ubuntu上模拟Hadoop集群

python - 将类函数传递给 PySpark RDD

apache-spark - apache Spark - 从 groupByKey 结果的 Iterable 创建 RDD

scala - 如何在 spark-notebook 中从 Accumulo 1.6 创建 Spark RDD?

apache-spark - Spark SQL - 使用 SQL 语句而不是表名通过 JDBC 加载数据

amazon-web-services - Apache Spark Gradient Boosted Tree 训练运行性能缓慢

performance - 如何获取 spark 作业的指标?

python - RPC 协议(protocol)比较

apache-spark - Spark ALS PredictAll 返回空