我试图了解 Spark 中的作业和阶段是如何定义的,为此我现在使用我找到的代码 here和 Spark 用户界面。为了在 Spark UI 上看到它,我必须多次复制文本并将其粘贴到文件上,因此需要更多时间来处理。
这是 Spark UI 的输出:
现在,我明白有 3 个作业,因为有 3 个操作,并且阶段是由于随机操作而生成的,但我不明白的是为什么在作业 1 中阶段 4、5 和 6 是与作业 0 的阶段 0、1 和 2 相同,作业 2 也发生同样的情况。
除了只看到 java 代码(在执行任何操作之前)之外,我如何知道作业将处于哪些阶段?另外,为什么跳过第 4 阶段和第 9 阶段?我如何知道它会在执行之前发生?
最佳答案
I understand that there are three jobs because there are three actions
我什至会说,本来可以有更多 Spark 作业,但最少数量是 3
。这完全取决于转换的实现和所使用的操作。
I don't understand is why in the Job 1 stages 4, 5 and 6 are the same as stages 0, 1 and 2 of Job 0 and the same happens for Job 2.
作业 1 是在 RDD finalRdd
上运行的某些操作的结果。该 RDD 是使用(向后)创建的:join
、textFile
、map
和 distinct
。
val people = sc.textFile("people.csv").map { line =>
val tokens = line.split(",")
val key = tokens(2)
(key, (tokens(0), tokens(1))) }.distinct
val cities = sc.textFile("cities.csv").map { line =>
val tokens = line.split(",")
(tokens(0), tokens(1))
}
val finalRdd = people.join(cities)
运行上面的代码,您将看到相同的 DAG。
现在,当您执行 leftOuterJoin
或 rightOuterJoin
操作时,您将获得另外两个 DAG。您正在使用以前使用的 RDD 来运行新的 Spark 作业,因此您将看到相同的阶段。
why are stage 4 and 9 skipped
Spark 通常会跳过某些阶段的执行。灰色的阶段是已经计算过的阶段,因此 Spark 将重用它们,从而提高性能。
How can I know what stages will be in more than a job only seeing the java code (before executing anything)?
这就是 RDD 谱系(图)提供的功能。
scala> people.leftOuterJoin(cities).toDebugString
res15: String =
(3) MapPartitionsRDD[99] at leftOuterJoin at <console>:28 []
| MapPartitionsRDD[98] at leftOuterJoin at <console>:28 []
| CoGroupedRDD[97] at leftOuterJoin at <console>:28 []
+-(2) MapPartitionsRDD[81] at distinct at <console>:27 []
| | ShuffledRDD[80] at distinct at <console>:27 []
| +-(2) MapPartitionsRDD[79] at distinct at <console>:27 []
| | MapPartitionsRDD[78] at map at <console>:24 []
| | people.csv MapPartitionsRDD[77] at textFile at <console>:24 []
| | people.csv HadoopRDD[76] at textFile at <console>:24 []
+-(3) MapPartitionsRDD[84] at map at <console>:29 []
| cities.csv MapPartitionsRDD[83] at textFile at <console>:29 []
| cities.csv HadoopRDD[82] at textFile at <console>:29 []
正如您所看到的,由于存在 3 个随机依赖项(具有分区数量的边),因此您最终将得到 4 个阶段。
圆括号中的数字是 DAGScheduler
最终将用于创建具有确切任务数量的任务集的分区数量。每个阶段一个 TaskSet
。
关于apache-spark - Spark 如何管理阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41407459/