apache-spark - Spark 如何在 Hadoop YARN 上准备执行器?

标签 apache-spark hadoop-yarn

我试图了解 Spark 如何准备执行器的详细信息。为了做到这一点,我尝试调试 org.apache.spark.executor.CoarseGrainedExecutorBackend 并调用

Thread.currentThread().getContextClassLoader.getResource("")

它指向以下目录:

/hadoop/yarn/local/usercache/_MY_USER_NAME_/appcache/application_1507907717252_15771/container_1507907717252_15771_01_000002/

查看目录,我发现了以下文件:

default_container_executor_session.sh
default_container_executor.sh
launch_container.sh
__spark_conf__
__spark_libs__

问题是谁将文件传递给每个执行器,然后使用适当的类路径运行 CoarseGrainedExecutorBackend ?脚本是什么?它们都是 YARN 自动生成的吗?

我查看了org.apache.spark.deploy.SparkSubmit,但没有在里面找到任何有用的东西。

最佳答案

哎哟...您要求提供有关 Spark 在请求资源时如何与集群管理器通信的大量详细信息。让我给你一些信息。继续询问您是否想要更多...


您正在使用 Hadoop YARN 作为 Spark 应用程序的集群管理器。让我们只关注这个特定的集群管理器(因为 Spark 支持其他集群管理器,例如 Apache Mesos、Spark Standalone、DC/OS 以及很快的 Kubernetes,它们都有自己的方法来处理 Spark 部署)。

默认情况下,使用 spark-submit 提交 Spark 应用程序时,Spark 应用程序(即它实际使用的 SparkContext)会请求三个 YARN 容器。一个容器用于 Spark 应用程序的 ApplicationMaster,它知道如何与 YARN 通信并为两个 Spark 执行程序请求另外两个 YARN 容器。

可以查看YARN官方文档的Apache Hadoop YARNHadoop: Writing YARN Applications更深入地了解 YARN 内部结构。

提交 Spark 应用程序时,Spark 的 ApplicationMaster使用 YARN“协议(protocol)”提交给 YARN,该协议(protocol)要求对第一个 YARN 容器(容器 0)的请求使用包含所有必要的启动详细信息的 ContainerLaunchContext(请参阅Client.createContainerLaunchContext)。

enter image description here

who delivers the files to each executor

这就是 YARN 如何被告知如何为 Spark 应用程序启动 ApplicationMaster 的方式。在满足 ApplicationMaster 容器的请求时,YARN 会下载您在容器工作空间中找到的必要文件。

这是任何 YARN 应用程序在 YARN 上工作的内部方式,与 Spark(几乎)无关。

负责通信的代码位于 Spark 的 Client 中,尤其是。 Client.submitApplication .

enter image description here

and then just runs CoarseGrainedExecutorBackend with the appropriate classpath.

引用Mastering Apache Spark 2 gitbook:

CoarseGrainedExecutorBackend is a standalone application that is started in a resource container when (...) Spark on YARN’s ExecutorRunnable is started.

ExecutorRunnable 当 Spark on YARN 的 YarnAllocator 在分配的 YARN 资源容器中调度时启动。

enter image description here

What are the scripts? Are they all YARN-autogenerated?

有点。

有些是由 Spark 作为 Spark 应用程序提交的一部分准备的,而其他则是特定于 YARN 的。

在 Spark 应用程序中启用 DEBUG 日志记录级别,您将看到文件传输。


更多信息可以在Spark官方文档的Running Spark on YARN中找到和 Mastering Apache Spark 2我的 gitbook。

关于apache-spark - Spark 如何在 Hadoop YARN 上准备执行器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47710036/

相关文章:

scala - 将 Yarn 集群配置添加到 Spark 应用程序

apache-spark - Spark BigQuery 连接器 : BaseEncoding$DecodingException: Unrecognized character: 0xa

hadoop - Spark 和 Map-Reduce 一起使用

hadoop - Hbase 问题 |反序列化 SCAN 字符串时出现谷歌 protobuf 标签不匹配错误

python - 有没有办法在 Pyspark 中动态猜测架构?

apache-spark - 如何在 Spark Streaming 中删除执行者的日志

hadoop - 如果工作节点上未安装 Spark(在 YARN 上),Spark 执行器如何启动?

scala - 在 yarn 簇上使用带有管道的 addFile

apache-spark - 如何在 Java 中通过应用程序 ID 获取 Spark 应用程序句柄

python-3.x - “RDD”对象没有属性 '_jdf' pyspark RDD