How to establish a connection between the master, worker, and application of Spark analytics

Source: Internet
Author: User

 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 ===============================================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.