Spark源码剖析(五):Master原理与源码剖析(下)

一. 状态改变机制源码分析

在剖析Master核心的资源调度算法以前,让咱们先来看看Master的状态改变机制。 算法

Driver状态改变

Alt text 
能够看出,一旦Driver状态发生改变,基本没有好事情,后果要么是删除Driver,要么是报异常! 
  
removeDriver方法:app

Alt text

Executor状态改变

Alt text

Alt text 
能够看出,若是Executor时非正常退出,会尝试从新调度(启动)该Executor,直到该Application达到了最大的重试次数10次。 
  
removeApplication方法源码分析

Alt text


二. 资源调度机制源码分析(schedule方法)

  1. schedule方法的做用是为当前等待分配资源的app分配可用的集群资源,该方法会在新的app加入或者是可用资源改变时被调用。 
  2. 首先是调度Drivers(只有在yarn cluster模式下Driver才须要调度),随机打乱AliveWorkers的Alt text

  1. 接下来咱们来调度Application(核心!),使用简单的FIFO策略,调度算法分为spreadOutApps和非spreadOutApps,spreadOutApps算法就是尽量平均的将总app cores分配到全部Worker节点,非spreadOutApps算法就是将总app cores分配到尽量少的Worker节点

Alt text

Alt text 
  
canUse()方法spa

Alt text 
  
launchExecutor方法code

Alt text

相关文章
相关标签/搜索