shirobert 发表于 2018-10-31 10:35:00

hadoop之MapReduce框架TaskTracker端心跳机制分析(源码分析第六篇)

/**  
   * Main service loop.Will stay in this loop forever.
  
   */
  
State offerService() throws Exception {
  
    long lastHeartbeat = System.currentTimeMillis();//上一次发心跳距现在时间
  
   ////此循环主要根据控制完成task个数控制心跳间隔。
  
    while (running && !shuttingDown) {
  
      try {
  
      long now = System.currentTimeMillis();//获得当前时间
  

  
      // accelerate to account for multiple finished tasks up-front
  
      //通过完成的任务数动态控制心跳间隔时间
  
       long remaining =
  
          (lastHeartbeat + getHeartbeatInterval(finishedCount.get())) - now;
  
      while (remaining > 0) {
  
          // sleeps for the wait time or
  
          // until there are *enough* empty slots to schedule tasks
  
          synchronized (finishedCount) {
  
            finishedCount.wait(remaining);
  

  
            // Recompute
  
            now = System.currentTimeMillis();
  
            remaining =
  
            (lastHeartbeat + getHeartbeatInterval(finishedCount.get())) - now;
  

  
            if (remaining
页: [1]
查看完整版本: hadoop之MapReduce框架TaskTracker端心跳机制分析(源码分析第六篇)