Skip to content

Commit d3ce53e

Browse files
committed
YARN-9642. Fix Memory Leak in AbstractYarnScheduler caused by timer. Contributed by Bibin A Chundatt.
1 parent 6d7f01c commit d3ce53e

File tree

1 file changed

+10
-2
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler

1 file changed

+10
-2
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public abstract class AbstractYarnScheduler
148148
@VisibleForTesting
149149
Thread updateThread;
150150
private final Object updateThreadMonitor = new Object();
151+
private Timer releaseCache;
151152

152153
/*
153154
* All schedulers which are inheriting AbstractYarnScheduler should use
@@ -208,7 +209,7 @@ public void serviceInit(Configuration conf) throws Exception {
208209
nodeTracker.setConfiguredMaxAllocationWaitTime(
209210
configuredMaximumAllocationWaitTime);
210211
maxClusterLevelAppPriority = getMaxPriorityFromConf(conf);
211-
createReleaseCache();
212+
this.releaseCache = new Timer("Pending Container Clear Timer");
212213
autoUpdateContainers =
213214
conf.getBoolean(YarnConfiguration.RM_AUTO_UPDATE_CONTAINERS,
214215
YarnConfiguration.DEFAULT_RM_AUTO_UPDATE_CONTAINERS);
@@ -230,6 +231,7 @@ protected void serviceStart() throws Exception {
230231
updateThread.start();
231232
}
232233
schedulingMonitorManager.startAll();
234+
createReleaseCache();
233235
super.serviceStart();
234236
}
235237

@@ -239,6 +241,12 @@ protected void serviceStop() throws Exception {
239241
updateThread.interrupt();
240242
updateThread.join(THREAD_JOIN_TIMEOUT_MS);
241243
}
244+
245+
//Stop Timer
246+
if (releaseCache != null) {
247+
releaseCache.cancel();
248+
releaseCache = null;
249+
}
242250
schedulingMonitorManager.stop();
243251
super.serviceStop();
244252
}
@@ -635,7 +643,7 @@ private void recoverResourceRequestForContainer(RMContainer rmContainer) {
635643

636644
protected void createReleaseCache() {
637645
// Cleanup the cache after nm expire interval.
638-
new Timer().schedule(new TimerTask() {
646+
releaseCache.schedule(new TimerTask() {
639647
@Override
640648
public void run() {
641649
clearPendingContainerCache();

0 commit comments

Comments
 (0)