StandaloneAppClient是什么

这篇文章主要介绍“StandaloneAppClient是什么”,在日常操作中,相信很多人在StandaloneAppClient是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”StandaloneAppClient是什么”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

StandaloneAppClient是什么?这个很容易搞混淆。其实StandaloneAppClient不是SparkApplication,它主要是用在ScheduleBackend中的。

独立集群环境中,ScheduleBackend是用的StandaloneScheduleBackend,它继承了CoarseGrainedSchedulerBackend类。

StandaloneScheduleBackend里面用了一个叫StandaloneAppClient的类,这个StandaloneAppClient很具有迷惑性,其实它的主要功能是替换CoarseGrainedSchedulerBackend的资源申请的方法,改为向Master申请资源,我们看看相关代码片段就行了。

先看他启动的时候:

private def tryRegisterAllMasters(): Array[JFuture[_]] = {
      for (masterAddress <- masterRpcAddresses) yield {
        registerMasterThreadPool.submit(new Runnable {
          override def run(): Unit = try {
            if (registered.get) {
              return
            }
            logInfo("Connecting to master " + masterAddress.toSparkURL + "...")
            val masterRef = rpcEnv.setupEndpointRef(masterAddress, Master.ENDPOINT_NAME)
            masterRef.send(RegisterApplication(appDescription, self))
          } catch {
          }
        })
      }
    }

向Master发送RegisterApplication消息,将本appDesc注册给Master,这个和DriverDescription注册到Master是有点区别的。

再比如资源申请的代码:

 def requestTotalExecutors(requestedTotal: Int): Future[Boolean] = {
    if (endpoint.get != null && appId.get != null) {
      endpoint.get.ask[Boolean](RequestExecutors(appId.get, requestedTotal))
    } else {
      logWarning("Attempted to request executors before driver fully initialized.")
      Future.successful(false)
    }
  }

就是向Master发送RequestExecutor消息申请Executor资源。

到此,关于“StandaloneAppClient是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!