Apache Spark:客户端和集群部署模式之间的差异

Apache Spark: Differences between client and cluster deploy modes

TL;DR: 在 Spark Standalone 集群中,客户端和集群部署模式有什么区别?如何设置我的应用程序 运行 开启的模式?


我们有一个包含三台机器的 Spark Standalone 集群,它们都装有 Spark 1.6.1:

Spark Documentation,我读到:

(...) For standalone clusters, Spark currently supports two deploy modes. In client mode, the driver is launched in the same process as the client that submits the application. In cluster mode, however, the driver is launched from one of the Worker processes inside the cluster, and the client process exits as soon as it fulfills its responsibility of submitting the application without waiting for the application to finish.

但是,我并没有真正理解通过阅读这篇文章的实际差异,也不知道不同部署模式的优点和缺点是什么。

此外,当我使用 start-submit 启动我的应用程序时,即使我将 属性 spark.submit.deployMode 设置为 "cluster",我的上下文的 Spark UI 也会显示以下条目:

所以我无法测试这两种模式以查看实际差异。话虽如此,我的问题是:

1) Spark Standalone client 部署模式和 cluster 部署模式之间的实际区别是什么?使用每一个的优点和缺点是什么?

2) 如何使用 spark-submit 选择我的应用程序 运行 运行哪一个?

What are the practical differences between Spark Standalone client deploy mode and cluster deploy mode? What are the pro's and con's of using each one?

让我们看看客户端模式和集群模式的区别。

客户:

  • 驱动程序 运行s 在专用进程内的专用服务器(主节点)上。这意味着它拥有执行工作所需的所有可用资源。
  • Driver开辟专用的Netty HTTP服务器,将指定的JAR文件分发给所有Worker节点(大优势)。
  • 因为Master节点有自己的专用资源,所以你不需要"spend" Driver程序的worker资源。
  • 如果驱动程序进程终止,您需要一个外部监控系统来重置它的执行。

集群:

  • Driver 运行s 在集群的一个 Worker 节点上。工人由Master领导选择
  • Driver 运行作为 Worker 内部的专用独立进程
  • 驱动程序占用 至少 1 个核心和其中一名工作人员的专用内存量(可以配置)。
  • 可以使用 --supervise 标志从主节点监控驱动程序,并在它死掉时重置。
  • 在集群模式下工作时,与应用程序执行相关的所有 JAR 都需要对所有工作人员公开可用。这意味着您可以手动将它们放在共享位置或每个工作人员的文件夹中。

哪个更好?不确定,这实际上是供您试验和决定的。这不是更好的决定,您可以从前者和后者中获益,由您决定哪个更适合您的用例。

How to I choose which one my application is going to be running on, using spark-submit

选择 运行 模式的方法是使用 --deploy-mode 标志。来自 Spark Configuration 页面:

/bin/spark-submit \
  --class <main-class>
  --master <master-url> \
  --deploy-mode <deploy-mode> \
  --conf <key>=<value> \
  ... # other options
  <application-jar> \
  [application-arguments]

我也有同样的情况,这里主节点使用独立的 ec2 集群。在此设置中,客户端模式是合适的。在这个驱动程序中,直接在充当集群客户端的 spark-submit 进程中启动。应用的Input & output附在console.Thus,这种模式特别适合涉及REPL的应用

否则,如果您的应用程序是从远离工作机器的机器提交的,那么使用集群模式来最小化网络延迟是很常见的 b/w 驱动程序和执行程序。

假设您要通过 SSH 连接到主节点,在 EMR 中执行 spark 提交。 如果您提供选项 --deploy-mode cluster,则会发生以下情况。

  1. 您将无法在终端中看到详细的日志。
  2. 由于驱动程序不是在 Master 本身中创建的,因此您将无法从终端终止作业。

但在 --deploy-mode 客户端的情况下:

  1. 您将能够在终端中看到详细的日志。
  2. 您将能够从终端本身终止作业。

这些是我到目前为止所注意到的基本内容。