• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > spark core源码分析7 Executor的运行,sparkexecutor

spark core源码分析7 Executor的运行,sparkexecutor

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含spark executor,spark executor cores,executor,executorservice,threadpoolexecutor等服务器相关知识,网友希望可以进行参考

spark core源码分析7 Executor的运行,sparkexecutor


实际任务的运行,都是通过Executor类来执行的。这一节,我们只介绍Standalone模式。

源码位置:org.apache.spark.executor.CoarseGrainedExecutorBackend

private def run(
    driverUrl: String,
    executorId: String,
    hostname: String,
    cores: Int,
    appId: String,
    workerUrl: Option[String],
    userClassPath: Seq[URL]) {
  SignalLogger.register(log)
  SparkHadoopUtil.get.runAsSparkUser { () =>
    // Debug code
    Utils.checkHost(hostname)

    // Bootstrap to fetch the driver's Spark properties.
    val executorConf = new SparkConf//创建Executor sparkConf
    val port = executorConf.getInt("spark.executor.port", 0)
    //创建akkaRpcEnv,内部包含actorSystem
    val fetcher = RpcEnv.create(
      "driverPropsFetcher",
      hostname,
      port,
      executorConf,
      new SecurityManager(executorConf))
    //获取driver的ActorRef
    val driver = fetcher.setupEndpointRefByURI(driverUrl)
    val props = driver.askWithRetry[Seq[(String, String)]](RetrieveSparkProps) ++
      Seq[(String, String)](("spark.app.id", appId))
    fetcher.shutdown()

    // Create SparkEnv using properties we fetched from the driver.
    val driverConf = new SparkConf()//创建driver sparkConf
    for ((key, value) <- props) {
      // this is required for SSL in standalone mode
      if (SparkConf.isExecutorStartupConf(key)) {
        driverConf.setIfMissing(key, value)
      } else {
        driverConf.set(key, value)
      }
    }
    if (driverConf.contains("spark.yarn.credentials.file")) {
      logInfo("Will periodically update credentials from: " +
        driverConf.get("spark.yarn.credentials.file"))
      SparkHadoopUtil.get.startExecutorDelegationTokenRenewer(driverConf)
    }
    //创建Executor 的sparkEnv,下面分析
    val env = SparkEnv.createExecutorEnv(
      driverConf, executorId, hostname, port, cores, isLocal = false)

    // SparkEnv sets spark.driver.port so it shouldn't be 0 anymore.
    val boundPort = env.conf.getInt("spark.executor.port", 0)
    assert(boundPort != 0)
    // Start the CoarseGrainedExecutorBackend endpoint.
    val sparkHostPort = hostname + ":" + boundPort
    //这里创建Executor 的ActorRef,onStart方法主要是向driver注册Executor,见下面分析
    env.rpcEnv.setupEndpoint("Executor", new CoarseGrainedExecutorBackend(
      env.rpcEnv, driverUrl, executorId, sparkHostPort, cores, userClassPath, env))
    //这个workerWatcher我没看出起什么作用的
    workerUrl.foreach { url =>
      env.rpcEnv.setupEndpoint("WorkerWatcher", new WorkerWatcher(env.rpcEnv, url))
    }
    env.rpcEnv.awaitTermination()
    SparkHadoopUtil.get.stopExecutorDelegationTokenRenewer()
  }
}
先介绍createExecutorEnv,这个与driver端的几乎一样,之前已经介绍过了,这里就介绍一下与driver不同的地方

1、mapOutputTracker在Executor端是MapOutputTrackerWorker对象,mapOutputTracker.trackerEndpoint实际引用的是driver的ActorRef。

2、blockManagerMaster在内部保存的也是driver的ActorRef

3、outputCommitCoordinator.coordinatorRef实际包含的也是driver的ActorRef

现在介绍一下CoarseGrainedExecutorBackend的onStart方法,看它主动干了什么事。

发送RegisterExecutor消息到driver端,注册Executor。成功返回后再向自己发送RegisteredExecutor消息

override def onStart() {
  logInfo("Connecting to driver: " + driverUrl)
  rpcEnv.asyncSetupEndpointRefByURI(driverUrl).flatMap { ref =>
    // This is a very fast action so we can use "ThreadUtils.sameThread"
    driver = Some(ref)
    ref.ask[RegisteredExecutor.type](
      RegisterExecutor(executorId, self, hostPort, cores, extractLogUrls))
  }(ThreadUtils.sameThread).onComplete {
    // This is a very fast action so we can use "ThreadUtils.sameThread"
    case Success(msg) => Utils.tryLogNonFatalError {
      Option(self).foreach(_.send(msg)) // msg must be RegisteredExecutor
    }
    case Failure(e) => logError(s"Cannot register with driver: $driverUrl", e)
  }(ThreadUtils.sameThread)
}
看driver端接收到后如何处理?重点看最后的makeOffers。当由Executor注册上来之后,如果有等待执行的任务,这时就可以开始了。这个方法后续还会用到,且目前还没讲到任务调度的章节,后续再解释。这里只需要知道,Executor注册上来之后,会触发一把任务调度(如果有任务的话)
case RegisterExecutor(executorId, executorRef, hostPort, cores, logUrls) =>
  Utils.checkHostPort(hostPort, "Host port expected " + hostPort)
  if (executorDataMap.contains(executorId)) {
    context.reply(RegisterExecutorFailed("Duplicate executor ID: " + executorId))
  } else {
    logInfo("Registered executor: " + executorRef + " with ID " + executorId)
    context.reply(RegisteredExecutor)//反馈RegisteredExecutor消息到Executor
    addressToExecutorId(executorRef.address) = executorId
    totalCoreCount.addAndGet(cores)//每注册成功一个Executor,就记录总的cores
    totalRegisteredExecutors.addAndGet(1)
    val (host, _) = Utils.parseHostPort(hostPort)
    val data = new ExecutorData(executorRef, executorRef.address, host, cores, cores, logUrls)
    // This must be synchronized because variables mutated
    // in this block are read when requesting executors
    CoarseGrainedSchedulerBackend.this.synchronized {
      executorDataMap.put(executorId, data)
      if (numPendingExecutors > 0) {
        numPendingExecutors -= 1
        logDebug(s"Decremented number of pending executors ($numPendingExecutors left)")
      }
    }
    listenerBus.post(
      SparkListenerExecutorAdded(System.currentTimeMillis(), executorId, data))
    makeOffers()
  }
Executor端接收到之后,创建真正的Executor对象,Executor类是运行任务的接口,里面维护着该Executor进程上的所有任务
case RegisteredExecutor =>
  logInfo("Successfully registered with driver")
  val (hostname, _) = Utils.parseHostPort(hostPort)
  executor = new Executor(executorId, hostname, env, userClassPath, isLocal = false)
至此,Executor端的注册逻辑就介绍完了,后续将结合真正的任务介绍其他的内容。




版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • spark core源码分析7 Executor的运行,sparkexecutor

相关文章

  • Spark On Yarn 详细配置流程
  • MapReduce小文件处理之CombineFileInputFormat实现,mapreducecombine
  • Spark MLlib LDA主题模型(1),mlliblda
  • hive如何应对数据倾斜,hive应对数据倾斜
  • CSR1000V在XenServer的安装和简单使用,csr1000vxenserver
  • Hadoop之——HBase笔记,hadoophbase
  • HDFS概述---namenode的设计详解,hdfs概述---namenode
  • getRequestDispatcher()与sendRedirect()的区别,request.sendredirect
  • Mesos资料收集(持续更新),mesos资料收集
  • Hadoop之——HDFS随笔,hadoophdfs

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • 通过TelnetClient获取Zookeeper监控数据,zookeeperclient
    • Azure云平台学习之路(三)——Cloud Services,azurecloud
    • HDFS学习笔记(2)hdfs_shell &amp; JavaAPI,hdfshdfs_shell
    • spark streaming kafka1.4.1中的低阶api createDirectStream使用总结,directstream
    • Hadoop之——HDFS随笔,hadoophdfs
    • Andrew Ng机器学习课程10补充,andrewng
    • Elasticsearch之Nested Aggregation,elasticsearch
    • HBase RegionServer详解(未完),hbaseregionserver
    • 从Hadoop URL中读取数据,hadoopurl读取数据
    • hive SymlinkTextInputFormat介绍及用法,textinputformat

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有