master.prestart () {webui.bind () Context.system.scheduler.schedule ( Span style= "color: #800080;" >0 Millis, Worker_timeout millis, Self, checkforworkertimeout) // Timed task detects if a dead worker needs to remove the case checkforworkertimeout => {timeoutdeadworkers ()} /* * Check for, a nd remove, any timed-out workers */ def Timeoutdeadworkers () {... if (Worker.lastheartbeat < CurrentTime-((reaper_iterations + 1 ) * Worker_timeout) {workers -= WORKER}}}
Worker.prestart () {Overridedef prestart () {webUi=NewWorkerwebui ( This, Workdir, Some (Webuiport)) Webui.bind () Registerwithmaster ()//register the worker to master} def tryregisterallmasters () { for(MasterUrl <-masterurls) {Loginfo ("Connecting to Master"+ MasterUrl +"...") Val actor=context.actorselection (Master.toakkaurl (MasterUrl)) actor!Registerworker (Workerid, host, port, cores, memory, Webui.boundport, publicaddress) }}
master.scala case Registerworker () {persistenceengine.addworker (worker) Sender ! Registeredworker (MasterUrl, Masterwebuiurl) // schedule () //the next section of the dispatch section parse
worker.scala case Registeredworker () {Registered = true Context.system.scheduler.schedule ( 0 Millis, Heartbeat_millis Millis, Self, sendheartbeat) // worker registered successfully, Periodically sends heartbeat information to master case Sendheartbeat => masterlock.synchronized { If (connected) {Master! Heartbeat (Workerid)}}
Master.scala Case Heartbeat (Workerid) = {idtoworker. Get (Workerid) match { case Some (workerinfo)= System.currenttimemillis () // update the last time that the worker sent the heartbeat information Case None = = logwarning ("" + Workerid)}}
================= the above steps to complete the worker-to-master connection ===============================================
Sparkcontext at startup:
Sparkcontext.createtaskscheduler () ==>new sparkdeployschedulerbackend () ==> Create Appclient and start ==>clientactor.prestart (): Registerwithmaster () {actor! RegisterApplication (appdescription)} // initiate registerapplication event to master
Master.scala Case =! Registeredapplication (App.id, MasterUrl) // Initiating a registeredapplication event to a worker indicates that the application has registered successfully schedule ()}
======================= The above steps complete the application to master connection ===============================================