org.apache.flink.runtime.iterative.event.WorkerDoneEvent Java Examples
The following examples show how to use
org.apache.flink.runtime.iterative.event.WorkerDoneEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyncEventHandler.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private void onWorkerDoneEvent(WorkerDoneEvent workerDoneEvent) { if (this.endOfSuperstep) { throw new RuntimeException("Encountered WorderDoneEvent when still in End-of-Superstep status."); } workerDoneEventCounter++; String[] aggNames = workerDoneEvent.getAggregatorNames(); Value[] aggregates = workerDoneEvent.getAggregates(userCodeClassLoader); if (aggNames.length != aggregates.length) { throw new RuntimeException("Inconsistent WorkerDoneEvent received!"); } for (int i = 0; i < aggNames.length; i++) { @SuppressWarnings("unchecked") Aggregator<Value> aggregator = (Aggregator<Value>) this.aggregators.get(aggNames[i]); aggregator.aggregate(aggregates[i]); } if (workerDoneEventCounter % numberOfEventsUntilEndOfSuperstep == 0) { endOfSuperstep = true; Thread.currentThread().interrupt(); } }
Example #2
Source File: SyncEventHandler.java From flink with Apache License 2.0 | 6 votes |
private void onWorkerDoneEvent(WorkerDoneEvent workerDoneEvent) { if (this.endOfSuperstep) { throw new RuntimeException("Encountered WorderDoneEvent when still in End-of-Superstep status."); } workerDoneEventCounter++; String[] aggNames = workerDoneEvent.getAggregatorNames(); Value[] aggregates = workerDoneEvent.getAggregates(userCodeClassLoader); if (aggNames.length != aggregates.length) { throw new RuntimeException("Inconsistent WorkerDoneEvent received!"); } for (int i = 0; i < aggNames.length; i++) { @SuppressWarnings("unchecked") Aggregator<Value> aggregator = (Aggregator<Value>) this.aggregators.get(aggNames[i]); aggregator.aggregate(aggregates[i]); } if (workerDoneEventCounter % numberOfEventsUntilEndOfSuperstep == 0) { endOfSuperstep = true; Thread.currentThread().interrupt(); } }
Example #3
Source File: SyncEventHandler.java From flink with Apache License 2.0 | 6 votes |
private void onWorkerDoneEvent(WorkerDoneEvent workerDoneEvent) { if (this.endOfSuperstep) { throw new RuntimeException("Encountered WorderDoneEvent when still in End-of-Superstep status."); } workerDoneEventCounter++; String[] aggNames = workerDoneEvent.getAggregatorNames(); Value[] aggregates = workerDoneEvent.getAggregates(userCodeClassLoader); if (aggNames.length != aggregates.length) { throw new RuntimeException("Inconsistent WorkerDoneEvent received!"); } for (int i = 0; i < aggNames.length; i++) { @SuppressWarnings("unchecked") Aggregator<Value> aggregator = (Aggregator<Value>) this.aggregators.get(aggNames[i]); aggregator.aggregate(aggregates[i]); } if (workerDoneEventCounter % numberOfEventsUntilEndOfSuperstep == 0) { endOfSuperstep = true; Thread.currentThread().interrupt(); } }
Example #4
Source File: SyncEventHandler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public void onEvent(TaskEvent event) { if (WorkerDoneEvent.class.equals(event.getClass())) { onWorkerDoneEvent((WorkerDoneEvent) event); return; } throw new IllegalStateException("Unable to handle event " + event.getClass().getName()); }
Example #5
Source File: SyncEventHandler.java From flink with Apache License 2.0 | 5 votes |
@Override public void onEvent(TaskEvent event) { if (WorkerDoneEvent.class.equals(event.getClass())) { onWorkerDoneEvent((WorkerDoneEvent) event); return; } throw new IllegalStateException("Unable to handle event " + event.getClass().getName()); }
Example #6
Source File: SyncEventHandler.java From flink with Apache License 2.0 | 5 votes |
@Override public void onEvent(TaskEvent event) { if (WorkerDoneEvent.class.equals(event.getClass())) { onWorkerDoneEvent((WorkerDoneEvent) event); return; } throw new IllegalStateException("Unable to handle event " + event.getClass().getName()); }
Example #7
Source File: IterationSynchronizationSinkTask.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public void invoke() throws Exception { this.headEventReader = new MutableRecordReader<>( getEnvironment().getInputGate(0), getEnvironment().getTaskManagerInfo().getTmpDirectories()); TaskConfig taskConfig = new TaskConfig(getTaskConfiguration()); // store all aggregators this.aggregators = new HashMap<>(); for (AggregatorWithName<?> aggWithName : taskConfig.getIterationAggregators(getUserCodeClassLoader())) { aggregators.put(aggWithName.getName(), aggWithName.getAggregator()); } // store the aggregator convergence criterion if (taskConfig.usesConvergenceCriterion()) { convergenceCriterion = taskConfig.getConvergenceCriterion(getUserCodeClassLoader()); convergenceAggregatorName = taskConfig.getConvergenceCriterionAggregatorName(); Preconditions.checkNotNull(convergenceAggregatorName); } // store the default aggregator convergence criterion if (taskConfig.usesImplicitConvergenceCriterion()) { implicitConvergenceCriterion = taskConfig.getImplicitConvergenceCriterion(getUserCodeClassLoader()); implicitConvergenceAggregatorName = taskConfig.getImplicitConvergenceCriterionAggregatorName(); Preconditions.checkNotNull(implicitConvergenceAggregatorName); } maxNumberOfIterations = taskConfig.getNumberOfIterations(); // set up the event handler int numEventsTillEndOfSuperstep = taskConfig.getNumberOfEventsUntilInterruptInIterativeGate(0); eventHandler = new SyncEventHandler(numEventsTillEndOfSuperstep, aggregators, getEnvironment().getUserClassLoader()); headEventReader.registerTaskEventListener(eventHandler, WorkerDoneEvent.class); IntValue dummy = new IntValue(); while (!terminationRequested()) { if (log.isInfoEnabled()) { log.info(formatLogString("starting iteration [" + currentIteration + "]")); } // this call listens for events until the end-of-superstep is reached readHeadEventChannel(dummy); if (log.isInfoEnabled()) { log.info(formatLogString("finishing iteration [" + currentIteration + "]")); } if (checkForConvergence()) { if (log.isInfoEnabled()) { log.info(formatLogString("signaling that all workers are to terminate in iteration [" + currentIteration + "]")); } requestTermination(); sendToAllWorkers(new TerminationEvent()); } else { if (log.isInfoEnabled()) { log.info(formatLogString("signaling that all workers are done in iteration [" + currentIteration + "]")); } AllWorkersDoneEvent allWorkersDoneEvent = new AllWorkersDoneEvent(aggregators); sendToAllWorkers(allWorkersDoneEvent); // reset all aggregators for (Aggregator<?> agg : aggregators.values()) { agg.reset(); } currentIteration++; } } }
Example #8
Source File: IterationHeadTask.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private void sendEventToSync(WorkerDoneEvent event) throws IOException, InterruptedException { if (log.isInfoEnabled()) { log.info(formatLogString("sending " + WorkerDoneEvent.class.getSimpleName() + " to sync")); } this.toSync.broadcastEvent(event); }
Example #9
Source File: IterationSynchronizationSinkTask.java From flink with Apache License 2.0 | 4 votes |
@Override public void invoke() throws Exception { this.headEventReader = new MutableRecordReader<>( getEnvironment().getInputGate(0), getEnvironment().getTaskManagerInfo().getTmpDirectories()); TaskConfig taskConfig = new TaskConfig(getTaskConfiguration()); // store all aggregators this.aggregators = new HashMap<>(); for (AggregatorWithName<?> aggWithName : taskConfig.getIterationAggregators(getUserCodeClassLoader())) { aggregators.put(aggWithName.getName(), aggWithName.getAggregator()); } // store the aggregator convergence criterion if (taskConfig.usesConvergenceCriterion()) { convergenceCriterion = taskConfig.getConvergenceCriterion(getUserCodeClassLoader()); convergenceAggregatorName = taskConfig.getConvergenceCriterionAggregatorName(); Preconditions.checkNotNull(convergenceAggregatorName); } // store the default aggregator convergence criterion if (taskConfig.usesImplicitConvergenceCriterion()) { implicitConvergenceCriterion = taskConfig.getImplicitConvergenceCriterion(getUserCodeClassLoader()); implicitConvergenceAggregatorName = taskConfig.getImplicitConvergenceCriterionAggregatorName(); Preconditions.checkNotNull(implicitConvergenceAggregatorName); } maxNumberOfIterations = taskConfig.getNumberOfIterations(); // set up the event handler int numEventsTillEndOfSuperstep = taskConfig.getNumberOfEventsUntilInterruptInIterativeGate(0); eventHandler = new SyncEventHandler(numEventsTillEndOfSuperstep, aggregators, getEnvironment().getUserClassLoader()); headEventReader.registerTaskEventListener(eventHandler, WorkerDoneEvent.class); IntValue dummy = new IntValue(); while (!terminationRequested()) { if (log.isInfoEnabled()) { log.info(formatLogString("starting iteration [" + currentIteration + "]")); } // this call listens for events until the end-of-superstep is reached readHeadEventChannel(dummy); if (log.isInfoEnabled()) { log.info(formatLogString("finishing iteration [" + currentIteration + "]")); } if (checkForConvergence()) { if (log.isInfoEnabled()) { log.info(formatLogString("signaling that all workers are to terminate in iteration [" + currentIteration + "]")); } requestTermination(); sendToAllWorkers(new TerminationEvent()); } else { if (log.isInfoEnabled()) { log.info(formatLogString("signaling that all workers are done in iteration [" + currentIteration + "]")); } AllWorkersDoneEvent allWorkersDoneEvent = new AllWorkersDoneEvent(aggregators); sendToAllWorkers(allWorkersDoneEvent); // reset all aggregators for (Aggregator<?> agg : aggregators.values()) { agg.reset(); } currentIteration++; } } }
Example #10
Source File: IterationHeadTask.java From flink with Apache License 2.0 | 4 votes |
private void sendEventToSync(WorkerDoneEvent event) throws IOException, InterruptedException { if (log.isInfoEnabled()) { log.info(formatLogString("sending " + WorkerDoneEvent.class.getSimpleName() + " to sync")); } this.toSync.broadcastEvent(event); }
Example #11
Source File: IterationSynchronizationSinkTask.java From flink with Apache License 2.0 | 4 votes |
@Override public void invoke() throws Exception { this.headEventReader = new MutableRecordReader<>( getEnvironment().getInputGate(0), getEnvironment().getTaskManagerInfo().getTmpDirectories()); TaskConfig taskConfig = new TaskConfig(getTaskConfiguration()); // store all aggregators this.aggregators = new HashMap<>(); for (AggregatorWithName<?> aggWithName : taskConfig.getIterationAggregators(getUserCodeClassLoader())) { aggregators.put(aggWithName.getName(), aggWithName.getAggregator()); } // store the aggregator convergence criterion if (taskConfig.usesConvergenceCriterion()) { convergenceCriterion = taskConfig.getConvergenceCriterion(getUserCodeClassLoader()); convergenceAggregatorName = taskConfig.getConvergenceCriterionAggregatorName(); Preconditions.checkNotNull(convergenceAggregatorName); } // store the default aggregator convergence criterion if (taskConfig.usesImplicitConvergenceCriterion()) { implicitConvergenceCriterion = taskConfig.getImplicitConvergenceCriterion(getUserCodeClassLoader()); implicitConvergenceAggregatorName = taskConfig.getImplicitConvergenceCriterionAggregatorName(); Preconditions.checkNotNull(implicitConvergenceAggregatorName); } maxNumberOfIterations = taskConfig.getNumberOfIterations(); // set up the event handler int numEventsTillEndOfSuperstep = taskConfig.getNumberOfEventsUntilInterruptInIterativeGate(0); eventHandler = new SyncEventHandler(numEventsTillEndOfSuperstep, aggregators, getEnvironment().getUserClassLoader()); headEventReader.registerTaskEventListener(eventHandler, WorkerDoneEvent.class); IntValue dummy = new IntValue(); while (!terminationRequested()) { if (log.isInfoEnabled()) { log.info(formatLogString("starting iteration [" + currentIteration + "]")); } // this call listens for events until the end-of-superstep is reached readHeadEventChannel(dummy); if (log.isInfoEnabled()) { log.info(formatLogString("finishing iteration [" + currentIteration + "]")); } if (checkForConvergence()) { if (log.isInfoEnabled()) { log.info(formatLogString("signaling that all workers are to terminate in iteration [" + currentIteration + "]")); } requestTermination(); sendToAllWorkers(new TerminationEvent()); } else { if (log.isInfoEnabled()) { log.info(formatLogString("signaling that all workers are done in iteration [" + currentIteration + "]")); } AllWorkersDoneEvent allWorkersDoneEvent = new AllWorkersDoneEvent(aggregators); sendToAllWorkers(allWorkersDoneEvent); // reset all aggregators for (Aggregator<?> agg : aggregators.values()) { agg.reset(); } currentIteration++; } } }
Example #12
Source File: IterationHeadTask.java From flink with Apache License 2.0 | 4 votes |
private void sendEventToSync(WorkerDoneEvent event) throws IOException, InterruptedException { if (log.isInfoEnabled()) { log.info(formatLogString("sending " + WorkerDoneEvent.class.getSimpleName() + " to sync")); } this.toSync.broadcastEvent(event); }