Search in sources :

Example 56 with TaskConfig

use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.

the class IterationHeadTask method initOutputs.

@Override
protected void initOutputs() throws Exception {
    // initialize the regular outputs first (the ones into the step function).
    super.initOutputs();
    // at this time, the outputs to the step function are created
    // add the outputs for the final solution
    List<RecordWriter<?>> finalOutputWriters = new ArrayList<RecordWriter<?>>();
    final TaskConfig finalOutConfig = this.config.getIterationHeadFinalOutputConfig();
    final ClassLoader userCodeClassLoader = getUserCodeClassLoader();
    this.finalOutputCollector = BatchTask.getOutputCollector(this, finalOutConfig, userCodeClassLoader, finalOutputWriters, config.getNumOutputs(), finalOutConfig.getNumOutputs());
    // sanity check the setup
    final int writersIntoStepFunction = this.eventualOutputs.size();
    final int writersIntoFinalResult = finalOutputWriters.size();
    final int syncGateIndex = this.config.getIterationHeadIndexOfSyncOutput();
    if (writersIntoStepFunction + writersIntoFinalResult != syncGateIndex) {
        throw new Exception("Error: Inconsistent head task setup - wrong mapping of output gates.");
    }
    // now, we can instantiate the sync gate
    this.toSync = new RecordWriterBuilder<>().build(getEnvironment().getWriter(syncGateIndex));
    this.toSyncPartitionId = getEnvironment().getWriter(syncGateIndex).getPartitionId();
}
Also used : RecordWriter(org.apache.flink.runtime.io.network.api.writer.RecordWriter) RecordWriterBuilder(org.apache.flink.runtime.io.network.api.writer.RecordWriterBuilder) ArrayList(java.util.ArrayList) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) IOException(java.io.IOException)

Example 57 with TaskConfig

use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.

the class AbstractIterativeTask method initialize.

// --------------------------------------------------------------------------------------------
// Main life cycle methods that implement the iterative behavior
// --------------------------------------------------------------------------------------------
@Override
protected void initialize() throws Exception {
    super.initialize();
    // check if the driver is resettable
    if (this.driver instanceof ResettableDriver) {
        final ResettableDriver<?, ?> resDriver = (ResettableDriver<?, ?>) this.driver;
        // make sure that the according inputs are not reset
        for (int i = 0; i < resDriver.getNumberOfInputs(); i++) {
            if (resDriver.isInputResettable(i)) {
                excludeFromReset(i);
            }
        }
    }
    TaskConfig config = getLastTasksConfig();
    isWorksetIteration = config.getIsWorksetIteration();
    isWorksetUpdate = config.getIsWorksetUpdate();
    isSolutionSetUpdate = config.getIsSolutionSetUpdate();
    if (isWorksetUpdate) {
        worksetBackChannel = BlockingBackChannelBroker.instance().getAndRemove(brokerKey());
        if (isWorksetIteration) {
            worksetAggregator = getIterationAggregators().getAggregator(WorksetEmptyConvergenceCriterion.AGGREGATOR_NAME);
            if (worksetAggregator == null) {
                throw new RuntimeException("Missing workset elements count aggregator.");
            }
        }
    }
}
Also used : TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) ResettableDriver(org.apache.flink.runtime.operators.ResettableDriver)

Example 58 with TaskConfig

use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.

the class IterationSynchronizationSinkTask method invoke.

// --------------------------------------------------------------------------------------------
@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().getUserCodeClassLoader().asClassLoader());
    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++;
        }
    }
}
Also used : TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) TerminationEvent(org.apache.flink.runtime.iterative.event.TerminationEvent) IntValue(org.apache.flink.types.IntValue) AllWorkersDoneEvent(org.apache.flink.runtime.iterative.event.AllWorkersDoneEvent)

Example 59 with TaskConfig

use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.

the class ChainedAllReduceDriverTest method testMapTask.

@Test
public void testMapTask() throws Exception {
    final int keyCnt = 100;
    final int valCnt = 20;
    final double memoryFraction = 1.0;
    // environment
    initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
    mockEnv.getExecutionConfig().enableObjectReuse();
    addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
    addOutput(this.outList);
    // chained reduce config
    {
        final TaskConfig reduceConfig = new TaskConfig(new Configuration());
        // input
        reduceConfig.addInputToGroup(0);
        reduceConfig.setInputSerializer(serFact, 0);
        // output
        reduceConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
        reduceConfig.setOutputSerializer(serFact);
        // driver
        reduceConfig.setDriverStrategy(DriverStrategy.ALL_REDUCE);
        reduceConfig.setDriverComparator(compFact, 0);
        reduceConfig.setDriverComparator(compFact, 1);
        reduceConfig.setRelativeMemoryDriver(memoryFraction);
        // udf
        reduceConfig.setStubWrapper(new UserCodeClassWrapper<>(MockReduceStub.class));
        getTaskConfig().addChainedTask(ChainedAllReduceDriver.class, reduceConfig, "reduce");
    }
    // chained map+reduce
    {
        registerTask(FlatMapDriver.class, MockMapStub.class);
        BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(mockEnv);
        testTask.invoke();
    }
    int sumTotal = valCnt * keyCnt * (keyCnt - 1) / 2;
    Assert.assertEquals(1, this.outList.size());
    Assert.assertEquals(sumTotal, this.outList.get(0).getField(0, IntValue.class).getValue());
}
Also used : UserCodeClassWrapper(org.apache.flink.api.common.operators.util.UserCodeClassWrapper) Configuration(org.apache.flink.configuration.Configuration) BatchTask(org.apache.flink.runtime.operators.BatchTask) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) FlatMapDriver(org.apache.flink.runtime.operators.FlatMapDriver) MockMapStub(org.apache.flink.runtime.operators.FlatMapTaskTest.MockMapStub) Test(org.junit.Test)

Example 60 with TaskConfig

use of org.apache.flink.runtime.operators.util.TaskConfig in project flink by apache.

the class ChainTaskTest method testBatchTaskOutputInCloseMethod.

@Test
public void testBatchTaskOutputInCloseMethod() {
    final int numChainedTasks = 10;
    final int keyCnt = 100;
    final int valCnt = 10;
    try {
        initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
        addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
        addOutput(outList);
        registerTask(FlatMapDriver.class, MockMapStub.class);
        for (int i = 0; i < numChainedTasks; i++) {
            final TaskConfig taskConfig = new TaskConfig(new Configuration());
            taskConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
            taskConfig.setOutputSerializer(serFact);
            taskConfig.setStubWrapper(new UserCodeClassWrapper<>(MockDuplicateLastValueMapFunction.class));
            getTaskConfig().addChainedTask(ChainedFlatMapDriver.class, taskConfig, "chained-" + i);
        }
        final BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(mockEnv);
        testTask.invoke();
        Assert.assertEquals(keyCnt * valCnt + numChainedTasks, outList.size());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) BatchTask(org.apache.flink.runtime.operators.BatchTask) RichFlatMapFunction(org.apache.flink.api.common.functions.RichFlatMapFunction) FlatMapFunction(org.apache.flink.api.common.functions.FlatMapFunction) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) IOException(java.io.IOException) DataSourceTaskTest(org.apache.flink.runtime.operators.DataSourceTaskTest) Test(org.junit.Test)

Aggregations

TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)61 IOException (java.io.IOException)17 Configuration (org.apache.flink.configuration.Configuration)16 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)14 Test (org.junit.Test)14 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)13 BulkIterationPlanNode (org.apache.flink.optimizer.plan.BulkIterationPlanNode)9 BulkPartialSolutionPlanNode (org.apache.flink.optimizer.plan.BulkPartialSolutionPlanNode)9 DualInputPlanNode (org.apache.flink.optimizer.plan.DualInputPlanNode)9 IterationPlanNode (org.apache.flink.optimizer.plan.IterationPlanNode)9 NAryUnionPlanNode (org.apache.flink.optimizer.plan.NAryUnionPlanNode)9 PlanNode (org.apache.flink.optimizer.plan.PlanNode)9 SingleInputPlanNode (org.apache.flink.optimizer.plan.SingleInputPlanNode)9 SinkPlanNode (org.apache.flink.optimizer.plan.SinkPlanNode)9 SolutionSetPlanNode (org.apache.flink.optimizer.plan.SolutionSetPlanNode)9 SourcePlanNode (org.apache.flink.optimizer.plan.SourcePlanNode)9 WorksetIterationPlanNode (org.apache.flink.optimizer.plan.WorksetIterationPlanNode)9 WorksetPlanNode (org.apache.flink.optimizer.plan.WorksetPlanNode)9 CompilerException (org.apache.flink.optimizer.CompilerException)8 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)8