seojangho commented on a change in pull request #1: [NEMO-26] Implement 
SourceLocationAwareSchedulingPolicy
URL: https://github.com/apache/incubator-nemo/pull/1#discussion_r172759560
 
 

 ##########
 File path: 
runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SourceLocationAwareSchedulingPolicy.java
 ##########
 @@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2018 Seoul National University
+ *
+ * Licensed 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 edu.snu.nemo.runtime.master.scheduler;
+
+import edu.snu.nemo.common.exception.SchedulingException;
+import edu.snu.nemo.common.ir.Readable;
+import 
edu.snu.nemo.common.ir.vertex.executionproperty.ExecutorPlacementProperty;
+import edu.snu.nemo.runtime.common.plan.physical.ScheduledTaskGroup;
+import edu.snu.nemo.runtime.common.state.TaskGroupState;
+import edu.snu.nemo.runtime.master.JobStateManager;
+import edu.snu.nemo.runtime.master.resource.ExecutorRepresenter;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.concurrent.ThreadSafe;
+import javax.inject.Inject;
+import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * This policy is same as {@link RoundRobinSchedulingPolicy}, however for 
TaskGroups
+ * with {@link edu.snu.nemo.common.ir.vertex.SourceVertex}, it tries to pick 
one of the executors
+ * where the corresponding data resides.
+ */
+@ThreadSafe
+@DriverSide
+public final class SourceLocationAwareSchedulingPolicy implements 
SchedulingPolicy {
+  private static final Logger LOG = 
LoggerFactory.getLogger(SourceLocationAwareSchedulingPolicy.class);
+
+  private final ExecutorRegistry executorRegistry;
+  private final RoundRobinSchedulingPolicy roundRobinSchedulingPolicy;
+  private final long scheduleTimeoutMs;
+
+  @Inject
+  private SourceLocationAwareSchedulingPolicy(final ExecutorRegistry 
executorRegistry,
+                                              final RoundRobinSchedulingPolicy 
roundRobinSchedulingPolicy) {
+    this.executorRegistry = executorRegistry;
+    this.roundRobinSchedulingPolicy = roundRobinSchedulingPolicy;
+    this.scheduleTimeoutMs = roundRobinSchedulingPolicy.getScheduleTimeoutMs();
+  }
+
+  @Override
+  public long getScheduleTimeoutMs() {
+    return scheduleTimeoutMs;
+  }
+
+  /**
+   * Try to schedule a TaskGroup.
+   * If the TaskGroup has one or more source tasks, this method schedules the 
task group to one of the physical nodes,
+   * chosen from union of set of locations where splits of each source task 
resides.
+   * If the TaskGroup has no source tasks, falls back to {@link 
RoundRobinSchedulingPolicy}.
+   * @param scheduledTaskGroup to schedule.
+   * @param jobStateManager jobStateManager which the TaskGroup belongs to.
+   * @return true if the task group is successfully scheduled, false otherwise.
+   */
+  @Override
+  public synchronized boolean scheduleTaskGroup(final ScheduledTaskGroup 
scheduledTaskGroup,
+                                                final JobStateManager 
jobStateManager) {
+    Set<String> sourceLocations = Collections.emptySet();
+    try {
+      sourceLocations = 
getSourceLocations(scheduledTaskGroup.getLogicalTaskIdToReadable().values());
+    } catch (final Exception e) {
+      LOG.warn(String.format("Exception while trying to get source location 
for %s",
+          scheduledTaskGroup.getTaskGroupId()), e);
+    }
+    if (sourceLocations.size() == 0) {
+      // No source location information found, fall back to the 
RoundRobinSchedulingPolicy
+      return roundRobinSchedulingPolicy.scheduleTaskGroup(scheduledTaskGroup, 
jobStateManager);
+    }
+
+    if (scheduleToLocalNode(scheduledTaskGroup, jobStateManager, 
sourceLocations)) {
+      return true;
+    } else {
+      try {
+        Thread.sleep(scheduleTimeoutMs);
 
 Review comment:
   Yup. Thanks.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to