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