You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nemo.apache.org by je...@apache.org on 2018/04/06 02:36:05 UTC

[incubator-nemo] 25/40: intermediate data patch

This is an automated email from the ASF dual-hosted git repository.

jeongyoon pushed a commit to branch skew_exp
in repository https://gitbox.apache.org/repos/asf/incubator-nemo.git

commit 239cb10a32480e2952a24742edc06776f3c1f410
Author: sanha <sa...@naver.com>
AuthorDate: Wed Mar 21 13:22:02 2018 +0900

    intermediate data patch
---
 conf/src/main/java/edu/snu/nemo/conf/JobConf.java  |  2 +-
 .../nemo/runtime/master/BlockManagerMaster.java    |  4 +-
 .../SourceLocationAwareSchedulingPolicy.java       | 76 +++++++++++++++++++++-
 3 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/conf/src/main/java/edu/snu/nemo/conf/JobConf.java b/conf/src/main/java/edu/snu/nemo/conf/JobConf.java
index c539d7a..d89bf8a 100644
--- a/conf/src/main/java/edu/snu/nemo/conf/JobConf.java
+++ b/conf/src/main/java/edu/snu/nemo/conf/JobConf.java
@@ -144,7 +144,7 @@ public final class JobConf extends ConfigurationModuleBuilder {
   /**
    * Scheduler timeout in ms.
    */
-  @NamedParameter(doc = "Scheduler timeout in ms", short_name = "scheduler_timeout_ms", default_value = "50")
+  @NamedParameter(doc = "Scheduler timeout in ms", short_name = "scheduler_timeout_ms", default_value = "10")
   public final class SchedulerTimeoutMs implements Name<Integer> {
   }
 
diff --git a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/BlockManagerMaster.java b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/BlockManagerMaster.java
index 8e7c5c4..ff29d3d 100644
--- a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/BlockManagerMaster.java
+++ b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/BlockManagerMaster.java
@@ -303,8 +303,8 @@ public final class BlockManagerMaster {
    * @param message        the request message.
    * @param messageContext the message context which will be used for response.
    */
-  void onRequestBlockLocation(final ControlMessage.Message message,
-                              final MessageContext messageContext) {
+  private void onRequestBlockLocation(final ControlMessage.Message message,
+                                      final MessageContext messageContext) {
     assert (message.getType() == ControlMessage.MessageType.RequestBlockLocation);
     final String blockId = message.getRequestBlockLocationMsg().getBlockId();
     final long requestId = message.getId();
diff --git a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SourceLocationAwareSchedulingPolicy.java b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SourceLocationAwareSchedulingPolicy.java
index 56ac2ff..ae2b5bd 100644
--- a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SourceLocationAwareSchedulingPolicy.java
+++ b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SourceLocationAwareSchedulingPolicy.java
@@ -17,9 +17,14 @@ 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.edge.executionproperty.DataCommunicationPatternProperty;
+import edu.snu.nemo.common.ir.executionproperty.ExecutionProperty;
 import edu.snu.nemo.common.ir.vertex.executionproperty.ExecutorPlacementProperty;
+import edu.snu.nemo.runtime.common.RuntimeIdGenerator;
+import edu.snu.nemo.runtime.common.plan.physical.PhysicalStageEdge;
 import edu.snu.nemo.runtime.common.plan.physical.ScheduledTaskGroup;
 import edu.snu.nemo.runtime.common.state.TaskGroupState;
+import edu.snu.nemo.runtime.master.BlockManagerMaster;
 import edu.snu.nemo.runtime.master.JobStateManager;
 import edu.snu.nemo.runtime.master.resource.ExecutorRepresenter;
 import org.apache.reef.annotations.audience.DriverSide;
@@ -29,6 +34,7 @@ import org.slf4j.LoggerFactory;
 import javax.annotation.concurrent.ThreadSafe;
 import javax.inject.Inject;
 import java.util.*;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
@@ -51,6 +57,7 @@ public final class SourceLocationAwareSchedulingPolicy implements SchedulingPoli
   private final long scheduleTimeoutMs;
   private final Lock lock = new ReentrantLock();
   private final Condition moreExecutorsAvailableCondition = lock.newCondition();
+  private final BlockManagerMaster blockManagerMaster;
 
   /**
    * Injectable constructor for {@link SourceLocationAwareSchedulingPolicy}.
@@ -59,10 +66,12 @@ public final class SourceLocationAwareSchedulingPolicy implements SchedulingPoli
    */
   @Inject
   private SourceLocationAwareSchedulingPolicy(final ExecutorRegistry executorRegistry,
-                                              final RoundRobinSchedulingPolicy roundRobinSchedulingPolicy) {
+                                              final RoundRobinSchedulingPolicy roundRobinSchedulingPolicy,
+                                              final BlockManagerMaster blockManagerMaster) {
     this.executorRegistry = executorRegistry;
     this.roundRobinSchedulingPolicy = roundRobinSchedulingPolicy;
     this.scheduleTimeoutMs = roundRobinSchedulingPolicy.getScheduleTimeoutMs();
+    this.blockManagerMaster = blockManagerMaster;
   }
 
   @Override
@@ -93,12 +102,41 @@ public final class SourceLocationAwareSchedulingPolicy implements SchedulingPoli
         LOG.warn(String.format("Exception while trying to get source location for %s",
             scheduledTaskGroup.getTaskGroupId()), e);
       }
+
+      long timeoutInNanoseconds = scheduleTimeoutMs * 1000000;
       if (sourceLocations.size() == 0) {
+        if (scheduledTaskGroup.getTaskGroupIncomingEdges().size() == 1) {
+          final PhysicalStageEdge physicalStageEdge = scheduledTaskGroup.getTaskGroupIncomingEdges().get(0);
+          if (DataCommunicationPatternProperty.Value.OneToOne.equals(
+              physicalStageEdge.getProperty(ExecutionProperty.Key.DataCommunicationPattern))) {
+            final String blockIdToRead =
+                RuntimeIdGenerator.generateBlockId(physicalStageEdge.getId(), scheduledTaskGroup.getTaskGroupIdx());
+            final BlockManagerMaster.BlockLocationRequestHandler locationHandler =
+                blockManagerMaster.getBlockLocationHandler(blockIdToRead);
+            if (locationHandler.getLocationFuture().isDone()) {
+              try {
+                final String location = locationHandler.getLocationFuture().get();
+                while (timeoutInNanoseconds > 0) {
+                  if (scheduleToLocalExecutor(scheduledTaskGroup, jobStateManager, location)) {
+                    return true;
+                  }
+                  try {
+                    timeoutInNanoseconds = moreExecutorsAvailableCondition.awaitNanos(timeoutInNanoseconds);
+                  } catch (final InterruptedException e) {
+                    throw new SchedulingException(e);
+                  }
+                }
+                return false;
+              } catch (final InterruptedException | ExecutionException e) {
+                LOG.error("Error during getting intermediate data location!", e);
+              }
+            }
+          }
+        }
         // No source location information found, fall back to the RoundRobinSchedulingPolicy
         return roundRobinSchedulingPolicy.scheduleTaskGroup(scheduledTaskGroup, jobStateManager);
       }
 
-      long timeoutInNanoseconds = scheduleTimeoutMs * 1000000;
       while (timeoutInNanoseconds > 0) {
         if (scheduleToLocalNode(scheduledTaskGroup, jobStateManager, sourceLocations)) {
           return true;
@@ -149,6 +187,40 @@ public final class SourceLocationAwareSchedulingPolicy implements SchedulingPoli
     }
   }
 
+  /**
+   * Try to schedule a TaskGroup with intermediate data.
+   * @param scheduledTaskGroup TaskGroup to schedule
+   * @param jobStateManager {@link JobStateManager}
+   * @param intermLocation  which the TaskGroup belongs to.
+   * @return true if the task group is successfully scheduled, false otherwise.
+   */
+  private boolean scheduleToLocalExecutor(final ScheduledTaskGroup scheduledTaskGroup,
+                                          final JobStateManager jobStateManager,
+                                          final String intermLocation) {
+    lock.lock();
+    try {
+      final Optional<ExecutorRepresenter> candidateExecutor = executorRegistry.getRunningExecutorIds().stream()
+          .map(executorId -> executorRegistry.getRunningExecutorRepresenter(executorId))
+          .filter(executor -> executor.getRunningTaskGroups().size() - executor.getSmallTaskGroups().size()
+              < executor.getExecutorCapacity())
+          .filter(executor -> executor.getExecutorId().equals(intermLocation))
+          .findAny();
+      if (!candidateExecutor.isPresent()) {
+        return false;
+      }
+      final ExecutorRepresenter selectedExecutor = candidateExecutor.get();
+
+      jobStateManager.onTaskGroupStateChanged(scheduledTaskGroup.getTaskGroupId(), TaskGroupState.State.EXECUTING);
+      selectedExecutor.onTaskGroupScheduled(scheduledTaskGroup);
+      LOG.info("Scheduling {} (interm location: {}) to {} (node name: {})", scheduledTaskGroup.getTaskGroupId(),
+          String.join(", ", intermLocation), selectedExecutor.getExecutorId(),
+          selectedExecutor.getNodeName());
+      return true;
+    } finally {
+      lock.unlock();
+    }
+  }
+
   @Override
   public void onExecutorAdded(final ExecutorRepresenter executorRepresenter) {
     lock.lock();

-- 
To stop receiving notification emails like this one, please contact
jeongyoon@apache.org.