Browse Source

YARN-5262. Optimize sending RMNodeFinishedContainersPulledByAMEvent for every AM heartbeat.

Rohith Sharma K S 8 years ago
parent
commit
26b5e6116f

+ 6 - 3
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptImpl.java

@@ -826,9 +826,11 @@ public class RMAppAttemptImpl implements RMAppAttempt, Recoverable {
           }
         }
 
-        finishedContainersSentToAM.putIfAbsent(nodeId, new ArrayList
-              <ContainerStatus>());
-        finishedContainersSentToAM.get(nodeId).addAll(finishedContainers);
+        if (!finishedContainers.isEmpty()) {
+          finishedContainersSentToAM.putIfAbsent(nodeId,
+              new ArrayList<ContainerStatus>());
+          finishedContainersSentToAM.get(nodeId).addAll(finishedContainers);
+        }
       }
 
       return returnList;
@@ -1871,6 +1873,7 @@ public class RMAppAttemptImpl implements RMAppAttempt, Recoverable {
       eventHandler.handle(new RMNodeFinishedContainersPulledByAMEvent(nodeId,
         containerIdList));
     }
+    this.finishedContainersSentToAM.clear();
   }
 
   // Add am container to the list so that am container instance will be

+ 7 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/TestRMAppAttemptTransitions.java

@@ -1444,6 +1444,13 @@ public class TestRMAppAttemptTransitions {
     Assert.assertTrue(applicationAttempt.getJustFinishedContainers().isEmpty());
     Assert.assertEquals(0, getFinishedContainersSentToAM(applicationAttempt)
         .size());
+
+    // verify if no containers to acknowledge to NM then event should not be
+    // triggered. Number of times event invoked is 1 i.e on second pull
+    containerStatuses = applicationAttempt.pullJustFinishedContainers();
+    Assert.assertEquals(0, containerStatuses.size());
+    Mockito.verify(rmnodeEventHandler, times(1))
+        .handle(Mockito.any(RMNodeEvent.class));
   }
 
   private static List<ContainerStatus> getFinishedContainersSentToAM(