From 10a154cedd2dd24efc7c8520a5e5b01ef5304ed8 Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Tue, 27 Dec 2016 12:30:35 -0800 Subject: [PATCH] YARN-5969. FairShareComparator: Cache value of getResourceUsage for better performance. (zhangshilong via kasha) (cherry picked from commit c3973e7080bf71b57ace4a6adf4bb43f3c5d35b5) --- .../fair/policies/FairSharePolicy.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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/policies/FairSharePolicy.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/policies/FairSharePolicy.java index f120f0fc374..d47ea07c655 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/policies/FairSharePolicy.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/policies/FairSharePolicy.java @@ -79,29 +79,32 @@ public class FairSharePolicy extends SchedulingPolicy { double minShareRatio1, minShareRatio2; double useToWeightRatio1, useToWeightRatio2; double weight1, weight2; + //Do not repeat the getResourceUsage calculation + Resource resourceUsage1 = s1.getResourceUsage(); + Resource resourceUsage2 = s2.getResourceUsage(); Resource minShare1 = Resources.min(RESOURCE_CALCULATOR, null, s1.getMinShare(), s1.getDemand()); Resource minShare2 = Resources.min(RESOURCE_CALCULATOR, null, s2.getMinShare(), s2.getDemand()); boolean s1Needy = Resources.lessThan(RESOURCE_CALCULATOR, null, - s1.getResourceUsage(), minShare1); + resourceUsage1, minShare1); boolean s2Needy = Resources.lessThan(RESOURCE_CALCULATOR, null, - s2.getResourceUsage(), minShare2); - minShareRatio1 = (double) s1.getResourceUsage().getMemorySize() + resourceUsage2, minShare2); + minShareRatio1 = (double) resourceUsage1.getMemorySize() / Resources.max(RESOURCE_CALCULATOR, null, minShare1, ONE).getMemorySize(); - minShareRatio2 = (double) s2.getResourceUsage().getMemorySize() + minShareRatio2 = (double) resourceUsage2.getMemorySize() / Resources.max(RESOURCE_CALCULATOR, null, minShare2, ONE).getMemorySize(); weight1 = s1.getWeights().getWeight(ResourceType.MEMORY); weight2 = s2.getWeights().getWeight(ResourceType.MEMORY); if (weight1 > 0.0 && weight2 > 0.0) { - useToWeightRatio1 = s1.getResourceUsage().getMemorySize() / weight1; - useToWeightRatio2 = s2.getResourceUsage().getMemorySize() / weight2; + useToWeightRatio1 = resourceUsage1.getMemorySize() / weight1; + useToWeightRatio2 = resourceUsage2.getMemorySize() / weight2; } else { // Either weight1 or weight2 equals to 0 if (weight1 == weight2) { // If they have same weight, just compare usage - useToWeightRatio1 = s1.getResourceUsage().getMemorySize(); - useToWeightRatio2 = s2.getResourceUsage().getMemorySize(); + useToWeightRatio1 = resourceUsage1.getMemorySize(); + useToWeightRatio2 = resourceUsage2.getMemorySize(); } else { // By setting useToWeightRatios to negative weights, we give the // zero-weight one less priority, so the non-zero weight one will