【问题标题】:Cannot save collect-ed RDD to local file system of Driver无法将收集的 RDD 保存到 Driver 的本地文件系统
【发布时间】:2015-08-28 21:02:06
【问题描述】:

我在调用 collect() 后尝试保存一个 RDD。我在 Host-1 上调用 spark-submit(我假设 Driver 是我调用 spark-submit 脚本的主机,所以在这种情况下 Host-1 是 Driver),从 HBase 获取一些数据,对其运行一些操作然后在 RDD 上调用 collect() 并遍历收集的列表并将其保存到本地文件系统文件。本质上:

if __name__ == "__main__":
    sc = SparkContext(appName="HBaseInputFormat")
    # read the data from hbase
    # ...
    # ...
    output = new_rdd.collect()

    with open("/var/tmp/tmpfile.csv", 'w') as tmpf:
        for o in output:
            print (o)
            tmpf.write("%s\n"%str(o))
    tmpf.close()

这实际上适用于保存在 /var/tmp/tmpfile.csv 中的数据,除了数据保存在与 Driver 不同的主机上,比如 Host-3。 我的印象是 collect 总是会收集驱动程序主机上的分布式数据集,因此文件也应该在驱动程序上创建。 我哪里错了?

【问题讨论】:

    标签: python hadoop apache-spark hbase pyspark


    【解决方案1】:

    我假设 Driver 是我调用 spark-submit 脚本的主机,所以在这种情况下 Host-1 是 Driver

    这不正确!请参阅running spark on yarn 上的文档。

    In yarn-cluster mode, the Spark driver runs inside an application master process which is managed by YARN on the cluster, and the client can go away after initiating the application. In yarn-client mode, the driver runs in the client process, and the application master is only used for requesting resources from YARN.

    您很可能在 yarn-cluster 模式下运行 spark,并且驱动程序被选择在集群中的一个节点上。

    将此更改为 yarn-client,驱动程序将在您提交作业的节点上运行。

    【讨论】:

      猜你喜欢
      • 2017-03-06
      • 2015-09-23
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 2013-08-19
      • 2011-01-29
      相关资源
      最近更新 更多