Spark维护Executor列表

本文深入解析了Spark中Executor与Driver间的心跳机制。详细介绍了Driver端如何通过HeartbeatReceiver组件定期检查并移除失效的Executor,同时阐述了Executor端如何定时向Driver发送心跳信号以维持连接的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spark任务启动后,Executor会定时向Driver发送心跳信息,Driver端通过HeartbeatReceiver处理心跳信息,HeartbeatReceiver会在启动前,生成一个定时线程维护可用Executor列表:

  override def onStart(): Unit = {
    timeoutCheckingTask = eventLoopThread.scheduleAtFixedRate(new Runnable {
      override def run(): Unit = Utils.tryLogNonFatalError {
        Option(self).foreach(_.ask[Boolean](ExpireDeadHosts))
      }
    }, 0, checkTimeoutIntervalMs, TimeUnit.MILLISECONDS)
  }

checkTimeoutIntervalMs默认为60s,可以通过设置【spark.storage.blockManagerTimeoutIntervalMs】或【spark.network.timeoutInterval】两个属性设置

每隔60s执行一次终止失效Executor的操作

失效的Executor的判断标准是【当前时间-上一次心跳时间】>指定的时间,默认为120s,即如果120s还没有收到Executor发过来的心跳信息,则认为该Executor失效,可以通过设置【spark.storage.blockManagerSlaveTimeoutMs】或【spark.network.timeout】设置。


Executor发送心跳:

/**
   * Schedules a task to report heartbeat and partial metrics for active tasks to driver.
   */
  private def startDriverHeartbeater(): Unit = {
    val intervalMs = conf.getTimeAsMs("spark.executor.heartbeatInterval", "10s")

    // Wait a random interval so the heartbeats don't end up in sync
    val initialDelay = intervalMs + (math.random * intervalMs).asInstanceOf[Int]

    val heartbeatTask = new Runnable() {
      override def run(): Unit = Utils.logUncaughtExceptions(reportHeartBeat())
    }
    heartbeater.scheduleAtFixedRate(heartbeatTask, initialDelay, intervalMs, TimeUnit.MILLISECONDS)
  }

IntervalMs默认为10s,也就是每10s,Executor会向Driver发送一次心跳信息,可以通过属性【spark.executor.heartbeatInterval】设置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值