Spark Stage

Spark Stage

什么是Stage

Spark中的一个Stage只不过是物理执行计划其中的一个步骤,它是物理执行计划的一个执行单元。一个Job会被拆分为多组Task,每组任务被称为一个Stage,可以简单理解为MapReduce里面的Map Stage, Reduce Stage。

spark task提交原理

Spark的Job中Stage之间会有依赖关系。可以利用这些依赖关系把Job所有stage串连起来形成一个有向无环图。在单个job内是根据shuffle算子来拆分stage的,shuffle之前是一个stage,shuffle之后是另一个stage,如果一个job中有多个shuffle,那么每个shuffle之前都是一个stage。一个job被提交运行之后,将会触发stage及其父stage的执行。

spark stage

窄依赖
指父RDD的每一个分区最多被一个子RDD的分区所用,表现为一个父RDD的分区对应于一个子RDD的分区,和两个父RDD的分区对应于一个子RDD 的分区。图中,map/filter和union属于第一类,对输入进行协同划分(co-partitioned)的join属于第二类。

宽依赖
指子RDD的分区依赖于父RDD的所有分区,这是因为shuffle类操作,如图中的groupByKey和未经协同划分的join。
spark 宽依赖窄依赖

Stage:
一个Job会被拆分为多组Task,每组任务被称为一个Stage就像Map Stage, Reduce Stage。Stage的划分,简单的说是以ShuffleMapStage 和ResultStage 这两种类型来划分。

在Spark中有两类task,一类是shuffleMapTask,一类是resultTask,第一类task的输出是shuffle所需数据,第二类task的输出是result,stage的划分也以此为依据,shuffle之前的所有变换是一个stage,shuffle之后的操作是另一个stage。

比如 rdd.parallize(1 to 10).foreach(println) 这个操作没有shuffle,直接就输出了,那么只有它的task是resultTask,stage也只有一个;

如果是rdd.map(x => (x, 1)).reduceByKey(_ + _).foreach(println), 这个job因为有reduce,所以有一个shuffle过程,那么reduceByKey之前的是一个stage,执行shuffleMapTask,输出shuffle所需的数据,reduceByKey到最后是一个stage,直接就输出结果了。

如果job中有多次shuffle,那么每个shuffle之前都是一个stage。

Spark会根据RDD之间的依赖关系将DAG图划分为不同的阶段,对于窄依赖,由于partition依赖关系的确定性,partition的转换处理就可以在同一个线程里完成,窄依赖就被spark划分到同一个stage中,而对于宽依赖,只能等父RDD shuffle处理完成后,下一个stage才能开始接下来的计算。之所以称之为ShuffleMapTask是因为它需要将自己的计算结果通过shuffle到下一个stage中。

Spark Stage的分类

在Spark中,Stage可以分成两种类型。分别是:

  • ShuffleMapStage
  1. 这种Stage是以Shuffle为输出边界
  2. 其输入边界可以是从外部获取数据,也可以是另一个ShuffleMapStage的输出
  3. 其输出可以是另一个Stage的开始
  4. ShuffleMapStage的最后Task就是ShuffleMapTask
  5. 在一个Job里可能有该类型的Stage,也可以能没有该类型Stage
  • ResultStage
  1. 这种Stage是直接输出结果
  2. 其输入边界可以是从外部获取数据,也可以是另一个ShuffleMapStage的输出
  3. ResultStage的最后Task就是ResultTask
  4. 在一个Job里必定有该类型Stage

Stage类的定义

Stage类是一个抽象类,类的定义如下:

abstract class Stage {    def findMissingPartitions(): Seq[Int]}
  • 21
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Big data is getting bigger and bigger day by day. And I don't mean tera, peta, exa, zetta, and yotta bytes of data collected all over the world every day. I refer to complexity and number of components utilized in any decent and respectable big data ecosystem. Never mind the technical nitties gritties—just keeping up with terminologies, new buzzwords, and hypes popping up all the time can be a real challenge in itself. By the time you have mastered them all, and put your hard- earned knowledge to practice, you will discover that half of them are old and inef cient, and nobody uses them anymore. Spark is not one of those "here today, gone tomorrow" fads. Spark is here to stay with us for the foreseeable future, and it is well worth to get your teeth into it in order to get some value out of your data NOW, rather than in some, errr, unforeseeable future. Spark and the technologies built on top of it are the next crucial step in the big data evolution. They offer 100x faster in-memory, and 10x on disk processing speeds in comparison to the traditional Hadoop jobs. There's no better way of getting to know Spark than by reading this book, written by Mike Frampton, a colleague of mine, whom I rst met many, many years ago and have kept in touch ever since. Mike's main professional interest has always been data and in pre-big data days, he worked on data warehousing, processing, and analyzing projects for major corporations. He experienced the inef ciencies, poor value, and frustrations that the traditional methodologies of crunching the data offer rst hand. So understanding big data, what it offers, where it is coming from, and where it is heading, and is intrinsically intuitive to him. Mike wholeheartedly embraced big data the moment it arrived, and has been devoted to it ever since. He practices what he preaches, and is not in it for money. He is very active in the big data community, writes books, produces presentations on SlideShare and YouTube, and is always rst to test-drive the new, emerging products. Mike's passion for big data, as you will nd out, is highly infectious, and he is always one step ahead, exploring the new and innovative ways big data is used for. No wonder that in this book, he will teach you how to use Spark in conjunction with the very latest technologies; some of them are still in development stage, such as machine learning and Neural Network. But fear not, Mike will carefully guide you step by step, ensuring that you will have a direct, personal experience of the power and usefulness of these technologies, and are able to put them in practice immediately.
ClusterManager:在Standalone模式中即为Master(主节点),控制整个集群,监控Worker。在YARN模式中为资源管理器。 Worker:从节点,负责控制计算节点,启动Executor。在YARN模式中为NodeManager,负责计算节点的控制。 Driver:运行Application的main()函数并创建SparkContext。 Executor:执行器,在worker node上执行任务的组件、用于启动线程池运行任务。每个Application拥有独立的一组Executors。 SparkContext:整个应用的上下文,控制应用的生命周期。 RDD:Spark的基本计算单元,一组RDD可形成执行的有向无环图RDD Graph。 DAG Scheduler:实现将Spark作业分解成一到多个Stage,每个Stage根据RDD的Partition个数决定Task的个数,然后生成相应的Task set放到TaskScheduler中。 TaskScheduler:将任务(Task)分发给Executor执行。 Stage:一个Spark作业一般包含一到多个Stage。 Task:一个Stage包含一到多个Task,通过多个Task实现并行运行的功能。 Transformations:转换(Transformations) (如:map, filter, groupBy, join等),Transformations操作是Lazy的,也就是说从一个RDD转换生成另一个RDD的操作不是马上执行,Spark在遇到Transformations操作时只会记录需要这样的操作,并不会去执行,需要等到有Actions操作的时候才会真正启动计算过程进行计算。 Actions:操作(Actions) (如:count, collect, save等),Actions操作会返回结果或把RDD数据写到存储系统中。Actions是触发Spark启动计算的动因。 SparkEnv:线程级别的上下文,存储运行时的重要组件的引用。 SparkEnv内创建并包含如下一些重要组件的引用。 MapOutPutTracker:负责Shuffle元信息的存储。 BroadcastManager:负责广播变量的控制与元信息的存储。 BlockManager:负责存储管理、创建和查找块。 MetricsSystem:监控运行时性能指标信息。 SparkConf:负责存储配置信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不二人生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值