org.apache.flink.runtime.operators.util.metrics.CountingCollector Java Examples

The following examples show how to use org.apache.flink.runtime.operators.util.metrics.CountingCollector. 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: UnionWithTempOperator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	
	final Collector<T> output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	T reuse = this.taskContext.<T>getInputSerializer(STREAMED_INPUT).getSerializer().createInstance();
	T record;
	
	final MutableObjectIterator<T> input = this.taskContext.getInput(STREAMED_INPUT);
	while (this.running && ((record = input.next(reuse)) != null)) {
		numRecordsIn.inc();
		output.collect(record);
	}
	
	final MutableObjectIterator<T> cache = this.taskContext.getInput(CACHED_INPUT);
	while (this.running && ((record = cache.next(reuse)) != null)) {
		numRecordsIn.inc();
		output.collect(record);
	}
}
 
Example #2
Source File: UnionWithTempOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	
	final Collector<T> output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	T reuse = this.taskContext.<T>getInputSerializer(STREAMED_INPUT).getSerializer().createInstance();
	T record;
	
	final MutableObjectIterator<T> input = this.taskContext.getInput(STREAMED_INPUT);
	while (this.running && ((record = input.next(reuse)) != null)) {
		numRecordsIn.inc();
		output.collect(record);
	}
	
	final MutableObjectIterator<T> cache = this.taskContext.getInput(CACHED_INPUT);
	while (this.running && ((record = cache.next(reuse)) != null)) {
		numRecordsIn.inc();
		output.collect(record);
	}
}
 
Example #3
Source File: UnionWithTempOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	
	final Collector<T> output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	T reuse = this.taskContext.<T>getInputSerializer(STREAMED_INPUT).getSerializer().createInstance();
	T record;
	
	final MutableObjectIterator<T> input = this.taskContext.getInput(STREAMED_INPUT);
	while (this.running && ((record = input.next(reuse)) != null)) {
		numRecordsIn.inc();
		output.collect(record);
	}
	
	final MutableObjectIterator<T> cache = this.taskContext.getInput(CACHED_INPUT);
	while (this.running && ((record = cache.next(reuse)) != null)) {
		numRecordsIn.inc();
		output.collect(record);
	}
}
 
Example #4
Source File: CoGroupDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception
{
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();

	final CoGroupFunction<IT1, IT2, OT> coGroupStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final CoGroupTaskIterator<IT1, IT2> coGroupIterator = this.coGroupIterator;
	
	while (this.running && coGroupIterator.next()) {
		coGroupStub.coGroup(coGroupIterator.getValues1(), coGroupIterator.getValues2(), collector);
	}
}
 
Example #5
Source File: AbstractOuterJoinDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	
	final FlatJoinFunction<IT1, IT2, OT> joinStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final JoinTaskIterator<IT1, IT2, OT> outerJoinIterator = this.outerJoinIterator;
	
	while (this.running && outerJoinIterator.callWithNextKey(joinStub, collector)) {
	}
}
 
Example #6
Source File: JoinDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	final FlatJoinFunction<IT1, IT2, OT> joinStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final JoinTaskIterator<IT1, IT2, OT> joinIterator = this.joinIterator;
	
	while (this.running && joinIterator.callWithNextKey(joinStub, collector)) {
	}
}
 
Example #7
Source File: AbstractCachedBuildSideJoinDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	final FlatJoinFunction<IT1, IT2, OT> matchStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	
	while (this.running && matchIterator != null && matchIterator.callWithNextKey(matchStub, collector)) {
	}
}
 
Example #8
Source File: ChainedDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
public void setup(TaskConfig config, String taskName, Collector<OT> outputCollector,
		AbstractInvokable parent, ClassLoader userCodeClassLoader, ExecutionConfig executionConfig,
		Map<String, Accumulator<?,?>> accumulatorMap)
{
	this.config = config;
	this.taskName = taskName;
	this.userCodeClassLoader = userCodeClassLoader;
	this.metrics = parent.getEnvironment().getMetricGroup().getOrAddOperator(taskName);
	this.numRecordsIn = this.metrics.getIOMetricGroup().getNumRecordsInCounter();
	this.numRecordsOut = this.metrics.getIOMetricGroup().getNumRecordsOutCounter();
	this.outputCollector = new CountingCollector<>(outputCollector, numRecordsOut);

	Environment env = parent.getEnvironment();

	if (parent instanceof BatchTask) {
		this.udfContext = ((BatchTask<?, ?>) parent).createRuntimeContext(metrics);
	} else {
		this.udfContext = new DistributedRuntimeUDFContext(env.getTaskInfo(), userCodeClassLoader,
				parent.getExecutionConfig(), env.getDistributedCacheEntries(), accumulatorMap, metrics, env.getExternalResourceInfoProvider()
		);
	}

	this.executionConfig = executionConfig;
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	setup(parent);
}
 
Example #9
Source File: CoGroupDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception
{
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();

	final CoGroupFunction<IT1, IT2, OT> coGroupStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final CoGroupTaskIterator<IT1, IT2> coGroupIterator = this.coGroupIterator;
	
	while (this.running && coGroupIterator.next()) {
		coGroupStub.coGroup(coGroupIterator.getValues1(), coGroupIterator.getValues2(), collector);
	}
}
 
Example #10
Source File: AbstractOuterJoinDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	
	final FlatJoinFunction<IT1, IT2, OT> joinStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final JoinTaskIterator<IT1, IT2, OT> outerJoinIterator = this.outerJoinIterator;
	
	while (this.running && outerJoinIterator.callWithNextKey(joinStub, collector)) {
	}
}
 
Example #11
Source File: JoinDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	final FlatJoinFunction<IT1, IT2, OT> joinStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final JoinTaskIterator<IT1, IT2, OT> joinIterator = this.joinIterator;
	
	while (this.running && joinIterator.callWithNextKey(joinStub, collector)) {
	}
}
 
Example #12
Source File: AbstractCachedBuildSideJoinDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	final FlatJoinFunction<IT1, IT2, OT> matchStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	
	while (this.running && matchIterator != null && matchIterator.callWithNextKey(matchStub, collector)) {
	}
}
 
Example #13
Source File: ChainedDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
public void setup(TaskConfig config, String taskName, Collector<OT> outputCollector,
		AbstractInvokable parent, ClassLoader userCodeClassLoader, ExecutionConfig executionConfig,
		Map<String, Accumulator<?,?>> accumulatorMap)
{
	this.config = config;
	this.taskName = taskName;
	this.userCodeClassLoader = userCodeClassLoader;
	this.metrics = parent.getEnvironment().getMetricGroup().getOrAddOperator(taskName);
	this.numRecordsIn = this.metrics.getIOMetricGroup().getNumRecordsInCounter();
	this.numRecordsOut = this.metrics.getIOMetricGroup().getNumRecordsOutCounter();
	this.outputCollector = new CountingCollector<>(outputCollector, numRecordsOut);

	Environment env = parent.getEnvironment();

	if (parent instanceof BatchTask) {
		this.udfContext = ((BatchTask<?, ?>) parent).createRuntimeContext(metrics);
	} else {
		this.udfContext = new DistributedRuntimeUDFContext(env.getTaskInfo(), userCodeClassLoader,
				parent.getExecutionConfig(), env.getDistributedCacheEntries(), accumulatorMap, metrics
		);
	}

	this.executionConfig = executionConfig;
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	setup(parent);
}
 
Example #14
Source File: CoGroupDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception
{
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();

	final CoGroupFunction<IT1, IT2, OT> coGroupStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final CoGroupTaskIterator<IT1, IT2> coGroupIterator = this.coGroupIterator;
	
	while (this.running && coGroupIterator.next()) {
		coGroupStub.coGroup(coGroupIterator.getValues1(), coGroupIterator.getValues2(), collector);
	}
}
 
Example #15
Source File: AbstractOuterJoinDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	
	final FlatJoinFunction<IT1, IT2, OT> joinStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final JoinTaskIterator<IT1, IT2, OT> outerJoinIterator = this.outerJoinIterator;
	
	while (this.running && outerJoinIterator.callWithNextKey(joinStub, collector)) {
	}
}
 
Example #16
Source File: JoinDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	final FlatJoinFunction<IT1, IT2, OT> joinStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	final JoinTaskIterator<IT1, IT2, OT> joinIterator = this.joinIterator;
	
	while (this.running && joinIterator.callWithNextKey(joinStub, collector)) {
	}
}
 
Example #17
Source File: AbstractCachedBuildSideJoinDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
	final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
	final FlatJoinFunction<IT1, IT2, OT> matchStub = this.taskContext.getStub();
	final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
	
	while (this.running && matchIterator != null && matchIterator.callWithNextKey(matchStub, collector)) {
	}
}
 
Example #18
Source File: ChainedDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public void setup(TaskConfig config, String taskName, Collector<OT> outputCollector,
		AbstractInvokable parent, ClassLoader userCodeClassLoader, ExecutionConfig executionConfig,
		Map<String, Accumulator<?,?>> accumulatorMap)
{
	this.config = config;
	this.taskName = taskName;
	this.userCodeClassLoader = userCodeClassLoader;
	this.metrics = parent.getEnvironment().getMetricGroup().getOrAddOperator(taskName);
	this.numRecordsIn = this.metrics.getIOMetricGroup().getNumRecordsInCounter();
	this.numRecordsOut = this.metrics.getIOMetricGroup().getNumRecordsOutCounter();
	this.outputCollector = new CountingCollector<>(outputCollector, numRecordsOut);

	Environment env = parent.getEnvironment();

	if (parent instanceof BatchTask) {
		this.udfContext = ((BatchTask<?, ?>) parent).createRuntimeContext(metrics);
	} else {
		this.udfContext = new DistributedRuntimeUDFContext(env.getTaskInfo(), userCodeClassLoader,
				parent.getExecutionConfig(), env.getDistributedCacheEntries(), accumulatorMap, metrics
		);
	}

	this.executionConfig = executionConfig;
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	setup(parent);
}
 
Example #19
Source File: ChainedDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void setOutputCollector(Collector<?> outputCollector) {
	this.outputCollector = new CountingCollector<>((Collector<OT>) outputCollector, numRecordsOut);
}
 
Example #20
Source File: ReduceCombineDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception {
	final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();

	strategy = taskContext.getTaskConfig().getDriverStrategy();

	// instantiate the serializer / comparator
	final TypeSerializerFactory<T> serializerFactory = taskContext.getInputSerializer(0);
	comparator = taskContext.getDriverComparator(0);
	serializer = serializerFactory.getSerializer();
	reducer = taskContext.getStub();
	output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);

	MemoryManager memManager = taskContext.getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(
		taskContext.getTaskConfig().getRelativeMemoryDriver());
	memory = memManager.allocatePages(taskContext.getContainingTask(), numMemoryPages);

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("ReduceCombineDriver object reuse: " + (objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}

	switch (strategy) {
		case SORTED_PARTIAL_REDUCE:
			// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
			if (comparator.supportsSerializationWithKeyNormalization() &&
				serializer.getLength() > 0 && serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING) {
				sorter = new FixedLengthRecordSorter<T>(serializer, comparator.duplicate(), memory);
			} else {
				sorter = new NormalizedKeySorter<T>(serializer, comparator.duplicate(), memory);
			}
			break;
		case HASHED_PARTIAL_REDUCE:
			table = new InPlaceMutableHashTable<T>(serializer, comparator, memory);
			reduceFacade = table.new ReduceFacade(reducer, output, objectReuseEnabled);
			break;
		default:
			throw new Exception("Invalid strategy " + taskContext.getTaskConfig().getDriverStrategy() + " for reduce combiner.");
	}
}
 
Example #21
Source File: ReduceCombineDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception {
	final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();

	strategy = taskContext.getTaskConfig().getDriverStrategy();

	// instantiate the serializer / comparator
	final TypeSerializerFactory<T> serializerFactory = taskContext.getInputSerializer(0);
	comparator = taskContext.getDriverComparator(0);
	serializer = serializerFactory.getSerializer();
	reducer = taskContext.getStub();
	output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);

	MemoryManager memManager = taskContext.getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(
		taskContext.getTaskConfig().getRelativeMemoryDriver());
	memory = memManager.allocatePages(taskContext.getContainingTask(), numMemoryPages);

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("ReduceCombineDriver object reuse: " + (objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}

	switch (strategy) {
		case SORTED_PARTIAL_REDUCE:
			// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
			if (comparator.supportsSerializationWithKeyNormalization() &&
				serializer.getLength() > 0 && serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING) {
				sorter = new FixedLengthRecordSorter<T>(serializer, comparator.duplicate(), memory);
			} else {
				sorter = new NormalizedKeySorter<T>(serializer, comparator.duplicate(), memory);
			}
			break;
		case HASHED_PARTIAL_REDUCE:
			table = new InPlaceMutableHashTable<T>(serializer, comparator, memory);
			reduceFacade = table.new ReduceFacade(reducer, output, objectReuseEnabled);
			break;
		default:
			throw new Exception("Invalid strategy " + taskContext.getTaskConfig().getDriverStrategy() + " for reduce combiner.");
	}
}
 
Example #22
Source File: ChainedDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void setOutputCollector(Collector<?> outputCollector) {
	this.outputCollector = new CountingCollector<>((Collector<OT>) outputCollector, numRecordsOut);
}
 
Example #23
Source File: ChainedDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void setOutputCollector(Collector<?> outputCollector) {
	this.outputCollector = new CountingCollector<>((Collector<OT>) outputCollector, numRecordsOut);
}
 
Example #24
Source File: ReduceCombineDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception {
	final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();

	strategy = taskContext.getTaskConfig().getDriverStrategy();

	// instantiate the serializer / comparator
	final TypeSerializerFactory<T> serializerFactory = taskContext.getInputSerializer(0);
	comparator = taskContext.getDriverComparator(0);
	serializer = serializerFactory.getSerializer();
	reducer = taskContext.getStub();
	output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);

	MemoryManager memManager = taskContext.getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(
		taskContext.getTaskConfig().getRelativeMemoryDriver());
	memory = memManager.allocatePages(taskContext.getContainingTask(), numMemoryPages);

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("ReduceCombineDriver object reuse: " + (objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}

	switch (strategy) {
		case SORTED_PARTIAL_REDUCE:
			// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
			if (comparator.supportsSerializationWithKeyNormalization() &&
				serializer.getLength() > 0 && serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING) {
				sorter = new FixedLengthRecordSorter<T>(serializer, comparator.duplicate(), memory);
			} else {
				sorter = new NormalizedKeySorter<T>(serializer, comparator.duplicate(), memory);
			}
			break;
		case HASHED_PARTIAL_REDUCE:
			table = new InPlaceMutableHashTable<T>(serializer, comparator, memory);
			reduceFacade = table.new ReduceFacade(reducer, output, objectReuseEnabled);
			break;
		default:
			throw new Exception("Invalid strategy " + taskContext.getTaskConfig().getDriverStrategy() + " for reduce combiner.");
	}
}