Search in sources :

Example 6 with CountingMutableObjectIterator

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

the class AllGroupCombineDriver method run.

@Override
public void run() throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("AllGroupCombine starting.");
    }
    final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    final TypeSerializerFactory<IN> serializerFactory = this.taskContext.getInputSerializer(0);
    TypeSerializer<IN> serializer = serializerFactory.getSerializer();
    final MutableObjectIterator<IN> in = new CountingMutableObjectIterator<>(this.taskContext.<IN>getInput(0), numRecordsIn);
    final GroupCombineFunction<IN, OUT> reducer = this.taskContext.getStub();
    final Collector<OUT> output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        final ReusingMutableToRegularIteratorWrapper<IN> inIter = new ReusingMutableToRegularIteratorWrapper<IN>(in, serializer);
        if (inIter.hasNext()) {
            reducer.combine(inIter, output);
        }
    } else {
        final NonReusingMutableToRegularIteratorWrapper<IN> inIter = new NonReusingMutableToRegularIteratorWrapper<IN>(in, serializer);
        if (inIter.hasNext()) {
            reducer.combine(inIter, output);
        }
    }
}
Also used : CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter) CountingMutableObjectIterator(org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator) NonReusingMutableToRegularIteratorWrapper(org.apache.flink.runtime.util.NonReusingMutableToRegularIteratorWrapper) ReusingMutableToRegularIteratorWrapper(org.apache.flink.runtime.util.ReusingMutableToRegularIteratorWrapper) NonReusingMutableToRegularIteratorWrapper(org.apache.flink.runtime.util.NonReusingMutableToRegularIteratorWrapper)

Example 7 with CountingMutableObjectIterator

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

the class CoGroupDriver method prepare.

@Override
public void prepare() throws Exception {
    final TaskConfig config = this.taskContext.getTaskConfig();
    if (config.getDriverStrategy() != DriverStrategy.CO_GROUP) {
        throw new Exception("Unrecognized driver strategy for CoGoup driver: " + config.getDriverStrategy().name());
    }
    final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    final MutableObjectIterator<IT1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
    final MutableObjectIterator<IT2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);
    // get the key positions and types
    final TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
    final TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
    final TypeComparator<IT1> groupComparator1 = this.taskContext.getDriverComparator(0);
    final TypeComparator<IT2> groupComparator2 = this.taskContext.getDriverComparator(1);
    final TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = config.getPairComparatorFactory(this.taskContext.getUserCodeClassLoader());
    if (pairComparatorFactory == null) {
        throw new Exception("Missing pair comparator factory for CoGroup driver");
    }
    ExecutionConfig executionConfig = taskContext.getExecutionConfig();
    this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();
    if (LOG.isDebugEnabled()) {
        LOG.debug("CoGroupDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
    }
    if (objectReuseEnabled) {
        // create CoGropuTaskIterator according to provided local strategy.
        this.coGroupIterator = new ReusingSortMergeCoGroupIterator<IT1, IT2>(in1, in2, serializer1, groupComparator1, serializer2, groupComparator2, pairComparatorFactory.createComparator12(groupComparator1, groupComparator2));
    } else {
        // create CoGropuTaskIterator according to provided local strategy.
        this.coGroupIterator = new NonReusingSortMergeCoGroupIterator<IT1, IT2>(in1, in2, serializer1, groupComparator1, serializer2, groupComparator2, pairComparatorFactory.createComparator12(groupComparator1, groupComparator2));
    }
    // open CoGroupTaskIterator - this triggers the sorting and blocks until the iterator is ready
    this.coGroupIterator.open();
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.taskContext.formatLogString("CoGroup task iterator ready."));
    }
}
Also used : TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Counter(org.apache.flink.metrics.Counter) CountingMutableObjectIterator(org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)

Example 8 with CountingMutableObjectIterator

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

the class MapPartitionDriver method run.

@Override
public void run() throws Exception {
    final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    // cache references on the stack
    final MutableObjectIterator<IT> input = new CountingMutableObjectIterator<>(this.taskContext.<IT>getInput(0), numRecordsIn);
    final MapPartitionFunction<IT, OT> function = this.taskContext.getStub();
    final Collector<OT> output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        final ReusingMutableToRegularIteratorWrapper<IT> inIter = new ReusingMutableToRegularIteratorWrapper<IT>(input, this.taskContext.<IT>getInputSerializer(0).getSerializer());
        function.mapPartition(inIter, output);
    } else {
        final NonReusingMutableToRegularIteratorWrapper<IT> inIter = new NonReusingMutableToRegularIteratorWrapper<IT>(input, this.taskContext.<IT>getInputSerializer(0).getSerializer());
        function.mapPartition(inIter, output);
    }
}
Also used : CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter) CountingMutableObjectIterator(org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator) ReusingMutableToRegularIteratorWrapper(org.apache.flink.runtime.util.ReusingMutableToRegularIteratorWrapper) NonReusingMutableToRegularIteratorWrapper(org.apache.flink.runtime.util.NonReusingMutableToRegularIteratorWrapper) NonReusingMutableToRegularIteratorWrapper(org.apache.flink.runtime.util.NonReusingMutableToRegularIteratorWrapper)

Example 9 with CountingMutableObjectIterator

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

the class CrossDriver method runBlockedOuterSecond.

private void runBlockedOuterSecond() throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.taskContext.formatLogString("Running Cross with Block-Nested-Loops: " + "First input is inner (spilling) side, second input is outer (blocking) side."));
    }
    final Counter numRecordsIn = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    final MutableObjectIterator<T1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<T1>getInput(0), numRecordsIn);
    final MutableObjectIterator<T2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<T2>getInput(1), numRecordsIn);
    final TypeSerializer<T1> serializer1 = this.taskContext.<T1>getInputSerializer(0).getSerializer();
    final TypeSerializer<T2> serializer2 = this.taskContext.<T2>getInputSerializer(1).getSerializer();
    final SpillingResettableMutableObjectIterator<T1> spillVals = new SpillingResettableMutableObjectIterator<T1>(in1, serializer1, this.memManager, this.taskContext.getIOManager(), this.memPagesForSpillingSide, this.taskContext.getContainingTask());
    this.spillIter = spillVals;
    final BlockResettableMutableObjectIterator<T2> blockVals = new BlockResettableMutableObjectIterator<T2>(this.memManager, in2, serializer2, this.memPagesForBlockSide, this.taskContext.getContainingTask());
    this.blockIter = blockVals;
    final CrossFunction<T1, T2, OT> crosser = this.taskContext.getStub();
    final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        final T1 val1Reuse = serializer1.createInstance();
        final T2 val2Reuse = serializer2.createInstance();
        T1 val1;
        T2 val2;
        // for all blocks
        do {
            // for all values from the spilling side
            while (this.running && ((val1 = spillVals.next(val1Reuse)) != null)) {
                // for all values in the block
                while (this.running && ((val2 = blockVals.next(val2Reuse)) != null)) {
                    collector.collect(crosser.cross(val1, val2));
                }
                blockVals.reset();
            }
            spillVals.reset();
        } while (this.running && blockVals.nextBlock());
    } else {
        T1 val1;
        T2 val2;
        // for all blocks
        do {
            // for all values from the spilling side
            while (this.running && ((val1 = spillVals.next()) != null)) {
                // for all values in the block
                while (this.running && ((val2 = blockVals.next()) != null)) {
                    collector.collect(crosser.cross(serializer1.copy(val1), val2));
                }
                blockVals.reset();
            }
            spillVals.reset();
        } while (this.running && blockVals.nextBlock());
    }
}
Also used : SpillingResettableMutableObjectIterator(org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator) BlockResettableMutableObjectIterator(org.apache.flink.runtime.operators.resettable.BlockResettableMutableObjectIterator) CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter) CountingMutableObjectIterator(org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)

Example 10 with CountingMutableObjectIterator

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

the class CrossDriver method runStreamedOuterFirst.

private void runStreamedOuterFirst() throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.taskContext.formatLogString("Running Cross with Nested-Loops: " + "First input is outer side, second input is inner (spilling) side."));
    }
    final Counter numRecordsIn = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    final MutableObjectIterator<T1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<T1>getInput(0), numRecordsIn);
    final MutableObjectIterator<T2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<T2>getInput(1), numRecordsIn);
    final TypeSerializer<T1> serializer1 = this.taskContext.<T1>getInputSerializer(0).getSerializer();
    final TypeSerializer<T2> serializer2 = this.taskContext.<T2>getInputSerializer(1).getSerializer();
    final SpillingResettableMutableObjectIterator<T2> spillVals = new SpillingResettableMutableObjectIterator<T2>(in2, serializer2, this.memManager, this.taskContext.getIOManager(), this.memPagesForSpillingSide, this.taskContext.getContainingTask());
    this.spillIter = spillVals;
    final CrossFunction<T1, T2, OT> crosser = this.taskContext.getStub();
    final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        final T1 val1Reuse = serializer1.createInstance();
        final T2 val2Reuse = serializer2.createInstance();
        T1 val1;
        T2 val2;
        // for all blocks
        while (this.running && ((val1 = in1.next(val1Reuse)) != null)) {
            // for all values from the spilling side
            while (this.running && ((val2 = spillVals.next(val2Reuse)) != null)) {
                collector.collect(crosser.cross(val1, val2));
            }
            spillVals.reset();
        }
    } else {
        T1 val1;
        T2 val2;
        // for all blocks
        while (this.running && ((val1 = in1.next()) != null)) {
            // for all values from the spilling side
            while (this.running && ((val2 = spillVals.next()) != null)) {
                collector.collect(crosser.cross(serializer1.copy(val1), val2));
            }
            spillVals.reset();
        }
    }
}
Also used : SpillingResettableMutableObjectIterator(org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator) CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter) CountingMutableObjectIterator(org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)

Aggregations

Counter (org.apache.flink.metrics.Counter)10 CountingMutableObjectIterator (org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)10 CountingCollector (org.apache.flink.runtime.operators.util.metrics.CountingCollector)6 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)4 SpillingResettableMutableObjectIterator (org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator)4 TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)4 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)2 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)2 BlockResettableMutableObjectIterator (org.apache.flink.runtime.operators.resettable.BlockResettableMutableObjectIterator)2 NonReusingMutableToRegularIteratorWrapper (org.apache.flink.runtime.util.NonReusingMutableToRegularIteratorWrapper)2 ReusingMutableToRegularIteratorWrapper (org.apache.flink.runtime.util.ReusingMutableToRegularIteratorWrapper)2 NonReusingBuildSecondReOpenableHashJoinIterator (org.apache.flink.runtime.operators.hash.NonReusingBuildSecondReOpenableHashJoinIterator)1 ReusingBuildSecondReOpenableHashJoinIterator (org.apache.flink.runtime.operators.hash.ReusingBuildSecondReOpenableHashJoinIterator)1