From 23b5c71729c26c2879e6cc41ce5862af0215d1fa Mon Sep 17 00:00:00 2001 From: Sangjin Lee Date: Wed, 17 Feb 2016 20:55:21 -0800 Subject: [PATCH] YARN-4690. Skip object allocation in FSAppAttempt#getResourceUsage when possible (Ming Ma via sjlee) (cherry picked from commit 7de70680fe44967e2afc92ba4c92f8e7afa7b151) --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../resourcemanager/scheduler/fair/FSAppAttempt.java | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 50c913a77f2..38a672fbfc0 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -2312,6 +2312,9 @@ Release 2.6.5 - UNRELEASED OPTIMIZATIONS + YARN-4690. Skip object allocation in FSAppAttempt#getResourceUsage when + possible (Ming Ma via sjlee) + BUG FIXES Release 2.6.4 - 2016-02-11 diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSAppAttempt.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSAppAttempt.java index 488f34ef7a8..7e0a6935b41 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSAppAttempt.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/FSAppAttempt.java @@ -890,7 +890,12 @@ public class FSAppAttempt extends SchedulerApplicationAttempt public Resource getResourceUsage() { // Here the getPreemptedResources() always return zero, except in // a preemption round - return Resources.subtract(getCurrentConsumption(), getPreemptedResources()); + // In the common case where preempted resource is zero, return the + // current consumption Resource object directly without calling + // Resources.subtract which creates a new Resource object for each call. + return getPreemptedResources().equals(Resources.none()) ? + getCurrentConsumption() : + Resources.subtract(getCurrentConsumption(), getPreemptedResources()); } @Override