Spark系列(八)Worker工作原理
工作原理图

源代码分析
包名:org.apache.spark.deploy.worker
启动driver入口点:registerWithMaster方法中的case LaunchDriver
| 1 | ) => DriverState.FINISHED |
| 37 | case _ => DriverState.FAILED |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | finalState = Some(state) |
| 42 | // 向Driver所属worker发送DriverStateChanged消息 |
| 43 | worker ! DriverStateChanged(driverId, state, finalException) |
| 44 | } |
| 45 | }.start() |
| 46 | } |
LaunchExecutor
管理LaunchExecutor的启动
| 1 | case LaunchExecutor(masterUrl, appId, execId, appDesc, cores_, memory_) => |
| 2 | if (masterUrl != activeMasterUrl) { |
| 3 | logWarning("Invalid Master (" + masterUrl + ") attempted to launch executor.") |
| 4 | } else { |
| 5 | try { |
| 6 | logInfo("Asked to launch executor %s/%d for %s".format(appId, execId, appDesc.name)) |
| 7 | |
| 8 | // Create the executor's working directory |
| 9 | // 创建executor本地工作目录 |
| 10 | val executorDir = new File(workDir, appId + "/" + execId) |
| 11 | if (!executorDir.mkdirs()) { |
| 12 | throw new IOException("Failed to create directory " + executorDir) |
| 13 | } |
| 14 | |
| 15 | // Create local dirs for the executor. These are passed to the executor via the |
| 16 | // SPARK_LOCAL_DIRS environment variable, and deleted by the Worker when the |
| 17 | // application finishes. |
| 18 | val appLocalDirs = appDirectories.get(appId).getOrElse { |
| 19 | Utils.getOrCreateLocalRootDirs(conf).map { dir => |
| 20 | Utils.createDirectory(dir).getAbsolutePath() |
| 21 | }.toSeq |
| 22 | } |
| 23 | appDirectories(appId) = appLocalDirs |
| 24 | // 创建ExecutorRunner对象 |
| 25 | val manager = new ExecutorRunner( |
| 26 | appId, |
| 27 | execId, |
| 28 | appDesc.copy(command = Worker.maybeUpdateSSLSettings(appDesc.command, conf)), |
| 29 | cores_, |
| 30 | memory_, |
| 31 | self, |
| 32 | workerId, |
| 33 | host, |
| 34 | webUi.boundPort, |
| 35 | publicAddress, |
| 36 | sparkHome, |
| 37 | executorDir, |
| 38 | akkaUrl, |
| 39 | conf, |
| 40 | appLocalDirs, ExecutorState.LOADING) |
| 41 | // executor加入本地缓存 |
| 42 | executors(appId + "/" + execId) = manager |
| 43 | manager.start() |
| 44 | // 增加worker已使用core |
| 45 | coresUsed += cores_ |
| 46 | // 增加worker已使用memory |
| 47 | memoryUsed += memory_ |
| 48 | // 通知master发送ExecutorStateChanged消息 |
| 49 | master ! ExecutorStateChanged(appId, execId, manager.state, None, None) |
| 50 | } |
| 51 | // 异常情况处理,通知master发送ExecutorStateChanged FAILED消息 |
| 52 | catch { |
| 53 | case e: Exception => { |
| 54 | logError(s"Failed to launch executor $appId/$execId for ${appDesc.name}.", e) |
| 55 | if (executors.contains(appId + "/" + execId)) { |
| 56 | executors(appId + "/" + execId).kill() |
| 57 | executors -= appId + "/" + execId |
| 58 | } |
| 59 | master ! ExecutorStateChanged(appId, execId, ExecutorState.FAILED, |
| 60 | Some(e.toString), None) |
| 61 | } |
| 62 | } |
| 63 | } |
总结
1、Worker、Driver、Application启动后都会向Master进行注册,并缓存到Master内存数据模型中
2、完成注册后发送LaunchExecutor、LaunchDriver到Worker
3、Worker收到消息后启动executor和driver进程,并调用Worker的ExecutorStateChanged和DriverStateChanged方法
4、发送ExecutorStateChanged和DriverStateChanged消息到Master的,根据各自的状态信息进行处理,最重要的是会调用schedule方法进行资源的重新调度
Spark系列(八)Worker工作原理的更多相关文章
- Spark系列(十)TaskSchedule工作原理
工作原理图 源码分析: 1.) 25 launchedTask = true 26 } 27 } catch { 28 ...
- Spark系列(九)DAGScheduler工作原理
以wordcount为示例进行深入分析 1 33 ) { 46 logInfo("Submitting " + tasks.size + " missi ...
- line-height系列——定义和工作原理总结
一.line-height的定义和工作原理总结 line-height的属性值: normal 默认 设置合理的行间距. number 设置数字,此数字会与当前的字体尺寸相乘来设置行间距li ...
- 源码分析八( hashmap工作原理)
首先从一条简单的语句开始,创建了一个hashmap对象: Map<String,String> hashmap = new HashMap<String,String>(); ...
- [Spark内核] 第32课:Spark Worker原理和源码剖析解密:Worker工作流程图、Worker启动Driver源码解密、Worker启动Executor源码解密等
本課主題 Spark Worker 原理 Worker 启动 Driver 源码鉴赏 Worker 启动 Executor 源码鉴赏 Worker 与 Master 的交互关系 [引言部份:你希望读者 ...
- 【原】Learning Spark (Python版) 学习笔记(三)----工作原理、调优与Spark SQL
周末的任务是更新Learning Spark系列第三篇,以为自己写不完了,但为了改正拖延症,还是得完成给自己定的任务啊 = =.这三章主要讲Spark的运行过程(本地+集群),性能调优以及Spark ...
- How Javascript works (Javascript工作原理) (八) WebAssembly 对比 JavaScript 及其使用场景
个人总结: webworker有以下三种: Dedicated Workers 由主进程实例化并且只能与之进行通信 Shared Workers 可以被运行在同源的所有进程访问(不同的浏览的选项卡,内 ...
- 49、Spark Streaming基本工作原理
一.大数据实时计算介绍 1.概述 Spark Streaming,其实就是一种Spark提供的,对于大数据,进行实时计算的一种框架.它的底层,其实,也是基于我们之前讲解的Spark Core的. 基本 ...
- 46、Spark SQL工作原理剖析以及性能优化
一.工作原理剖析 1.图解 二.性能优化 1.设置Shuffle过程中的并行度:spark.sql.shuffle.partitions(SQLContext.setConf()) 2.在Hive数据 ...
随机推荐
- C#基础练习(时间的三连击)
Form1的后台代码: namespace _07事件的三连击 { public partial class Form1 : Form { public Form1() ...
- iOS 越狱机免证书调试
目前在XCode上开发的iOS程序只能在模拟器Simulator中运行,如果要放到真机上测试,需要苹果官方认证的开发者账号,购买开发者证书iDP,99美金一年啊! 作为刚开始学习iOS编程的菜鸟,这么 ...
- sudo
sudo的目的:为非根用户授予根用户的权限: 配置文件:/etc/sudoers visudo命令编辑修改/etc/sudoers配置文件 1.一般用户赋权设置: [root@localhost ~] ...
- jsp中四种传递参数的方法
jsp中四种传递参数的方法如下: 1.form表单 2.request.setAttribute();和request.getAttribute(); 3.超链接:<a herf="i ...
- C语言中的宏展开
#include<stdio.h> #define f(a,b) a##b #define g(a) #a #define h(a) g(a) int main() { printf(,) ...
- Redis安装教程
1. Linux下Redis安装教程 (1)安装 #tar xf redis-2.6.14.tar.gz #cd redis-2.6.14 #make #make install (2)配置 修改re ...
- 使用设置报头x-Frame-Options限制iframe网页嵌套
x-frame-options的出现一部分是为了防止一些别有用心的者制作钓鱼网站,现在支持的浏览器有一下: chrome 4.1.249.1042 firefox 3.6.9(1.9.2.9) IE ...
- UVa 1467 (贪心+暴力) Installations
题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...
- Asp.Net IEnumerable,ICollection,IList,List区别
做C#的同学们,都知道,一类只能有一个继承类,但可以实现多个接口.这句话就告诉我们:IEnumerable,ICollection,IList,List区别了 首先我看看 IEnumerable: / ...
- context:property-placeholder
这个在spring中配置文件中是非常常用的. context:property-placeholder大大的方便了我们数据库的配置. 只需要在spring的配置文件里添加一句:<context: ...