SparkContext源码深入剖析
来源:互联网 发布:win10如何安装mysql 编辑:程序博客网 时间:2024/06/05 22:31
本节分析针对Standalone模式
版本:Spark2.11
在Spark中,SparkContext是Spark所有功能的一个入口,你无论是用java、scala,甚至是python编写都必须要有一个SparkContext,它的主要作用,包括初始化Spark应用程序所需的一些核心组件,包括 调度器(DAGSchedule、TaskScheduler),还会去到Spark Master节点上进行注册,等等
一句话,SparkContext,是Spark应用中,可以说是最最重要的一个对象
但是呢,在Spark中,编写不同类型的Spark应用程序,使用的SparkContext是不同的,如果使用scala,
// 使用的就是原生的SparkContext对象
// 但是如果使用Java,那么就是JavaSparkContext对象
// 如果是开发Spark SQL程序,那么就是SQLContext、HiveContext
// 如果是开发Spark Streaming程序,那么就是它独有的SparkContext
// 以此类推
一、TaskScheduler的初始化
1、TaskScheduler的创建
2分析standalone集群模式
3、分析TaskSchedulerImpl
/** * Schedules tasks for multiple types of clusters by acting through a SchedulerBackend.底层通过操作一个SchedulerBackend,针对不同种类的cluster(standalone,yarn,mesos)调度task * It can also work with a local setup by using a [[LocalSchedulerBackend]] and setting isLocal to true. 它也可以通过使用一个LocalSchedulerBackend并且将isLocal设置为true,来在本地模式下运行It handles common logic, like determining a scheduling order across jobs, waking up to launch speculative tasks, etc.*它负责处理一些通用的逻辑,比如说决定多个job的调度顺序,启动推测任务执行 * Clients should first call initialize() and start(), then submit task sets through the runTasks method. *客户端首先应调用它的initialize()和start方法,然后通过runTask()提交task sets * THREADING: [[SchedulerBackend]]s and task-submitting clients can call this class from multiple * threads, so it needs locks in public API methods to maintain its state. In addition, some * [[SchedulerBackend]]s synchronize on themselves when they want to send events here, and then * acquire a lock on us, so we need to make sure that we don't try to lock the backend while * we are holding a lock on ourselves. */private[spark] class TaskSchedulerImpl( val sc: SparkContext, val maxTaskFailures: Int, isLocal: Boolean = false) extends TaskScheduler with Logging
4、调用initialize()方法,创建调度池
5、调用start方法
调用StandaloneSchedulerBackend的start()
6、创建ApplicationDescription
它就代表了执行当前这个application最大需要多少cpu core,每个salve上需要多少内存
7 、创建了StandaloneAppClient
这是一个接口,它负责为appliction与Spark集群进行通信
它会接受一个spark masret的URL以及app description和一个集群时间的监听器,以及各种事件发生时,监听器的回调函数
到此阶段TaskScheduler的初始化完成
二、初始化DAGScheduler
阅读全文
0 0
- SparkContext源码深入剖析
- Spark内核源码深度剖析:sparkContext初始化的源码核心
- SparkContext源码
- 《apache spark源码剖析》 学习笔记之SparkContext
- Spark2.0.X源码深度剖析之 SparkContext
- Spark2.2 SparkContext原理剖析图及源码
- Spark内核源码深度剖析:SparkContext原理剖析与源码分析
- Spark内核源码深度剖析:SparkContext原理剖析与源码分析
- 深入源码剖析LruCache
- Retrofit 源码剖析-深入
- Retrofit 源码剖析-深入
- 【Spark】SparkContext源码解读
- 0028.SparkContext源码解析
- SparkContext源码解读
- 1.SparkContext源码分析
- Spark源码学习- SparkContext
- sparkContext源码分析
- 【Java深入】HashSet源码剖析
- PAT_乙题1004. 成绩排名 (20)
- 完数问题
- golang
- Java —— Advanced Language Features —> static
- 通用冒泡排序算法
- SparkContext源码深入剖析
- matlab基础知识(一)
- 使用Keras预训练模型ResNet50进行图像分类
- Python “树”的绘制代码
- node.js安装 jspm模块 并初始化 jspm 支持ECMAScript6语法
- AVRWARE++开发笔记10:晶振频率的选择
- 基于opencv 和 Dlib的人眼检测,放大与贴纸替换
- 证明自己没有消失
- android之View坐标系(view获取自身坐标的方法和点击事件中坐标的获取)