Spark 1.2.0如何将配置文件添加到所有Spark执行器的类路径中?

How to add configuration file to classpath of all Spark executors in Spark 1.2.0?

我正在使用 Typesafe Config,https://github.com/typesafehub/config,通过配置文件在 yarn-cluster 模式下参数化 Spark 作业 运行。 Typesafe Config 的默认行为是在 class 路径中搜索名称与正则表达式匹配的资源,并使用 ConfigFactory.load() 自动将它们加载到您的配置 class 中(为了我们的目的,假设文件它寻找的是 application.conf).

我可以使用 --driver-class-path <directory containing configuration file> 将配置文件加载到驱动程序中,但是使用 --conf spark.executor.extraClassPath=<directory containing configuration file> 不会像它应该的那样将资源放在所有执行程序的 class 路径上。执行者报告说,他们找不到某个密钥的特定配置设置,而该密钥确实存在于我试图添加到他们的 class 路径的配置文件中。

使用 Spark 将文件添加到所有执行程序 JVM 的class路径的正确方法是什么?

看起来 spark.executor.extraClassPath 属性 的值是相对于应用程序在执行器上的工作目录。

所以,要正确使用这个属性,应该先用--files <configuration file>让Spark把文件复制到所有executor的工作目录,然后用spark.executor.extraClassPath=./添加执行程序的工作目录到它的类路径。这种组合导致执行程序能够从配置文件中读取值。

我使用 SparkContext addFile 方法

val sc: SparkContext = {
  val sparkConf = new SparkConf()
    .set("spark.storage.memoryFraction", "0.3")
    .set("spark.driver.maxResultSize", "10g")
    .set("spark.default.parallelism", "1024")
    .setAppName("myproject")
  sparkConf.setMaster(getMaster)
  val sc = new SparkContext(sparkConf)
  sc.addFile("application.conf")
  sc
}