我利用 Spark
的 JDBC
功能,如下所示:
- 将
MySQL
表读取到DataFrame
- 改造它们
- 合并它们
- 将它们写入
HDFS
在 DataFrame
的整个生命周期中,不会对其执行任何操作
。它曾经按预期工作,但最近我遇到了问题。由于 Spark
的惰性求值,合并
导致读取操作的并行性减少。
因此,如果我使用 DataFrameReader.jdbc(..numPartitions..)
和 numPartitions=42
读取 DataFrame
,然后 在写入之前将其合并
到6个分区
,然后它读取DataFrame
,并发仅为6(仅触发6个查询)到MySQL
)。我想重复一下,之前它使用 42 的并行度进行读取,然后执行合并
。
我最近在 EMR 5.13
上迁移到 Spark 2.3.0
,这可能与此相关吗?有解决办法吗?
最佳答案
Thanks to Spark's lazy evaluation, the coalesce is resulting in reduced parallelism of read operation.
这与懒惰无关。 coalesce
故意不创建 analysis barrier :
However, if you're doing a drastic coalesce, e.g. to numPartitions = 1, this may result in your computation taking place on fewer nodes than you like (e.g. one node in the case of numPartitions = 1). To avoid this, you can call repartition. This will add a shuffle step, but means the current upstream partitions will be executed in parallel (per whatever the current partitioning is).
因此,只需遵循文档并使用repartition
而不是coalesce
即可。
关于apache-spark - 合并减少 JDBC 读取并行度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49891929/