Search in sources :

Example 11 with Counter

use of org.apache.flink.metrics.Counter in project flink by apache.

the class GroupReduceDriver method prepare.

// --------------------------------------------------------------------------------------------
@Override
public void prepare() throws Exception {
    TaskConfig config = this.taskContext.getTaskConfig();
    if (config.getDriverStrategy() != DriverStrategy.SORTED_GROUP_REDUCE) {
        throw new Exception("Unrecognized driver strategy for GroupReduce driver: " + config.getDriverStrategy().name());
    }
    final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    this.serializer = this.taskContext.<IT>getInputSerializer(0).getSerializer();
    this.comparator = this.taskContext.getDriverComparator(0);
    this.input = new CountingMutableObjectIterator<>(this.taskContext.<IT>getInput(0), numRecordsIn);
    ExecutionConfig executionConfig = taskContext.getExecutionConfig();
    this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();
    if (LOG.isDebugEnabled()) {
        LOG.debug("GroupReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
    }
}
Also used : Counter(org.apache.flink.metrics.Counter) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig)

Example 12 with Counter

use of org.apache.flink.metrics.Counter in project flink by apache.

the class GroupReduceDriver method run.

@Override
public void run() throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.taskContext.formatLogString("GroupReducer preprocessing done. Running GroupReducer code."));
    }
    final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    // cache references on the stack
    final GroupReduceFunction<IT, OT> stub = this.taskContext.getStub();
    final Collector<OT> output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        final ReusingKeyGroupedIterator<IT> iter = new ReusingKeyGroupedIterator<IT>(this.input, this.serializer, this.comparator);
        // run stub implementation
        while (this.running && iter.nextKey()) {
            stub.reduce(iter.getValues(), output);
        }
    } else {
        final NonReusingKeyGroupedIterator<IT> iter = new NonReusingKeyGroupedIterator<IT>(this.input, this.comparator);
        // run stub implementation
        while (this.running && iter.nextKey()) {
            stub.reduce(iter.getValues(), output);
        }
    }
}
Also used : CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter) NonReusingKeyGroupedIterator(org.apache.flink.runtime.util.NonReusingKeyGroupedIterator) ReusingKeyGroupedIterator(org.apache.flink.runtime.util.ReusingKeyGroupedIterator) NonReusingKeyGroupedIterator(org.apache.flink.runtime.util.NonReusingKeyGroupedIterator)

Example 13 with Counter

use of org.apache.flink.metrics.Counter in project flink by apache.

the class JoinDriver method prepare.

@Override
public void prepare() throws Exception {
    final TaskConfig config = this.taskContext.getTaskConfig();
    final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    // obtain task manager's memory manager and I/O manager
    final MemoryManager memoryManager = this.taskContext.getMemoryManager();
    final IOManager ioManager = this.taskContext.getIOManager();
    // set up memory and I/O parameters
    final double fractionAvailableMemory = config.getRelativeMemoryDriver();
    final int numPages = memoryManager.computeNumberOfPages(fractionAvailableMemory);
    // test minimum memory requirements
    final DriverStrategy ls = config.getDriverStrategy();
    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> comparator1 = this.taskContext.getDriverComparator(0);
    final TypeComparator<IT2> comparator2 = 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 join driver");
    }
    ExecutionConfig executionConfig = taskContext.getExecutionConfig();
    boolean objectReuseEnabled = executionConfig.isObjectReuseEnabled();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Join Driver object reuse: " + (objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
    }
    boolean hashJoinUseBitMaps = taskContext.getTaskManagerInfo().getConfiguration().getBoolean(ConfigConstants.RUNTIME_HASH_JOIN_BLOOM_FILTERS_KEY, ConfigConstants.DEFAULT_RUNTIME_HASH_JOIN_BLOOM_FILTERS);
    // create and return joining iterator according to provided local strategy.
    if (objectReuseEnabled) {
        switch(ls) {
            case INNER_MERGE:
                this.joinIterator = new ReusingMergeInnerJoinIterator<>(in1, in2, serializer1, comparator1, serializer2, comparator2, pairComparatorFactory.createComparator12(comparator1, comparator2), memoryManager, ioManager, numPages, this.taskContext.getContainingTask());
                break;
            case HYBRIDHASH_BUILD_FIRST:
                this.joinIterator = new ReusingBuildFirstHashJoinIterator<>(in1, in2, serializer1, comparator1, serializer2, comparator2, pairComparatorFactory.createComparator21(comparator1, comparator2), memoryManager, ioManager, this.taskContext.getContainingTask(), fractionAvailableMemory, false, false, hashJoinUseBitMaps);
                break;
            case HYBRIDHASH_BUILD_SECOND:
                this.joinIterator = new ReusingBuildSecondHashJoinIterator<>(in1, in2, serializer1, comparator1, serializer2, comparator2, pairComparatorFactory.createComparator12(comparator1, comparator2), memoryManager, ioManager, this.taskContext.getContainingTask(), fractionAvailableMemory, false, false, hashJoinUseBitMaps);
                break;
            default:
                throw new Exception("Unsupported driver strategy for join driver: " + ls.name());
        }
    } else {
        switch(ls) {
            case INNER_MERGE:
                this.joinIterator = new NonReusingMergeInnerJoinIterator<>(in1, in2, serializer1, comparator1, serializer2, comparator2, pairComparatorFactory.createComparator12(comparator1, comparator2), memoryManager, ioManager, numPages, this.taskContext.getContainingTask());
                break;
            case HYBRIDHASH_BUILD_FIRST:
                this.joinIterator = new NonReusingBuildFirstHashJoinIterator<>(in1, in2, serializer1, comparator1, serializer2, comparator2, pairComparatorFactory.createComparator21(comparator1, comparator2), memoryManager, ioManager, this.taskContext.getContainingTask(), fractionAvailableMemory, false, false, hashJoinUseBitMaps);
                break;
            case HYBRIDHASH_BUILD_SECOND:
                this.joinIterator = new NonReusingBuildSecondHashJoinIterator<>(in1, in2, serializer1, comparator1, serializer2, comparator2, pairComparatorFactory.createComparator12(comparator1, comparator2), memoryManager, ioManager, this.taskContext.getContainingTask(), fractionAvailableMemory, false, false, hashJoinUseBitMaps);
                break;
            default:
                throw new Exception("Unsupported driver strategy for join driver: " + ls.name());
        }
    }
    // open the iterator - this triggers the sorting or hash-table building
    // and blocks until the iterator is ready
    this.joinIterator.open();
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.taskContext.formatLogString("join 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) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) MemoryManager(org.apache.flink.runtime.memory.MemoryManager)

Example 14 with Counter

use of org.apache.flink.metrics.Counter in project flink by apache.

the class MapDriver 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 = this.taskContext.getInput(0);
    final MapFunction<IT, OT> function = this.taskContext.getStub();
    final Collector<OT> output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        IT record = this.taskContext.<IT>getInputSerializer(0).getSerializer().createInstance();
        while (this.running && ((record = input.next(record)) != null)) {
            numRecordsIn.inc();
            output.collect(function.map(record));
        }
    } else {
        IT record = null;
        while (this.running && ((record = input.next()) != null)) {
            numRecordsIn.inc();
            output.collect(function.map(record));
        }
    }
}
Also used : CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter)

Example 15 with Counter

use of org.apache.flink.metrics.Counter in project flink by apache.

the class ReduceDriver method run.

@Override
public void run() throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug(this.taskContext.formatLogString("Reducer preprocessing done. Running Reducer code."));
    }
    final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
    final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
    // cache references on the stack
    final MutableObjectIterator<T> input = this.input;
    final TypeSerializer<T> serializer = this.serializer;
    final TypeComparator<T> comparator = this.comparator;
    final ReduceFunction<T> function = this.taskContext.getStub();
    final Collector<T> output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
    if (objectReuseEnabled) {
        // We only need two objects. The first reference stores results and is
        // eventually collected. New values are read into the second.
        //
        // The output value must have the same key fields as the input values.
        T reuse1 = input.next();
        T reuse2 = serializer.createInstance();
        T value = reuse1;
        // iterate over key groups
        while (this.running && value != null) {
            numRecordsIn.inc();
            comparator.setReference(value);
            // iterate within a key group
            while ((reuse2 = input.next(reuse2)) != null) {
                numRecordsIn.inc();
                if (comparator.equalToReference(reuse2)) {
                    // same group, reduce
                    value = function.reduce(value, reuse2);
                    // by the user, so swap the reuse objects
                    if (value == reuse2) {
                        T tmp = reuse1;
                        reuse1 = reuse2;
                        reuse2 = tmp;
                    }
                } else {
                    // new key group
                    break;
                }
            }
            output.collect(value);
            // swap the value from the new key group into the first object
            T tmp = reuse1;
            reuse1 = reuse2;
            reuse2 = tmp;
            value = reuse1;
        }
    } else {
        T value = input.next();
        // iterate over key groups
        while (this.running && value != null) {
            numRecordsIn.inc();
            comparator.setReference(value);
            T res = value;
            // iterate within a key group
            while ((value = input.next()) != null) {
                numRecordsIn.inc();
                if (comparator.equalToReference(value)) {
                    // same group, reduce
                    res = function.reduce(res, value);
                } else {
                    // new key group
                    break;
                }
            }
            output.collect(res);
        }
    }
}
Also used : CountingCollector(org.apache.flink.runtime.operators.util.metrics.CountingCollector) Counter(org.apache.flink.metrics.Counter)

Aggregations

Counter (org.apache.flink.metrics.Counter)39 CountingCollector (org.apache.flink.runtime.operators.util.metrics.CountingCollector)18 CountingMutableObjectIterator (org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)10 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)8 Histogram (org.apache.flink.metrics.Histogram)8 Meter (org.apache.flink.metrics.Meter)8 Gauge (org.apache.flink.metrics.Gauge)7 SimpleCounter (org.apache.flink.metrics.SimpleCounter)7 Test (org.junit.Test)7 TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)5 Configuration (org.apache.flink.configuration.Configuration)4 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)4 MetricRegistryConfiguration (org.apache.flink.runtime.metrics.MetricRegistryConfiguration)4 TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)4 SpillingResettableMutableObjectIterator (org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator)4 IOException (java.io.IOException)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 TaskManagerJobMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerJobMetricGroup)3 TaskMetricGroup (org.apache.flink.runtime.metrics.groups.TaskMetricGroup)3 TestingHistogram (org.apache.flink.runtime.metrics.util.TestingHistogram)3