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 750756e3b3dc66bc3444e3f620d757d0ae09439e
Merge: 6190ffe a015a16
Author: sanha <[email protected]>
AuthorDate: Thu Mar 22 12:05:25 2018 +0900

    merge jh scheduler fix

 .travis.yml                                        |  19 +-
 .../main/java/edu/snu/nemo/client/JobLauncher.java |   1 -
 .../frontend/beam/NemoPipelineVisitor.java         |   3 +-
 .../spark/core/java/SparkFrontendUtils.java        |  14 +-
 .../compiler/frontend/spark/sql/SparkSession.java  |   9 +-
 .../frontend/spark/transform/CollectTransform.java |   9 +-
 conf/src/main/java/edu/snu/nemo/conf/JobConf.java  |   9 -
 .../nemo/examples/beam/AlternatingLeastSquare.java |   2 +-
 examples/resources/sample_executor_resources.json  |   6 +-
 .../examples/spark/sql/JavaSparkSQLExample.java    |   4 +-
 .../main/java/edu/snu/nemo/driver/NemoDriver.java  |   6 +-
 .../edu/snu/nemo/runtime/executor/Executor.java    |   4 +-
 .../nemo/runtime/executor/MetricManagerWorker.java |   2 +-
 .../master/scheduler/BatchSingleJobScheduler.java  |   7 +-
 .../master/scheduler/PendingTaskGroupQueue.java    |  22 +-
 .../scheduler/RoundRobinSchedulingPolicy.java      | 155 +++-----------
 .../runtime/master/scheduler/SchedulerRunner.java  |  98 +++++++--
 .../runtime/master/scheduler/SchedulingPolicy.java |   6 -
 .../master/scheduler/SingleJobTaskGroupQueue.java  | 103 ++++-----
 .../SourceLocationAwareSchedulingPolicy.java       | 236 +++++++--------------
 .../snu/nemo/tests/runtime/RuntimeTestUtil.java    |   3 +-
 .../executor/datatransfer/DataTransferTest.java    |   5 +-
 .../scheduler/BatchSingleJobSchedulerTest.java     |   4 +-
 .../master/scheduler/FaultToleranceTest.java       |   3 +-
 .../scheduler/RoundRobinSchedulingPolicyTest.java  |  88 +-------
 .../master/scheduler/SingleTaskGroupQueueTest.java | 111 ++--------
 .../SourceLocationAwareSchedulingPolicyTest.java   |  71 +------
 27 files changed, 342 insertions(+), 658 deletions(-)

diff --cc 
compiler/frontend/spark/src/main/java/edu/snu/nemo/compiler/frontend/spark/transform/CollectTransform.java
index 5f8efe5,94bfb11..c21463b
--- 
a/compiler/frontend/spark/src/main/java/edu/snu/nemo/compiler/frontend/spark/transform/CollectTransform.java
+++ 
b/compiler/frontend/spark/src/main/java/edu/snu/nemo/compiler/frontend/spark/transform/CollectTransform.java
@@@ -50,21 -45,21 +50,20 @@@ public final class CollectTransform<T> 
    }
  
    @Override
 -  public void onData(final Iterator<T> elements, final String srcVertexId) {
 +  public void onData(final T element) {
      // Write result to a temporary file.
      // TODO #740: remove this part, and make it properly transfer with 
executor.
 +    list.add(element);
 +  }
 +
 +  @Override
 +  public void close() {
-     try {
-       fos = new FileOutputStream(filename);
-       oos = new ObjectOutputStream(fos);
-       oos.writeObject(list);
-       oos.close();
+     try (final FileOutputStream fos = new FileOutputStream(filename)) {
+       try (final ObjectOutputStream oos = new ObjectOutputStream(fos)) {
 -        final ArrayList<T> list = new ArrayList<>();
 -        elements.forEachRemaining(list::add);
+         oos.writeObject(list);
+       }
      } catch (Exception e) {
 -      throw new RuntimeException(e);
 +      throw new RuntimeException("Exception while file closing in 
CollectTransform " + e);
      }
    }
 -
 -  @Override
 -  public void close() {
 -  }
  }
diff --cc 
runtime/executor/src/main/java/edu/snu/nemo/runtime/executor/Executor.java
index 8846cc3,06a07d2..254c854
--- a/runtime/executor/src/main/java/edu/snu/nemo/runtime/executor/Executor.java
+++ b/runtime/executor/src/main/java/edu/snu/nemo/runtime/executor/Executor.java
@@@ -83,7 -81,6 +81,7 @@@ public final class Executor 
      this.dataTransferFactory = dataTransferFactory;
      this.metricMessageSender = metricMessageSender;
      
messageEnvironment.setupListener(MessageEnvironment.EXECUTOR_MESSAGE_LISTENER_ID,
 new ExecutorMessageReceiver());
-     LOG.info("Executor [{}] capacity is " + executorCapacity, executorId);
++    LOG.info("Executor [{}]", executorId);
    }
  
    public String getExecutorId() {
diff --cc 
runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/BatchSingleJobScheduler.java
index dc7502c,b663aca..6f1737e
--- 
a/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/BatchSingleJobScheduler.java
+++ 
b/runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/BatchSingleJobScheduler.java
@@@ -380,10 -377,11 +381,11 @@@ public final class BatchSingleJobSchedu
        blockManagerMaster.onProducerTaskGroupScheduled(taskGroupId);
        final int taskGroupIdx = 
RuntimeIdGenerator.getIndexFromTaskGroupId(taskGroupId);
        LOG.debug("Enquing {}", taskGroupId);
-       pendingTaskGroupQueue.enqueue(new 
ScheduledTaskGroup(physicalPlan.getId(),
+       pendingTaskGroupQueue.add(new ScheduledTaskGroup(physicalPlan.getId(),
            stageToSchedule.getSerializedTaskGroupDag(), taskGroupId, 
stageIncomingEdges, stageOutgoingEdges, attemptIdx,
 -          stageToSchedule.getContainerType(), 
logicalTaskIdToReadables.get(taskGroupIdx)));
 +          stageToSchedule.getContainerType(), 
logicalTaskIdToReadables.get(taskGroupIdx), isSmall));
      });
+     schedulerRunner.onATaskGroupAvailable();
    }
  
    /**
diff --cc 
runtime/master/src/main/java/edu/snu/nemo/runtime/master/scheduler/SourceLocationAwareSchedulingPolicy.java
index d8fcc98,4a2c085..bf4af74
--- 
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
@@@ -15,16 -15,10 +15,15 @@@
   */
  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;
@@@ -34,11 -28,7 +33,8 @@@ 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;
- import java.util.concurrent.locks.ReentrantLock;
  import java.util.stream.Collectors;
  import java.util.stream.Stream;
  
@@@ -54,10 -44,6 +50,7 @@@ public final class SourceLocationAwareS
  
    private final ExecutorRegistry executorRegistry;
    private final RoundRobinSchedulingPolicy roundRobinSchedulingPolicy;
-   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}.
@@@ -66,19 -52,11 +59,13 @@@
     */
    @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
-   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,
@@@ -91,73 -69,21 +78,46 @@@
    @Override
    public boolean scheduleTaskGroup(final ScheduledTaskGroup 
scheduledTaskGroup,
                                     final JobStateManager jobStateManager) {
-     lock.lock();
+     Set<String> sourceLocations = Collections.emptySet();
      try {
-       Set<String> sourceLocations = Collections.emptySet();
-       try {
-         sourceLocations = 
getSourceLocations(scheduledTaskGroup.getLogicalTaskIdToReadable().values());
-       } catch (final UnsupportedOperationException e) {
-         // do nothing
-       } catch (final Exception e) {
-         LOG.warn(String.format("Exception while trying to get source location 
for %s",
-             scheduledTaskGroup.getTaskGroupId()), e);
-       }
+       sourceLocations = 
getSourceLocations(scheduledTaskGroup.getLogicalTaskIdToReadable().values());
+     } catch (final UnsupportedOperationException e) {
+       // do nothing
+     } catch (final Exception e) {
+       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);
-                   }
-                 }
-                 if (System.currentTimeMillis() % 50 == 0) {
-                   return 
roundRobinSchedulingPolicy.scheduleTaskGroup(scheduledTaskGroup, 
jobStateManager); // delay
-                 } else {
-                   return false;
-                 }
-               } catch (final InterruptedException | ExecutionException e) {
-                 LOG.error("Error during getting intermediate data location!", 
e);
+     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();
++              final boolean scheduled =
++                  scheduleToLocalExecutor(scheduledTaskGroup, 
jobStateManager, location);
++              if (!scheduled && System.currentTimeMillis() % 100 == 0) {
++                return 
roundRobinSchedulingPolicy.scheduleTaskGroup(scheduledTaskGroup, 
jobStateManager); // delay
++              } else {
++                return scheduled;
 +              }
++            } 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);
-       }
- 
-       while (timeoutInNanoseconds > 0) {
-         if (scheduleToLocalNode(scheduledTaskGroup, jobStateManager, 
sourceLocations)) {
-           return true;
-         }
-         try {
-           timeoutInNanoseconds = 
moreExecutorsAvailableCondition.awaitNanos(timeoutInNanoseconds);
-           // Signals on this condition does not necessarily guarantee that 
the added executor helps scheduling the
-           // TaskGroup we are interested in. We need to await again if the 
consequent scheduling attempt still fails,
-           // until we spend the time budget specified.
-         } catch (final InterruptedException e) {
-           throw new SchedulingException(e);
-         }
 +      }
-       return false;
-     } finally {
-       lock.unlock();
+       // No source location information found, fall back to the 
RoundRobinSchedulingPolicy
+       return roundRobinSchedulingPolicy.scheduleTaskGroup(scheduledTaskGroup, 
jobStateManager);
      }
+ 
+     return scheduleToLocalNode(scheduledTaskGroup, jobStateManager, 
sourceLocations);
    }
  
    /**
@@@ -170,70 -96,25 +130,54 @@@
    private boolean scheduleToLocalNode(final ScheduledTaskGroup 
scheduledTaskGroup,
                                        final JobStateManager jobStateManager,
                                        final Set<String> sourceLocations) {
-     lock.lock();
-     try {
-       final List<ExecutorRepresenter> candidateExecutors =
-           
selectExecutorByContainerTypeAndNodeNames(scheduledTaskGroup.getContainerType(),
 sourceLocations);
-       if (candidateExecutors.size() == 0) {
-         return false;
-       }
-       final int randomIndex = ThreadLocalRandom.current().nextInt(0, 
candidateExecutors.size());
-       final ExecutorRepresenter selectedExecutor = 
candidateExecutors.get(randomIndex);
- 
-       
jobStateManager.onTaskGroupStateChanged(scheduledTaskGroup.getTaskGroupId(), 
TaskGroupState.State.EXECUTING);
-       selectedExecutor.onTaskGroupScheduled(scheduledTaskGroup);
-       LOG.info("Scheduling {} (source location: {}) to {} (node name: {})", 
scheduledTaskGroup.getTaskGroupId(),
-           String.join(", ", sourceLocations), 
selectedExecutor.getExecutorId(),
-           selectedExecutor.getNodeName());
-       return true;
-     } finally {
-       lock.unlock();
+     final List<ExecutorRepresenter> candidateExecutors =
+         
selectExecutorByContainerTypeAndNodeNames(scheduledTaskGroup.getContainerType(),
 sourceLocations);
+     if (candidateExecutors.size() == 0) {
+       return false;
      }
+     final int randomIndex = ThreadLocalRandom.current().nextInt(0, 
candidateExecutors.size());
+     final ExecutorRepresenter selectedExecutor = 
candidateExecutors.get(randomIndex);
+ 
+     
jobStateManager.onTaskGroupStateChanged(scheduledTaskGroup.getTaskGroupId(), 
TaskGroupState.State.EXECUTING);
+     selectedExecutor.onTaskGroupScheduled(scheduledTaskGroup);
+     LOG.info("Scheduling {} (source location: {}) to {} (node name: {})", 
scheduledTaskGroup.getTaskGroupId(),
+         String.join(", ", sourceLocations), selectedExecutor.getExecutorId(),
+         selectedExecutor.getNodeName());
+     return true;
    }
  
 +  /**
 +   * 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();
++    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;
 +  }
 +
    @Override
    public void onExecutorAdded(final ExecutorRepresenter executorRepresenter) {
-     lock.lock();
-     try {
-       moreExecutorsAvailableCondition.signal();
-       roundRobinSchedulingPolicy.onExecutorAdded(executorRepresenter);
-     } finally {
-       lock.unlock();
-     }
+     roundRobinSchedulingPolicy.onExecutorAdded(executorRepresenter);
    }
  
    @Override
diff --cc 
tests/src/test/java/edu/snu/nemo/tests/runtime/master/scheduler/SingleTaskGroupQueueTest.java
index fb6db1f,12c8fe1..85755a1
--- 
a/tests/src/test/java/edu/snu/nemo/tests/runtime/master/scheduler/SingleTaskGroupQueueTest.java
+++ 
b/tests/src/test/java/edu/snu/nemo/tests/runtime/master/scheduler/SingleTaskGroupQueueTest.java
@@@ -398,9 -315,9 +315,9 @@@ public final class SingleTaskGroupQueue
     */
    private void scheduleStage(final PhysicalStage stage) {
      stage.getTaskGroupIds().forEach(taskGroupId ->
-         pendingTaskGroupPriorityQueue.enqueue(new ScheduledTaskGroup(
+         pendingTaskGroupPriorityQueue.add(new ScheduledTaskGroup(
              "TestPlan", stage.getSerializedTaskGroupDag(), taskGroupId, 
Collections.emptyList(),
 -            Collections.emptyList(), 0, stage.getContainerType(), 
Collections.emptyMap())));
 +            Collections.emptyList(), 0, stage.getContainerType(), 
Collections.emptyMap(), false)));
    }
  
    /**

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to