gpt4 book ai didi

apache-spark - 在集群模式下通过spark-submit共享配置文件

转载 作者:行者123 更新时间:2023-12-04 03:59:01 25 4
gpt4 key购买 nike

在开发过程中,我一直在“客户端”模式下运行我的spark作业。我使用“--file”与执行程序共享配置文件。驱动程序正在本地读取配置文件。现在,我想以“集群”模式部署作业。我现在很难与驱动程序共享配置文件。

例如,我将配置文件名称作为extraJavaOptions传递给驱动程序和执行程序。我正在使用SparkFiles.get()阅读文件

  val configFile = org.apache.spark.SparkFiles.get(System.getProperty("config.file.name"))

这在执行程序上运行良好,但在驱动程序上失败。我认为文件仅与执行者共享,而不与驱动程序运行所在的容器共享。
一种选择是将配置文件保留在S3中。我想检查一下是否可以使用spark-submit来实现。
> spark-submit --deploy-mode cluster --master yarn --driver-cores 2
> --driver-memory 4g --num-executors 4 --executor-cores 4 --executor-memory 10g \
> --files /home/hadoop/Streaming.conf,/home/hadoop/log4j.properties \
> --conf **spark.driver.extraJavaOptions**="-Dlog4j.configuration=log4j.properties
> -Dconfig.file.name=Streaming.conf" \
> --conf **spark.executor.extraJavaOptions**="-Dlog4j.configuration=log4j.properties
> -Dconfig.file.name=Streaming.conf" \
> --class ....

最佳答案

我在this线程中找到了解决此问题的方法。

您可以通过在末尾添加“#alias”来为通过--files提交的文件提供别名。通过此技巧,您应该能够通过其别名访问文件。

例如,以下代码可以正常运行。

spark-submit --master yarn-cluster --files test.conf#testFile.conf test.py

与test.py为:
path_f = 'testFile.conf'
try:
f = open(path_f, 'r')
except:
raise Exception('File not opened', 'EEEEEEE!')

和一个空的test.conf

关于apache-spark - 在集群模式下通过spark-submit共享配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40179397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com