我的应用程序读取一个大型镶木地板文件并执行一些数据提取以获取一个较小的 Spark 数据帧对象。该数据帧的所有内容必须存在于每个执行器节点上,以进行下一阶段的计算。我知道我可以通过收集广播来做到这一点,如这个 pyspark 片段中所示
sc = pyspark.SparkContext()
sqlc = HiveContext(sc)
# --- register hive tables and generate spark dataframe
spark_df = sqlc.sql('sql statement')
# collect spark dataframe contents into a Pandas dataframe at the driver
global_df = spark_df.toPandas()
# broadcast Pandas dataframe to all the executor nodes
sc.broadcast(global_df)
Run Code Online (Sandbox Code Playgroud)
我只是想知道:有没有更有效的方法来做到这一点?看起来这种模式使驱动程序节点成为瓶颈。
这取决于您需要如何处理您的小数据框。如果您需要将其与大数据帧连接,那么 Spark 可以自动优化这种广播小数据帧的连接。可以广播的数据帧的最大大小由spark.sql.autoBroadcastJoinThreshold选项配置,如文档http://spark.apache.org/docs/latest/sql-programming-guide.html#other-configuration-options中所述
| 归档时间: |
|
| 查看次数: |
1354 次 |
| 最近记录: |