shameersss1 commented on code in PR #7121:
URL: https://github.com/apache/hadoop/pull/7121#discussion_r1805875185


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java:
##########
@@ -2915,11 +2915,20 @@ private void updateResourceValuesFromConfig(Set<String> 
resourceTypes,
     }
   }
 
+  public static final String MULTI_NODE_SORTING_POLICY_SUFFIX =

Review Comment:
   Can we have javadoc explaining the use of this config



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/MultiNodeSorter.java:
##########
@@ -63,7 +64,7 @@ public class MultiNodeSorter<N extends SchedulerNode> extends 
AbstractService {
 
   public MultiNodeSorter(RMContext rmContext,
       MultiNodePolicySpec policy) {
-    super("MultiNodeLookupPolicy");
+    super("MultiNodeLookupPolicy:"+policy.getPolicyName());

Review Comment:
   nit: super("MultiNodeLookupPolicy: " + policy.getPolicyName());
   



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/policy/MultiComparatorPolicy.java:
##########
@@ -0,0 +1,346 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.policy;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.exceptions.ConfigurationException;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNode;
+import 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.MultiNodeLookupPolicy;
+import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+
+/**
+ * <p>
+ * This class has the following functionality:
+ *
+ * <p>
+ * MultiComparatorPolicy
+ * - manages some common comparators to help sorting nodes by
+ *      allocated/unallocated/total resource, dominant ratio, etc.
+ * - holds sorted nodes list based on the of nodes at given time.
+ * - can be configured with specified comparators.
+ * </p>
+ */
+public class MultiComparatorPolicy<N extends SchedulerNode>
+    implements MultiNodeLookupPolicy<N>, Configurable {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(MultiComparatorPolicy.class);
+  // comparators
+  private static final DominantResourceCalculator DOMINANT_RC =
+      new DominantResourceCalculator();
+  private static final Map<ComparatorKey, Function<SchedulerNode, Comparable>>
+      COMPARATOR_CALCULATORS = Collections.unmodifiableMap(
+      new HashMap<ComparatorKey, Function<SchedulerNode, Comparable>>() {{
+        // for vcores
+        put(ComparatorKey.ALLOCATED_VCORES,
+            obj -> obj.getAllocatedResource().getVirtualCores());
+        put(ComparatorKey.UNALLOCATED_VCORES,
+            obj -> obj.getUnallocatedResource().getVirtualCores());
+        put(ComparatorKey.TOTAL_VCORES,
+            obj -> obj.getTotalResource().getVirtualCores());
+        // for memory
+        put(ComparatorKey.ALLOCATED_MEMORY,
+            obj -> obj.getAllocatedResource().getMemorySize());
+        put(ComparatorKey.UNALLOCATED_MEMORY,
+            obj -> obj.getUnallocatedResource().getMemorySize());
+        put(ComparatorKey.TOTAL_MEMORY,
+            obj -> obj.getTotalResource().getMemorySize());
+        // for resource
+        put(ComparatorKey.ALLOCATED_RESOURCE,
+            SchedulerNode::getAllocatedResource);
+        put(ComparatorKey.UNALLOCATED_RESOURCE,
+            SchedulerNode::getUnallocatedResource);
+        put(ComparatorKey.TOTAL_RESOURCE,
+            SchedulerNode::getTotalResource);
+        // for dominant ratio
+        put(ComparatorKey.DOMINANT_ALLOCATED_RATIO, obj -> Resources
+            .ratio(DOMINANT_RC, obj.getAllocatedResource(),
+                obj.getTotalResource()));
+        // for node ID
+        put(ComparatorKey.NODE_ID, SchedulerNode::getNodeID);
+      }});
+  // conf keys and default values
+  public static final String COMPARATORS_CONF_KEY = "comparators";
+  protected static final List<Comparator> DEFAULT_COMPARATORS = Collections
+      .unmodifiableList(Arrays.asList(

Review Comment:
   So this means the default sorting policy is based on resource utilization, 
the node having less resource utilization will be given priority



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/CapacitySchedulerConfiguration.java:
##########
@@ -2915,11 +2915,20 @@ private void updateResourceValuesFromConfig(Set<String> 
resourceTypes,
     }
   }
 
+  public static final String MULTI_NODE_SORTING_POLICY_SUFFIX =
+      "multi-node-sorting.policy";
+
   @Private public static final String MULTI_NODE_SORTING_POLICIES =
       PREFIX + "multi-node-sorting.policy.names";
 
   @Private public static final String MULTI_NODE_SORTING_POLICY_NAME =
-      PREFIX + "multi-node-sorting.policy";
+      PREFIX + MULTI_NODE_SORTING_POLICY_SUFFIX;
+
+  public static final String MULTI_NODE_SORTING_POLICY_CURRENT_NAME =
+      MULTI_NODE_SORTING_POLICY_NAME + ".current-name";

Review Comment:
   Can we have javadoc explaining the use of this config
   



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/MultiNodeSorter.java:
##########
@@ -74,23 +75,30 @@ public synchronized MultiNodeLookupPolicy<N> 
getMultiNodeLookupPolicy() {
   }
 
   public void serviceInit(Configuration conf) throws Exception {
-    LOG.info("Initializing MultiNodeSorter=" + policySpec.getPolicyClassName()
+    LOG.info("Initializing MultiNodeSorter policyName=" + 
policySpec.getPolicyName()
+        + ", policyClassName=" + policySpec.getPolicyClassName()
         + ", with sorting interval=" + policySpec.getSortingInterval());
-    initPolicy(policySpec.getPolicyClassName());
+    initPolicy(policySpec);
     super.serviceInit(conf);
   }
 
   @SuppressWarnings("unchecked")
-  void initPolicy(String policyName) throws YarnException {
+  void initPolicy(MultiNodePolicySpec policySpec) throws YarnException {
+    String policyName = policySpec.getPolicyName();
+    String policyClassName = policySpec.getPolicyClassName();
     Class<?> policyClass;
     try {
-      policyClass = Class.forName(policyName);
+      policyClass = Class.forName(policyClassName);
     } catch (ClassNotFoundException e) {
       throw new YarnException(
-          "Invalid policy name:" + policyName + e.getMessage());
+          "Invalid policy class name:" + policyClassName + e.getMessage());
     }
+    Configuration policyConf = new Configuration(this.getConfig());

Review Comment:
   Can we reuse config object instead of creating new one ?



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/policy/MultiComparatorPolicy.java:
##########
@@ -0,0 +1,346 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.policy;
+
+import org.apache.hadoop.classification.VisibleForTesting;
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.exceptions.ConfigurationException;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerNode;
+import 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
+import 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.MultiNodeLookupPolicy;
+import org.apache.hadoop.yarn.util.resource.DominantResourceCalculator;
+import org.apache.hadoop.yarn.util.resource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static 
org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration.DOT;
+
+/**
+ * <p>
+ * This class has the following functionality:
+ *
+ * <p>
+ * MultiComparatorPolicy
+ * - manages some common comparators to help sorting nodes by
+ *      allocated/unallocated/total resource, dominant ratio, etc.
+ * - holds sorted nodes list based on the of nodes at given time.
+ * - can be configured with specified comparators.
+ * </p>
+ */
+public class MultiComparatorPolicy<N extends SchedulerNode>
+    implements MultiNodeLookupPolicy<N>, Configurable {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(MultiComparatorPolicy.class);
+  // comparators
+  private static final DominantResourceCalculator DOMINANT_RC =
+      new DominantResourceCalculator();
+  private static final Map<ComparatorKey, Function<SchedulerNode, Comparable>>
+      COMPARATOR_CALCULATORS = Collections.unmodifiableMap(
+      new HashMap<ComparatorKey, Function<SchedulerNode, Comparable>>() {{
+        // for vcores
+        put(ComparatorKey.ALLOCATED_VCORES,
+            obj -> obj.getAllocatedResource().getVirtualCores());
+        put(ComparatorKey.UNALLOCATED_VCORES,
+            obj -> obj.getUnallocatedResource().getVirtualCores());
+        put(ComparatorKey.TOTAL_VCORES,
+            obj -> obj.getTotalResource().getVirtualCores());
+        // for memory
+        put(ComparatorKey.ALLOCATED_MEMORY,
+            obj -> obj.getAllocatedResource().getMemorySize());
+        put(ComparatorKey.UNALLOCATED_MEMORY,
+            obj -> obj.getUnallocatedResource().getMemorySize());
+        put(ComparatorKey.TOTAL_MEMORY,
+            obj -> obj.getTotalResource().getMemorySize());
+        // for resource
+        put(ComparatorKey.ALLOCATED_RESOURCE,
+            SchedulerNode::getAllocatedResource);
+        put(ComparatorKey.UNALLOCATED_RESOURCE,
+            SchedulerNode::getUnallocatedResource);
+        put(ComparatorKey.TOTAL_RESOURCE,
+            SchedulerNode::getTotalResource);
+        // for dominant ratio
+        put(ComparatorKey.DOMINANT_ALLOCATED_RATIO, obj -> Resources
+            .ratio(DOMINANT_RC, obj.getAllocatedResource(),
+                obj.getTotalResource()));
+        // for node ID
+        put(ComparatorKey.NODE_ID, SchedulerNode::getNodeID);
+      }});
+  // conf keys and default values
+  public static final String COMPARATORS_CONF_KEY = "comparators";
+  protected static final List<Comparator> DEFAULT_COMPARATORS = Collections
+      .unmodifiableList(Arrays.asList(
+          new Comparator(ComparatorKey.DOMINANT_ALLOCATED_RATIO,
+              OrderDirection.ASC, COMPARATOR_CALCULATORS
+              .get(ComparatorKey.DOMINANT_ALLOCATED_RATIO)),
+          new Comparator(ComparatorKey.NODE_ID, OrderDirection.ASC,
+              COMPARATOR_CALCULATORS.get(ComparatorKey.NODE_ID))));
+
+  protected Map<String, Set<N>> nodesPerPartition = new ConcurrentHashMap<>();
+  protected List<Comparator> comparators;
+  private Configuration conf;
+
+  public MultiComparatorPolicy() {
+  }
+
+  @Override
+  public void setConf(Configuration conf) {
+    // init comparators
+    this.comparators = DEFAULT_COMPARATORS;
+    if (conf == null) {
+      return;
+    }
+    this.conf = conf;
+    String policyName = conf.get(
+        CapacitySchedulerConfiguration.MULTI_NODE_SORTING_POLICY_CURRENT_NAME);

Review Comment:
   what is the difference between `MULTI_NODE_SORTING_POLICY_CURRENT_NAME` and 
``MULTI_NODE_SORTING_POLICY`



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/placement/MultiNodePolicySpec.java:
##########
@@ -22,14 +22,25 @@
  */
 public class MultiNodePolicySpec {
 
+  private String policyName;
   private String policyClassName;
   private long sortingInterval;
 
-  public MultiNodePolicySpec(String policyClassName, long timeout) {
+  public MultiNodePolicySpec(String policyName, String policyClassName,

Review Comment:
   why both policyName and policyClassName is required here ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to