YARN-9642. Fix Memory Leak in AbstractYarnScheduler caused by timer. Contributed by Bibin A Chundatt.

This commit is contained in:
bibinchundatt 2019-08-26 23:21:33 +05:30
parent 6d7f01c92d
commit d3ce53e507
1 changed files with 10 additions and 2 deletions

View File

@ -148,6 +148,7 @@ public abstract class AbstractYarnScheduler
@VisibleForTesting @VisibleForTesting
Thread updateThread; Thread updateThread;
private final Object updateThreadMonitor = new Object(); private final Object updateThreadMonitor = new Object();
private Timer releaseCache;
/* /*
* All schedulers which are inheriting AbstractYarnScheduler should use * All schedulers which are inheriting AbstractYarnScheduler should use
@ -208,7 +209,7 @@ public void serviceInit(Configuration conf) throws Exception {
nodeTracker.setConfiguredMaxAllocationWaitTime( nodeTracker.setConfiguredMaxAllocationWaitTime(
configuredMaximumAllocationWaitTime); configuredMaximumAllocationWaitTime);
maxClusterLevelAppPriority = getMaxPriorityFromConf(conf); maxClusterLevelAppPriority = getMaxPriorityFromConf(conf);
createReleaseCache(); this.releaseCache = new Timer("Pending Container Clear Timer");
autoUpdateContainers = autoUpdateContainers =
conf.getBoolean(YarnConfiguration.RM_AUTO_UPDATE_CONTAINERS, conf.getBoolean(YarnConfiguration.RM_AUTO_UPDATE_CONTAINERS,
YarnConfiguration.DEFAULT_RM_AUTO_UPDATE_CONTAINERS); YarnConfiguration.DEFAULT_RM_AUTO_UPDATE_CONTAINERS);
@ -230,6 +231,7 @@ protected void serviceStart() throws Exception {
updateThread.start(); updateThread.start();
} }
schedulingMonitorManager.startAll(); schedulingMonitorManager.startAll();
createReleaseCache();
super.serviceStart(); super.serviceStart();
} }
@ -239,6 +241,12 @@ protected void serviceStop() throws Exception {
updateThread.interrupt(); updateThread.interrupt();
updateThread.join(THREAD_JOIN_TIMEOUT_MS); updateThread.join(THREAD_JOIN_TIMEOUT_MS);
} }
//Stop Timer
if (releaseCache != null) {
releaseCache.cancel();
releaseCache = null;
}
schedulingMonitorManager.stop(); schedulingMonitorManager.stop();
super.serviceStop(); super.serviceStop();
} }
@ -635,7 +643,7 @@ private void recoverResourceRequestForContainer(RMContainer rmContainer) {
protected void createReleaseCache() { protected void createReleaseCache() {
// Cleanup the cache after nm expire interval. // Cleanup the cache after nm expire interval.
new Timer().schedule(new TimerTask() { releaseCache.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
clearPendingContainerCache(); clearPendingContainerCache();