Storm系列(五)架构分析之Nimbus启动过程
启动流程图

mk-assignments
功能:对当前集群中所有Topology进行新一轮的任务调度。
实现源码路径:       
\apache-storm-0.9.4\storm-core\src\clj\backtype\storm\daemon\ nimbus.clj
方法原型:
| 1 | defnk mk-assignments [nimbus :scratch-topology-id nil] | 
- 参数nimbus为nimbus-data对象,scratch-topology-id为提交的Topology id.
- 从nimbus中依次获取conf、storm-cluster-state。
- 获取当前所有活跃的topology的id集合。
- 根据活跃的topology id调用read-topology-details方法,获取TopologyDetails信息并返回<storm-id,TopologyDetails>集合。
- 根据<storm-id,TopologyDetails>集合创建topologies对象。
- 获取已分配资源的Topology的id集合。
- 根据已分配资源的Topology id获取每个Topology的任务分配情况assigments,并返回<storm-id,Assigment>集合existing-assignments,除了scratch-topology-id指定的Topology不会获取它的Assigments。
- 调用compute-new-topology->executor->node+port方法获为所有Topology计算新的调度,返回topology->executor->node+port.
- 调用basic-supervisor-details-map从Zookeeper中获取所有SupervisorInfo信息,返回<supervisor-id,supervisorDetails>集合。
- 对第8步返回的结果集中的每一项进行遍历构造新的Assignment对象集合new-assignments,Assigmnet定义如下:        
 (defrecord Assignent [master-code-dir node->host executor->node+port executor->start-time-secs])
 master-code-dir:Nimbus在本地保存Topology信息路劲,主要包括stormjar.jar、stormcode.ser、stormconf.ser.
 node->host:该Topology分配的<supervisor-id,hostname>集合.
 executor->node+port:该Topology中executor的分配情况,node为supervisor-id,port为端口号。
 executor->start-time-secs:该Topology对用的supervisor的启动时间.
- 比较new-assignments与existing-assignments中的每一项是否有差异,如果没有就打印一条提示信息,如果有就将该Topology在Zookeeper中保存的调度结果更新为new-assignments。
- 计算new-assignment中的每一项新增加的slot并进行分配。(新增的solt通过new-assignment中的node+port减去existing-assignment中的node+port得到,返回为<topology-id,WorkerSlot>集合)        
 WorkerSlot格式为{ nodeId port }
功能总结:      
获取已分配资源的Topology的任务分配情况<storm-id,Assigment>集合(existing-assignments),获取活跃的Topology信息<storm-id,TopologyDetails>集合创建topologies对象。然后调用compute-new-topology->executor->node+port方法获为所有Topology计算新的调度,返回topology->executor->node+port再构造Assigmnet对象集。
compute-new-topology->executor->node+port
函数原型:
| 1 | defn compute-new-topology->executor->node+port [nimbus existing-assignments topologies scratch-topology-id] | 
参数说明:      
nimbus:nimbus-data对象。       
existing-assignments:当前已经分配的的任务,格式<topology-id,Assignment>。       
Topologies:当前活跃的Topology,格式<storm-id,TopologyDetails>.       
scratch-topology-id:需要重新调度的topology-id.
- 调用compute-topology->executors方法根据existing-assignments中的topology-id获取<topology-id,executors>集合,与调用compute-executors方法效果作用一样。
- 调用update-all-hearbeats!更新上一步中executor中的心跳信息.
- 调用compute-topology->alive-executors获取<topology-id,alive-executors>集合,每个topology-id对应的活跃的executor.
- 调用compute-supervisor->dead-ports获取<supervisor-id,dead-ports>集合。
- 调用compute-topology->scheduler-assignment获取<topology-id,Scheduler-AssignmentImpl>集合.(topology-id对用的任务分配情况Scheduler-AssignmentImpl == <ExecutorDetails,WorkerSlot>).
- 根据参数topologies中的topology-id进行条件过滤,该topology中所有executor为空或者topology中的所有executor不等于Topology中活跃的executor或者该Topology的num-use-workers小于其指定的num-worker,过滤后的结果集群赋值给missing-assignmnet-topologies.
- 调用all-scheduling-slots方法获取<node-id,port>集合。
- 调用read-all-supervisor-details方法获取<supervisor-id,supervisorDetails>集合。
- 根据参数nimbus、第5步、第8步的结果集构造Cluster对象。
- 调用nimbus中的scheduler方法进行任务调度。
- 从Cluster对象中获取重新调度完之后的所有Assignments作为new-scheduler-assignment,格式为<topology-id,SchedulerAssignment>集合。
- 调用compute-topology->executor->node+port将第11步的结果集转换为<topology-id,{executor[node port]}>集合。
- 调用basic-supervisor-details-map将Zookeeper中记录的所有SupervisorInfo都转换为SupervisorDetails,返回<supervisor-id,SuperviosrDetails>集合.
流程图:

compute-executor
函数原型:
| 1 | defn- compute-executors [nimbus storm-id] | 
函数实现说明:
- 获取storm-id(topology-id)对用的stormBase中component-executors形象(每个组件的并行度)。
- 获取storm-id对应的storm-conf配置。
- 获取storm-id对应Topology.
- 调用storm-task-info获取<task-id,component-id>集合,其中task-id对该Topology的所有组件是全局递增的。
- 将第4步的结果集转换为<component-id,tasks>并按照升序排序。
- 将第1步的结果集<component-id,parallelism>与第5步的结果集进行join得到<component-id,[parallelism,tasks]>集合.
- 对第6步的结果集中的每一项进行处理,将tasks集合均匀分布到数目为parallelism的分区上。
功能总结:
获取storm-id对应Topology所有组件的并行度(线程数),获取该Topology中各组件TOPOLOGY_TASK信息,最后的结果使每个线程中均匀分布多个task运行。
Storm系列(五)架构分析之Nimbus启动过程的更多相关文章
- Nimbus<一>Storm系列(五)架构分析之Nimbus启动过程
		启动流程图 mk-assignments 功能:对当前集群中所有Topology进行新一轮的任务调度. 实现源码路径: \apache-storm-0.9.4\storm-core\src\clj\b ... 
- Storm系列(九)架构分析之Supervisor-同步Nimbus的事件线程
		Supervisor由三个线程组成,一个计时器线程和两个事件线程. 计时器线程负责维持心跳已经更新Zookeeper中的状态,还负责每隔一定的时间将事件线程需要执行的事件添加到其对应的队列中. 两个事 ... 
- Storm系列(十三)架构分析之Worker-维护ZMQ连接
		Worker根据Topology的定义及分配到自身的任务情况,计算出发出的消息被那些Task接收,由于Worker上分配的任务可能被调整,因此Worker需要定时的更新这些连接信息. ZMQ连接信息更 ... 
- Storm系列(十一)架构分析之Supervisor-管理Worker进程的事件线程
		处理流程: 方法原型: (defn sync-processes [supervisor]) 函数说明: Supervisor是一个supervisor-data对象. 从local-state中 ... 
- Storm系列(七)架构分析之Scheduler-调度器[DefaultScheduler]
		Storm默认的任务调度器.实现如下: 1 (defn –prepare [this conf]) 2 (defn –schedule [this ^Topologies topologies ^ ... 
- Storm系列(六)架构分析之Scheduler-调度器[EventScheduler]
		任务调度接口定义: 1 IScheduler{ 2 // conf为当前nimbus的stormp配置 3 void prepare(Map conf); // 初始化 4 // to ... 
- Nimbus<三>Storm源码分析--Nimbus启动过程
		Nimbus server, 首先从启动命令开始, 同样是使用storm命令"storm nimbus”来启动看下源码, 此处和上面client不同, jvmtype="-serv ... 
- Linux第三周——跟踪分析内核的启动过程
		跟踪分析内核的启动过程实验 张潇月<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 这周主要学习的是对内核 ... 
- Netty源码分析之客户端启动过程
		一.先来看一下客户端示例代码. public class NettyClientTest { public void connect(int port, String host) throws Exc ... 
随机推荐
- 技术名词解释——Camus
			由LinkedIn公司开发的消息队列同步框架,提供将Kafka(一种消息队列框架)的数据装载到Hadoop分布式文件系统(HDFS)的功能. 英文版原文出处:http://docs.confluent ... 
- Makefile 多目录自动编译
			适用于多目录结构 C 工程自动编译. makefile 分成三类: 1. 工程根目录 makefile : 这个makefile执行分成两个阶段 a)递归进入每个子目录, 逐个执行子目录里面的 ma ... 
- TypeScript学习指南--目录索引
			关于TypeScript: TypeScript是一种由微软开发的自由和开源的编程语言.它是JavaScript的一个超集,而且本质上向这个语言添加了可选的静态类型和基于类的面向对象编程. TypeS ... 
- 中国.net域名网站的“前世今生”,那些年的光辉
			1987年9月的一天,中国的第一封电子邮件成功发出,邮件的内容大致是“跨越长城,走向世界”,在当时,没有人会想到十年后中国的互联网开始萌芽,并发展成今天的繁荣.1994年,“巴黎统筹委员会”的解散消除 ... 
- 如何获取HttpServletResponse里面的内容
			背景:在SPRING 框架之中, 有一个服务端需要提供多种形态的服务,这里的多种形态只是返回值得展示形式(其实 数据内在逻辑完全一样), 比如: 形式1: JSONP({“key1”: value ... 
- unity 导出 android安装包配置方案
			原地址:http://blog.csdn.net/u012085988/article/details/17393111 1.jdk本人安装的是win32版的(虽然系统是64位的.但听说装64位的导出 ... 
- 《sql注入攻击与防御 第2版》的总结 之 如何确定有sql注入漏洞
			看完<sql注入攻击与防御 第2版>后,发现原来自己也能黑网站了,就一个字:太爽了. 简单总结一下入侵步骤: 1.确定是否有sql注入漏洞 2.确定数据库类型 3.组合sql语句,实施渗透 ... 
- 152. Maximum Product Subarray
			题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ... 
- Android DownloadThread.run()学习
			android系统的下载代码写的很好,考虑的比较全面,值得我们学习.DownloadThread是其中执行下载的部分,下面从run进行研究. run(){ 一上来会设置一下下载线程的优先级:THREA ... 
- IPv6 tutorial – Part 8: Special addresses
			https://4sysops.com/archives/ipv6-tutorial-part-8-special-addresses/ The special IPv6 addresses disc ... 
