Spark分析之Standalone运行过程分析
一、集群启动过程--启动Master
$SPARK_HOME/sbin/start-master.sh
start-master.sh脚本关键内容:
spark-daemon.sh start org.apache.spark.deploy.master.Master 1 --ip $SPARK_MASTER_IP --port $SPARK_MASTER_PORT --webui-port $SPARK_MASTER_WEBUI_PORT
日志信息:$SPARK_HOME/logs/
// :: INFO Remoting: Remoting started; listening on addresses :[akka.tcp://sparkMaster@hadoop000:7077]
// :: INFO master.Master: Starting Spark master at spark://hadoop000:7077
// :: INFO server.Server: jetty-.y.z-SNAPSHOT
// :: INFO server.AbstractConnector: Started SelectChannelConnector@0.0.0.0:
// :: INFO ui.MasterWebUI: Started MasterWebUI at http://hadoop000:8080
// :: INFO master.Master: I have been elected leader! New state: ALIVE
二、集群启动过程--启动Worker
$SPARK_HOME/sbin/start-slaves.sh
start-slaves.sh脚本关键内容:
spark-daemon.sh start org.apache.spark.deploy.worker.Worker master-spark-URL
Worker运行时,需要注册到指定的master url,这里就是spark://hadoop000:7077
Worker启动之后主要做了两件事情:
1)将自己注册到Master(RegisterWorker);
2)定期发送心跳信息给Master;
Worker向Master发送注册信息:
Worker.scala
==>preStart
==>registerWithMaster
==>tryRegisterAllMasters
==> actor ! RegisterWorker(workerId, host, port, cores, memory, webUi.boundPort, publicAddress)
Master侧收到RegisterWorker通知:
Master.scala
==>case RegisterWorker(id, workerHost, workerPort, cores, memory, workerUiPort, publicAddress) => {
val worker = new WorkerInfo(id, workerHost, workerPort, cores, memory,
sender, workerUiPort, publicAddress)
if (registerWorker(worker)) {
persistenceEngine.addWorker(worker)
sender ! RegisteredWorker(masterUrl, masterWebUiUrl) //注册成功后向Worker发送注册成功信息
schedule()
}
}
Worker在收到Master发来的注册成功信息后,定期向Master发送心跳信息
Worker.scala
==>case SendHeartbeat =>
masterLock.synchronized {if (connected) { master ! Heartbeat(workerId) }
}
Master在接收到Worker发送来的心跳信息后更新最后一次心跳时间
Master.scala
==>case Heartbeat(workerId) => {
idToWorker.get(workerId) match {
case Some(workerInfo) =>
workerInfo.lastHeartbeat = System.currentTimeMillis()
}
}
Master定期移除超时未发送心跳信息给Master的Worker节点
Master.scala
==>preStart
==>CheckForWorkerTimeOut
==>case CheckForWorkerTimeOut => {timeOutDeadWorkers()} //Check for, and remove, any timed-out workers
日志信息:$SPARK_HOME/logs/
Master部分日志信息:
14/07/22 13:41:36 INFO master.Master: Registering worker hadoop000:48343 with 1 cores, 2.0 GB RAM
Worker部分日志信息:
14/07/22 13:41:35 INFO Worker: Starting Spark worker hadoop000:48343 with 1 cores, 2.0 GB RAM
14/07/22 13:41:35 INFO Worker: Spark home: /home/spark/app/spark-1.0.1-bin-2.3.0-cdh5.0.0
14/07/22 13:41:35 INFO WorkerWebUI: Started WorkerWebUI at http://hadoop000:8081
14/07/22 13:41:35 INFO Worker: Connecting to master spark://hadoop000:7077...
14/07/22 13:41:36 INFO Worker: Successfully registered with master spark://hadoop000:7077
三、Application提交过程
A、提交Application
运行spark-shell: $SPARK_HOME/bin/spark-shell --master spark://hadoop000:7077
日志信息:$SPARK_HOME/work
spark-shell属于application,在启动SparkContext的createTaskScheduler创建SparkDeploySchedulerBackend的过程中创建
client = new AppClient(sc.env.actorSystem, masters, appDesc, this, conf)
client.start()
会向Master发送RegisterApplication请求
AppClient.scala
==>preStart
==>registerWithMaster
==>tryRegisterAllMasters
==>actor ! RegisterApplication(appDescription)
B、 Master处理RegisterApplication的请求
在Master侧其处理的分支是RegisterApplication;Master在收到RegisterApplication请求之后,Master进行调度:如果有worker已经注册上来,发送LaunchExecutor指令给相应worker
Master.scala
==>case RegisterApplication(description) => {
logInfo("Registering app " + description.name)
val app = createApplication(description, sender)
registerApplication(app)
logInfo("Registered app " + description.name + " with ID " + app.id)
persistenceEngine.addApplication(app)
sender ! RegisteredApplication(app.id, masterUrl)
schedule()
}
==>schedule
==>launchExecutor(worker, exec)
==> worker.addExecutor(exec)
worker.actor ! LaunchExecutor(masterUrl,exec.application.id, exec.id, exec.application.desc, exec.cores, exec.memory)
exec.application.driver ! ExecutorAdded(exec.id, worker.id, worker.hostPort, exec.cores, exec.memory)
C、启动Executor
Worker在收到LaunchExecutor指令之后,会启动Executor进程
Worker.scala
==>case LaunchExecutor(masterUrl, appId, execId, appDesc, cores_, memory_) =>
logInfo("Asked to launch executor %s/%d for %s".format(appId, execId, appDesc.name))
val manager = new ExecutorRunner(appId, execId, appDesc, cores_, memory_,
self, workerId, host,
appDesc.sparkHome.map(userSparkHome => new File(userSparkHome)).getOrElse(sparkHome),
workDir, akkaUrl, ExecutorState.RUNNING)
executors(appId + "/" + execId) = manager
manager.start()
coresUsed += cores_
memoryUsed += memory_
masterLock.synchronized {master ! ExecutorStateChanged(appId, execId, manager.state, None, None)}
}
D、注册Executor
启动的Executor进程会根据启动时的入参,将自己注册到Driver中的SchedulerBackend
SparkDeploySchedulerBackend.scala
==>preStart (CoarseGrainedSchedulerBackend)
==> case RegisterExecutor(executorId, hostPort, cores) =>
logInfo("Registered executor: " + sender + " with ID " + executorId)
sender ! RegisteredExecutor(sparkProperties)
executorActor(executorId) = sender
executorHost(executorId) = Utils.parseHostPort(hostPort)._1
totalCores(executorId) = cores
freeCores(executorId) = cores
executorAddress(executorId) = sender.path.address
addressToExecutorId(sender.path.address) = executorId
totalCoreCount.addAndGet(cores)
makeOffers() CoarseGrainedExecutorBackend.scala
case RegisteredExecutor(sparkProperties) =>
ogInfo("Successfully registered with driver")
executor = new Executor(executorId, Utils.parseHostPort(hostPort)._1, sparkProperties,false)
executor日志信息位置:控制台/$SPARK_HOME/logs
E、运行Task
示例代码:
sc.textFile("hdfs://hadoop000:8020/hello.txt").flatMap(_.split('\t')).map((_,1)).reduceByKey(_+_).collect
SchedulerBackend收到Executor的注册消息之后,会将提交到的Spark Job分解为多个具体的Task,然后通过LaunchTask指令将这些Task分散到各个Executor上真正的运行。
CoarseGrainedSchedulerBackend.scala
def makeOffers() {
launchTasks(scheduler.resourceOffers(
executorHost.toArray.map {case (id, host) => new WorkerOffer(id, host, freeCores(id))}))
} ==>executorActor(task.executorId) ! LaunchTask(new SerializableBuffer(serializedTask))
==>CoarseGrainedSchedulerBackend case LaunchTask(data) =>
if (executor == null) {
logError("Received LaunchTask command but executor was null")
System.exit(1)
} else {
val ser = SparkEnv.get.closureSerializer.newInstance()
val taskDesc = ser.deserialize[TaskDescription](data.value)
logInfo("Got assigned task " + taskDesc.taskId)
executor.launchTask(this, taskDesc.taskId, taskDesc.serializedTask)
}
Master部分日志信息:
14/07/22 15:25:27 INFO master.Master: Registering app Spark shell
14/07/22 15:25:27 INFO master.Master: Registered app Spark shell with ID app-20140722152527-0001
14/07/22 15:25:27 INFO master.Master: Launching executor app-20140722152527-0001/0 on worker worker-20140722134135-hadoop000-48343
Worker部分日志信息:
Spark assembly has been built with Hive, including Datanucleus jars on classpath
14/07/22 15:25:27 INFO Worker: Asked to launch executor app-20140722152527-0001/0 for Spark shell
Spark assembly has been built with Hive, including Datanucleus jars on classpath
14/07/22 15:25:28 INFO ExecutorRunner: Launch command: "java" "-cp" "::/home/spark/app/spark-1.0.1-bin-2.3.0-cdh5.0.0/conf:/home/spark/app/spark-1.0.1-bin-2.3.0-cdh5.0.0/lib/spark-assembly-1.0.1-hadoop2.3.0-cdh5.0.0.jar:/home/spark/app/spark-1.0.1-bin-2.3.0-cdh5.0.0/lib/datanucleus-rdbms-3.2.1.jar:/home/spark/app/spark-1.0.1-bin-2.3.0-cdh5.0.0/lib/datanucleus-core-3.2.2.jar:/home/spark/app/spark-1.0.1-bin-2.3.0-cdh5.0.0/lib/datanucleus-api-jdo-3.2.1.jar" "-XX:MaxPermSize=128m" "-Xms1024M" "-Xmx1024M" "org.apache.spark.executor.CoarseGrainedExecutorBackend" "akka.tcp://spark@hadoop000:50515/user/CoarseGrainedScheduler" "0" "hadoop000" "1" "akka.tcp://sparkWorker@hadoop000:48343/user/Worker" "app-20140722152527-0001"
控制台部分日志信息:
14/07/22 15:25:31 INFO cluster.SparkDeploySchedulerBackend: Registered executor: Actor[akka.tcp://sparkExecutor@hadoop000:45150/user/Executor#-791712793] with ID 0
14/07/22 15:25:31 INFO CoarseGrainedExecutorBackend: Successfully registered with driver
每当有新的application注册到master,master都要调度schedule函数将application发送到相应的worker,在对应的worker启动相应的ExecutorBackend,最终的Task就运行在ExecutorBackend中。
Spark分析之Standalone运行过程分析的更多相关文章
- Spark分析之SparkContext启动过程分析
SparkContext作为整个Spark的入口,不管是spark.sparkstreaming.spark sql都需要首先创建一个SparkContext对象,然后基于这个SparkContext ...
- Spark standalone运行模式
Spark Standalone 部署配置 Standalone架构 手工启动一个Spark集群 https://spark.apache.org/docs/latest/spark-standalo ...
- Task的运行过程分析
Task的运行过程分析 Task的运行通过Worker启动时生成的Executor实例进行, caseRegisteredExecutor(sparkProperties)=> logInfo( ...
- 【Spark Core】任务运行机制和Task源代码浅析1
引言 上一小节<TaskScheduler源代码与任务提交原理浅析2>介绍了Driver側将Stage进行划分.依据Executor闲置情况分发任务,终于通过DriverActor向exe ...
- [大数据从入门到放弃系列教程]第一个spark分析程序
[大数据从入门到放弃系列教程]第一个spark分析程序 原文链接:http://www.cnblogs.com/blog5277/p/8580007.html 原文作者:博客园--曲高终和寡 **** ...
- Spark新手入门——3.Spark集群(standalone模式)安装
主要包括以下三部分,本文为第三部分: 一. Scala环境准备 查看二. Hadoop集群(伪分布模式)安装 查看三. Spark集群(standalone模式)安装 Spark集群(standalo ...
- 五、standalone运行模式
在上文中我们知道spark的集群主要有三种运行模式standalone.yarn.mesos,其中常被使用的是standalone和yarn,本文了解一下什么是standalone运行模式,它的运行流 ...
- Netty3 源代码分析 - NIO server绑定过程分析
Netty3 源代码分析 - NIO server绑定过程分析 一个框架封装的越好,越利于我们高速的coding.可是却掩盖了非常多的细节和原理.可是源代码可以揭示一切. 服务器端代码在指定 ...
- Spark 中 RDD的运行机制
1. RDD 的设计与运行原理 Spark 的核心是建立在统一的抽象 RDD 之上,基于 RDD 的转换和行动操作使得 Spark 的各个组件可以无缝进行集成,从而在同一个应用程序中完成大数据计算任务 ...
随机推荐
- Redis学习第五课:Redis Set类型及操作
Set是集合,它是string类型的无序集合.set是通过hash table实现的,添加.删除和查找的复杂度都是O(1). 对集合我们可以取并集.交集.差集.通过这些操作我们可以实现SNS中的好友推 ...
- antd中fomr中resetFields清空输入框
1.如果没有initValue的情况下,直接使用resetFields可以清空文本框的值 2.如果是有initValue的情况下,直接使用resetFields方法会直接重置为initValue的值 ...
- Mac 活动监视器 闪退 pro发热耗电过快问题解决,亲测可用解决
该解决办法转载 Mac 活动监视器 闪退 pro发热耗电过快问题解决 这个月新买了mac,升级了系统,出现CPU发热,高负荷运转问题,始终找不到问题解决办法, ,这个过程太痛苦了,也不知道是什么原因. ...
- magento -- 给Magento提速之缓存上的探索
依然在为Magento提速做努力,除了自带的缓存和编译,之前的所作的很多努力都是从减少JS,Css,图片等载入时间入手,而对页面载入耗时最早有时也是最大的一部分--获取页面数据没有做太多处理,以gap ...
- OK335xS U-boot GPIO control hacking
/**************************************************************************************** * OK335xS ...
- OK335xS GPMC nand device register hacking
/********************************************************************************* * OK335xS GPMC na ...
- GPIO口的输入输出模式
1.浮空输入 GPIO_Mode_IN_FLOATING 2.带上拉输入 GPIO_Mode_IPU 3.带下拉输入 GPIO_Mode_IPD 4.模拟输入 ...
- java8 array、list操作 汇【2】)- (Function,Consumer,Predicate,Supplier)应用
static class UserT { String name; public UserT(String zm) { this.name=zm; } public String getName() ...
- python 常见的内置函数
内置函数 接下来,我们就一起来看看python里的内置函数.截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是python提供给你直接可以拿来使用的所有函数.这 ...
- oracle mysql sql serve where in 语句的不同
类似这样的语句在mysql oracle 是可以执行成功的, select * from classfirst where (classid ,classname) not in (select c ...