started work to parrallize compliation and "installation"
Change-Id: I2e7f03b9f8074ef6f9e1c186009ed3cad6980b49
Showing
3 changed files
with
45 additions
and
25 deletions
... | @@ -82,6 +82,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -82,6 +82,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
82 | */ | 82 | */ |
83 | @Deprecated | 83 | @Deprecated |
84 | List<Operation> batchWrite(BatchWrite batch); | 84 | List<Operation> batchWrite(BatchWrite batch); |
85 | + | ||
85 | default void write(IntentData newData) {} | 86 | default void write(IntentData newData) {} |
86 | default void batchWrite(Iterable<IntentData> updates) {} | 87 | default void batchWrite(Iterable<IntentData> updates) {} |
87 | 88 | ... | ... |
... | @@ -22,6 +22,7 @@ import java.util.EnumSet; | ... | @@ -22,6 +22,7 @@ import java.util.EnumSet; |
22 | import java.util.List; | 22 | import java.util.List; |
23 | import java.util.Map; | 23 | import java.util.Map; |
24 | import java.util.Optional; | 24 | import java.util.Optional; |
25 | +import java.util.concurrent.Callable; | ||
25 | import java.util.concurrent.ConcurrentHashMap; | 26 | import java.util.concurrent.ConcurrentHashMap; |
26 | import java.util.concurrent.ConcurrentMap; | 27 | import java.util.concurrent.ConcurrentMap; |
27 | import java.util.concurrent.ExecutionException; | 28 | import java.util.concurrent.ExecutionException; |
... | @@ -66,6 +67,7 @@ import com.google.common.collect.Lists; | ... | @@ -66,6 +67,7 @@ import com.google.common.collect.Lists; |
66 | 67 | ||
67 | import static com.google.common.base.Preconditions.checkNotNull; | 68 | import static com.google.common.base.Preconditions.checkNotNull; |
68 | import static java.util.concurrent.Executors.newFixedThreadPool; | 69 | import static java.util.concurrent.Executors.newFixedThreadPool; |
70 | +import static java.util.concurrent.Executors.newSingleThreadExecutor; | ||
69 | import static org.onlab.util.Tools.namedThreads; | 71 | import static org.onlab.util.Tools.namedThreads; |
70 | import static org.onosproject.net.intent.IntentState.FAILED; | 72 | import static org.onosproject.net.intent.IntentState.FAILED; |
71 | import static org.onosproject.net.intent.IntentState.INSTALL_REQ; | 73 | import static org.onosproject.net.intent.IntentState.INSTALL_REQ; |
... | @@ -115,7 +117,8 @@ public class IntentManager | ... | @@ -115,7 +117,8 @@ public class IntentManager |
115 | protected FlowRuleService flowRuleService; | 117 | protected FlowRuleService flowRuleService; |
116 | 118 | ||
117 | 119 | ||
118 | - private ExecutorService executor; | 120 | + private ExecutorService batchExecutor; |
121 | + private ExecutorService workerExecutor; | ||
119 | 122 | ||
120 | private final IntentStoreDelegate delegate = new InternalStoreDelegate(); | 123 | private final IntentStoreDelegate delegate = new InternalStoreDelegate(); |
121 | private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate(); | 124 | private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate(); |
... | @@ -129,7 +132,8 @@ public class IntentManager | ... | @@ -129,7 +132,8 @@ public class IntentManager |
129 | store.setDelegate(delegate); | 132 | store.setDelegate(delegate); |
130 | trackerService.setDelegate(topoDelegate); | 133 | trackerService.setDelegate(topoDelegate); |
131 | eventDispatcher.addSink(IntentEvent.class, listenerRegistry); | 134 | eventDispatcher.addSink(IntentEvent.class, listenerRegistry); |
132 | - executor = newFixedThreadPool(NUM_THREADS, namedThreads("onos-intent-%d")); | 135 | + batchExecutor = newSingleThreadExecutor(namedThreads("onos-intent-batch")); |
136 | + workerExecutor = newFixedThreadPool(NUM_THREADS, namedThreads("onos-intent-worker-%d")); | ||
133 | idGenerator = coreService.getIdGenerator("intent-ids"); | 137 | idGenerator = coreService.getIdGenerator("intent-ids"); |
134 | Intent.bindIdGenerator(idGenerator); | 138 | Intent.bindIdGenerator(idGenerator); |
135 | log.info("Started"); | 139 | log.info("Started"); |
... | @@ -140,7 +144,7 @@ public class IntentManager | ... | @@ -140,7 +144,7 @@ public class IntentManager |
140 | store.unsetDelegate(delegate); | 144 | store.unsetDelegate(delegate); |
141 | trackerService.unsetDelegate(topoDelegate); | 145 | trackerService.unsetDelegate(topoDelegate); |
142 | eventDispatcher.removeSink(IntentEvent.class); | 146 | eventDispatcher.removeSink(IntentEvent.class); |
143 | - executor.shutdown(); | 147 | + batchExecutor.shutdown(); |
144 | Intent.unbindIdGenerator(idGenerator); | 148 | Intent.unbindIdGenerator(idGenerator); |
145 | log.info("Stopped"); | 149 | log.info("Stopped"); |
146 | } | 150 | } |
... | @@ -472,9 +476,15 @@ public class IntentManager | ... | @@ -472,9 +476,15 @@ public class IntentManager |
472 | @Override | 476 | @Override |
473 | public void run() { | 477 | public void run() { |
474 | try { | 478 | try { |
475 | - List<IntentUpdate> updates = createIntentUpdates(); | 479 | + // 1. wrap each intentdata in a runnable and submit |
480 | + List<Future<IntentUpdate>> updates = createIntentUpdates(); | ||
481 | + // TODO | ||
482 | + // 2. wait for completion of all the work | ||
483 | + // 3. accumulate results and submit batch write of IntentData to store | ||
484 | + // (we can also try to update these individually) | ||
476 | 485 | ||
477 | - new IntentBatchApplyFirst(ops, processIntentUpdates(updates), endTime, 0, null).run(); | 486 | + |
487 | + //new IntentBatchApplyFirst(ops, processIntentUpdates(updates), endTime, 0, null).run(); | ||
478 | } catch (Exception e) { | 488 | } catch (Exception e) { |
479 | log.error("Error submitting batches:", e); | 489 | log.error("Error submitting batches:", e); |
480 | // FIXME incomplete Intents should be cleaned up | 490 | // FIXME incomplete Intents should be cleaned up |
... | @@ -488,32 +498,39 @@ public class IntentManager | ... | @@ -488,32 +498,39 @@ public class IntentManager |
488 | } | 498 | } |
489 | } | 499 | } |
490 | 500 | ||
491 | - private List<IntentUpdate> createIntentUpdates() { | 501 | + private List<Future<IntentUpdate>> createIntentUpdates() { |
492 | return ops.stream() | 502 | return ops.stream() |
493 | - .map(IntentManager.this::createIntentUpdate) | 503 | + .map(IntentManager.this::submitIntentData) |
494 | .collect(Collectors.toList()); | 504 | .collect(Collectors.toList()); |
495 | } | 505 | } |
496 | - | ||
497 | - private List<CompletedIntentUpdate> processIntentUpdates(List<IntentUpdate> updates) { | ||
498 | - // start processing each Intents | ||
499 | - List<CompletedIntentUpdate> completed = new ArrayList<>(); | ||
500 | - for (IntentUpdate update : updates) { | ||
501 | - Optional<IntentUpdate> phase = Optional.of(update); | ||
502 | - IntentUpdate previous = update; | ||
503 | - while (true) { | ||
504 | - if (!phase.isPresent()) { | ||
505 | - // FIXME: not type safe cast | ||
506 | - completed.add((CompletedIntentUpdate) previous); | ||
507 | - break; | ||
508 | } | 506 | } |
509 | - previous = phase.get(); | 507 | + |
510 | - phase = previous.execute(); | 508 | + private Future<IntentUpdate> submitIntentData(IntentData data) { |
509 | + return workerExecutor.submit(new IntentWorker(data)); | ||
511 | } | 510 | } |
511 | + | ||
512 | + private class IntentWorker implements Callable<IntentUpdate> { | ||
513 | + | ||
514 | + private final IntentData data; | ||
515 | + | ||
516 | + private IntentWorker(IntentData data) { | ||
517 | + this.data = data; | ||
512 | } | 518 | } |
513 | 519 | ||
514 | - return completed; | 520 | + @Override |
521 | + public IntentUpdate call() throws Exception { | ||
522 | + IntentUpdate update = createIntentUpdate(data); | ||
523 | + Optional<IntentUpdate> currentPhase = Optional.of(update); | ||
524 | + IntentUpdate previousPhase = update; | ||
525 | + | ||
526 | + while (currentPhase.isPresent()) { | ||
527 | + previousPhase = currentPhase.get(); | ||
528 | + currentPhase = previousPhase.execute(); | ||
515 | } | 529 | } |
530 | + return previousPhase; | ||
516 | } | 531 | } |
532 | + } | ||
533 | + | ||
517 | 534 | ||
518 | // TODO: better naming | 535 | // TODO: better naming |
519 | private class IntentBatchApplyFirst extends IntentBatchPreprocess { | 536 | private class IntentBatchApplyFirst extends IntentBatchPreprocess { |
... | @@ -596,7 +613,7 @@ public class IntentManager | ... | @@ -596,7 +613,7 @@ public class IntentManager |
596 | retry(); | 613 | retry(); |
597 | } else { | 614 | } else { |
598 | // we are not done yet, yield the thread by resubmitting ourselves | 615 | // we are not done yet, yield the thread by resubmitting ourselves |
599 | - executor.submit(new IntentBatchProcessFutures(ops, intentUpdates, endTime, installAttempt, future)); | 616 | + batchExecutor.submit(new IntentBatchProcessFutures(ops, intentUpdates, endTime, installAttempt, future)); |
600 | } | 617 | } |
601 | } catch (Exception e) { | 618 | } catch (Exception e) { |
602 | log.error("Error submitting batches:", e); | 619 | log.error("Error submitting batches:", e); |
... | @@ -665,7 +682,7 @@ public class IntentManager | ... | @@ -665,7 +682,7 @@ public class IntentManager |
665 | return; | 682 | return; |
666 | } | 683 | } |
667 | Future<CompletedBatchOperation> future = applyNextBatch(intentUpdates); | 684 | Future<CompletedBatchOperation> future = applyNextBatch(intentUpdates); |
668 | - executor.submit(new IntentBatchProcessFutures(ops, intentUpdates, timeLimit, attempts, future)); | 685 | + batchExecutor.submit(new IntentBatchProcessFutures(ops, intentUpdates, timeLimit, attempts, future)); |
669 | } else { | 686 | } else { |
670 | log.error("Cancelling FlowRuleBatch failed."); | 687 | log.error("Cancelling FlowRuleBatch failed."); |
671 | abandonShip(); | 688 | abandonShip(); |
... | @@ -678,7 +695,8 @@ public class IntentManager | ... | @@ -678,7 +695,8 @@ public class IntentManager |
678 | public void execute(Collection<IntentData> operations) { | 695 | public void execute(Collection<IntentData> operations) { |
679 | log.info("Execute {} operation(s).", operations.size()); | 696 | log.info("Execute {} operation(s).", operations.size()); |
680 | log.debug("Execute operations: {}", operations); | 697 | log.debug("Execute operations: {}", operations); |
681 | - executor.execute(new IntentBatchPreprocess(operations)); | 698 | + batchExecutor.execute(new IntentBatchPreprocess(operations)); |
699 | + // TODO ensure that only one batch is in flight at a time | ||
682 | } | 700 | } |
683 | } | 701 | } |
684 | } | 702 | } | ... | ... |
-
Please register or login to post a comment