From 5205a330b387d2e133ee790b9fe7d5af3cd8bccc Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Wed, 29 Jul 2015 09:42:32 -0700 Subject: [PATCH] YARN-2768. Avoid cloning Resource in FSAppAttempt#updateDemand. (Hong Zhiguo via kasha) --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../hadoop/yarn/util/resource/Resources.java | 14 +++++++++++++- .../scheduler/fair/FSAppAttempt.java | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index be6a50cc6d..910b85c545 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -378,6 +378,9 @@ Release 2.8.0 - UNRELEASED YARN-3259. FairScheduler: Trigger fairShare updates on node events. (Anubhav Dhoot via kasha) + YARN-2768. Avoid cloning Resource in FSAppAttempt#updateDemand. + (Hong Zhiguo via kasha) + BUG FIXES YARN-3197. Confusing log generated by CapacityScheduler. (Varun Saxena diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java index 472811a72a..503d456cfd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/resource/Resources.java @@ -150,7 +150,19 @@ public static Resource multiplyTo(Resource lhs, double by) { public static Resource multiply(Resource lhs, double by) { return multiplyTo(clone(lhs), by); } - + + /** + * Multiply @param rhs by @param by, and add the result to @param lhs + * without creating any new {@link Resource} object + */ + public static Resource multiplyAndAddTo( + Resource lhs, Resource rhs, double by) { + lhs.setMemory(lhs.getMemory() + (int)(rhs.getMemory() * by)); + lhs.setVirtualCores(lhs.getVirtualCores() + + (int)(rhs.getVirtualCores() * by)); + return lhs; + } + public static Resource multiplyAndNormalizeUp( ResourceCalculator calculator,Resource lhs, double by, Resource factor) { return calculator.multiplyAndNormalizeUp(lhs, by, factor); 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 7419446aa5..cfec9157f8 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 @@ -801,8 +801,8 @@ public void updateDemand() { synchronized (this) { for (Priority p : getPriorities()) { for (ResourceRequest r : getResourceRequests(p).values()) { - Resource total = Resources.multiply(r.getCapability(), r.getNumContainers()); - Resources.addTo(demand, total); + Resources.multiplyAndAddTo(demand, + r.getCapability(), r.getNumContainers()); } } }