p-szucs commented on code in PR #6569:
URL: https://github.com/apache/hadoop/pull/6569#discussion_r1530182598


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/event/multidispatcher/MultiDispatcherExecutor.java:
##########
@@ -0,0 +1,122 @@
+/**
+ * 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.event.multidispatcher;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+
+import org.apache.hadoop.yarn.event.Event;
+import org.apache.hadoop.yarn.util.Clock;
+import org.apache.hadoop.yarn.util.MonotonicClock;
+
+/**
+ * This class contains the thread which process the {@link MultiDispatcher}'s 
events.
+ */
+public class MultiDispatcherExecutor {
+
+  private final Logger log;
+  private final MultiDispatcherConfig config;
+  private final MultiDispatcherExecutorThread[] threads;
+  private final Clock clock = new MonotonicClock();
+
+  public MultiDispatcherExecutor(
+      Logger log,
+      MultiDispatcherConfig config,
+      String dispatcherName
+  ) {
+    this.log = log;
+    this.config = config;
+    this.threads = new 
MultiDispatcherExecutorThread[config.getDefaultPoolSize()];
+    ThreadGroup group = new ThreadGroup(dispatcherName);
+    for (int i = 0; i < threads.length; ++i) {
+      threads[i] = new MultiDispatcherExecutorThread(group, i, 
config.getQueueSize());
+    }
+  }
+
+  public void start() {
+    for(Thread t : threads) {
+      t.start();
+    }
+  }
+
+  public void execute(Event event, Runnable runnable) {
+    String lockKey = event.getLockKey();
+    // abs of Integer.MIN_VALUE is Integer.MIN_VALUE
+    int threadIndex = lockKey == null  || lockKey.hashCode() == 
Integer.MIN_VALUE ?
+        0 : Math.abs(lockKey.hashCode() % threads.length);

Review Comment:
   Based on our discussion, I think a comment or description probably would be 
useful to make the goal of this computation more clear



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/event/multidispatcher/MultiDispatcherConfig.java:
##########
@@ -0,0 +1,77 @@
+/**
+ * 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.event.multidispatcher;
+
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * All the config what can be use in the {@link MultiDispatcher}
+ */
+class MultiDispatcherConfig extends Configuration {
+
+  private final String prefix;
+
+  public MultiDispatcherConfig(Configuration configuration, String 
dispatcherName) {
+    super(configuration);
+    this.prefix = String.format("yarn.dispatcher.multi-thread.%s.", 
dispatcherName);
+  }
+
+  /**
+   * How many executor thread should be created to handle the incoming events
+   * @return configured value, or default 4
+   */
+  public int getDefaultPoolSize() {
+    return super.getInt(prefix + "default-pool-size", 4);
+  }
+
+  /**
+   * Maximus size of the event queue of the executor threads.

Review Comment:
   Just a typo, if you touch the code again anyways :)



-- 
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