对于 YARN 上的 spark 应用程序 运行,哪种部署模式更好 - 客户端或集群

For spark applications running on YARN, which deploy mode is better - client or cluster

我了解 YARN 上 Spark 应用程序的客户端模式和集群模式之间的主要区别。

主要区别包括

  1. 驱动在哪运行 - clinet模式下本地,集群模式下Application Master
  2. Client 运行ning duration - 在 clinet 模式下,client 需要 运行 整个持续时间, 在集群模式下,客户端不需要 运行 因为 AM 会处理它
  3. 交互使用 - spark shell 和 pyspark。集群模式不太适合这些 要求驱动程序在客户端
  4. 上 运行
  5. 调度工作 - 在客户端模式下,客户端通过直接与容器通信来调度工作。 在集群模式下,A通过直接与容器通信来调度工作

两种情况的相似之处

  1. 谁处理来自 YARN 的执行程序请求 - 应用程序主管
  2. 谁启动执行程序进程 - YARN 节点管理器

我的问题是 - 在现实世界场景(生产环境)中,我们不需要交互模式,客户端不需要长时间 运行 - 集群模式是一个明显的选择吗?

客户端模式有什么好处,例如:

根据我的经验,在生产环境中,唯一合理的模式是集群模式,但有 2 个例外:

  • 当 hadoop 节点没有应用程序所需的资源时,例如:在执行结束时,spark 作业对无法从 hadoop 节点访问的服务器执行ssh
  • 当你使用 spark streaming 并且你想优雅地关闭它时(杀死集群模式应用程序会强制关闭流式传输,如果你 运行 在客户端模式下你可以调用 ssc.stop(stopGracefully = true)

根据文档,

A common deployment strategy is to submit your application from a gateway machine that is physically co-located with your worker machines (e.g. Master node in a standalone EC2 cluster). In this setup, client mode is appropriate. In client mode, the driver is launched directly within the client spark-submit process, with the input and output of the application attached to the console. Thus, this mode is especially suitable for applications that involve the REPL (e.g. Spark shell).

Alternatively, if your application is submitted from a machine far from the worker machines (e.g. locally on your laptop), it is common to use cluster mode to minimize network latency between the drivers and the executors. Note that cluster mode is currently not supported for standalone clusters, Mesos clusters, or python applications.

看起来,主要原因是当我们运行从远程提交spark时,为了减少执行者和驱动程序之间的延迟,集群模式是首选。