频道栏目
首页 > 资讯 > 云计算 > 正文

spark-源码-Master与Worker的启动

16-11-12        来源:[db:作者]  
收藏   我要投稿

概述
Spark作为一套高效的分布式运算框架,但是想要更深入的学习它,就要通过分析spark的源码,不但可以更好的帮助理解spark的工作过程,还可以提高对集群的排错能力,本文主要关注的是Spark的Master的启动流程与Worker启动流程。
Master启动
我们启动一个Master是通过Shell命令启动了一个脚本start-master.sh开始的,这个脚本的启动流程如下
start-master.sh -> spark-daemon.sh start org.apache.spark.deploy.master.Master

我们可以看到脚本首先启动了一个org.apache.spark.deploy.master.Master类,启动时会传入一些参数,比如cpu的执行核数,内存大小,app的main方法等
查看Master类的main方法
private[spark] object Master extends Logging {
val systemName = “sparkMaster”
private val actorName = “Master”

//master启动的入口,启动命令里会传入一些参数
def main(argStrings: Array[String]) {
SignalLogger.register(log)
//创建SparkConf
val conf = new SparkConf
//保存参数到SparkConf
val args = new MasterArguments(argStrings, conf)
//创建ActorSystem和Actor
val (actorSystem, , , _) = startSystemAndActor(args.host, args.port, args.webUiPort, conf)
//等待该主Actor结束
actorSystem.awaitTermination()
}

这里主要看startSystemAndActor方法
/**
* Start the Master and return a four tuple of:
* (1) The Master actor system 启动Master的actor system
* (2) The bound port 绑定端口
* (3) The web UI bound port 启动webui和port
* (4) The REST server bound port, if any 启动rest服务和绑定端口
*/
def startSystemAndActor(
host: String,
port: Int,
webUiPort: Int,
conf: SparkConf): (ActorSystem, Int, Int, Option[Int]) = {
val securityMgr = new SecurityManager(conf)

//利用AkkaUtils创建ActorSystem
val (actorSystem, boundPort) = AkkaUtils.createActorSystem(systemName, host, port, conf = conf,
  securityManager = securityMgr)

val actor = actorSystem.actorOf(
  Props(classOf[Master], host, boundPort, webUiPort, securityMgr, conf), actorName)

….
}
}

相关TAG标签
上一篇:MatConvNet包:运行fast_rcnn
下一篇:[收藏]深入浅出存储性能评估方法论
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站