apache-spark - 如何并行运行多个Spark作业?

标签 apache-spark

一个 Spark 有一个 Oracle 查询。所以我必须并行运行多个作业,以便所有查询同时触发。

如何并行运行多个作业?

最佳答案

引用官方文档Job Scheduling :

Second, within each Spark application, multiple "jobs" (Spark actions) may be running concurrently if they were submitted by different threads.

换句话说,单个 SparkContext 实例可由多个线程使用,从而能够提交多个可能并行运行或可能不并行运行的 Spark 作业。

Spark 作业是否并行运行取决于 CPU 数量(Spark 不跟踪调度的内存使用情况)。如果有足够的 CPU 来处理多个 Spark 作业的任务,它们将同时运行。

如果 CPU 数量不够,您可以考虑使用 FAIR scheduling mode (默认为 FIFO):

Inside a given Spark application (SparkContext instance), multiple parallel jobs can run simultaneously if they were submitted from separate threads. By “job”, in this section, we mean a Spark action (e.g. save, collect) and any tasks that need to run to evaluate that action. Spark’s scheduler is fully thread-safe and supports this use case to enable applications that serve multiple requests (e.g. queries for multiple users).

By default, Spark’s scheduler runs jobs in FIFO fashion. Each job is divided into “stages” (e.g. map and reduce phases), and the first job gets priority on all available resources while its stages have tasks to launch, then the second job gets priority, etc. If the jobs at the head of the queue don’t need to use the whole cluster, later jobs can start to run right away, but if the jobs at the head of the queue are large, then later jobs may be delayed significantly.

<小时/>

只是为了把事情弄清楚一点。

  1. spark-submit 是提交一个 Spark 应用程序来执行(不是 Spark 作业)。单个 Spark 应用程序可以有至少一个 Spark 作业。

  2. RDD 操作可能会或可能不会阻塞。 SparkContext 提供了两种提交(或运行)Spark 作业的方法,即 SparkContext.runJobSparkContext.submitJob,因此它不操作是否阻塞确实很重要,但使用什么 SparkContext 方法来实现非阻塞行为才是重要的。

请注意,“RDD 操作方法”已经编写完毕,并且它们的实现使用 Spark 开发人员所押注的任何内容(主要是 SparkContext.runJob,如 count 中所示):

// RDD.count
def count(): Long = sc.runJob(this, Utils.getIteratorSize _).sum

您必须编写自己的 RDD 操作(在自定义 RDD 上)才能在 Spark 应用程序中获得所需的非阻塞功能。

关于apache-spark - 如何并行运行多个Spark作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49568940/

相关文章:

apache-spark - Parquet 过滤器下推是否应该减少数据读取?

hadoop - Spark 应用程序继续运行并且似乎挂起 - org.apache.spark.sql.hive.thriftserver.HiveThriftServer2

apache-spark - Spark on K8 的问题加载 jar

apache-spark - 在 BinaryObjects 的 Ignite 缓存上执行 SQL

hadoop - 为什么 Spark 以不同的方式解释这两个查询?

apache-spark - Apache Spark 的结构化流与 Google PubSub

azure - 如何获取 Azure 容器文件夹的正确路径?

Azure Databricks 群集 API 身份验证

apache-spark - KryoSerializer 缓冲区溢出

scala - 两个对象SCALA之间的调用方法