use of org.apache.beam.runners.core.metrics.ExecutionStateSampler in project beam by apache.
the class MapTaskExecutorTest method testPerElementProcessingTimeCounters.
/**
* Verify counts for the per-element-output-time counter are correct.
*/
@Test
public void testPerElementProcessingTimeCounters() throws Exception {
PipelineOptions options = PipelineOptionsFactory.create();
options.as(DataflowPipelineDebugOptions.class).setExperiments(Lists.newArrayList(DataflowElementExecutionTracker.TIME_PER_ELEMENT_EXPERIMENT));
ExecutionStateSampler stateSampler = ExecutionStateSampler.newForTest();
DataflowExecutionStateTracker stateTracker = new DataflowExecutionStateTracker(stateSampler, new TestDataflowExecutionState(NameContext.forStage("test-stage"), "other", null, /* requestingStepName */
null, /* sideInputIndex */
null, /* metricsContainer */
NoopProfileScope.NOOP), counterSet, options, "test-work-item-id");
NameContext parDoName = nameForStep("s1");
// Wire a read operation with 3 elements to a ParDoOperation and assert that we count
// the correct number of elements.
ReadOperation read = ReadOperation.forTest(new TestReader("a", "b", "c"), new OutputReceiver(), TestOperationContext.create(counterSet, nameForStep("s0"), null, stateTracker));
ParDoOperation parDo = new ParDoOperation(new NoopParDoFn(), new OutputReceiver[0], TestOperationContext.create(counterSet, parDoName, null, stateTracker));
parDo.attachInput(read, 0);
List<Operation> operations = Lists.newArrayList(read, parDo);
try (MapTaskExecutor executor = new MapTaskExecutor(operations, counterSet, stateTracker)) {
executor.execute();
}
stateSampler.doSampling(100L);
CounterName counterName = CounterName.named("per-element-processing-time").withOriginalName(parDoName);
Counter<Long, CounterDistribution> counter = (Counter<Long, CounterDistribution>) counterSet.getExistingCounter(counterName);
assertThat(counter.getAggregate().getCount(), equalTo(3L));
}
use of org.apache.beam.runners.core.metrics.ExecutionStateSampler in project beam by apache.
the class StreamingModeExecutionContextTest method stateSamplingInStreaming.
@Test(timeout = 2000)
public void stateSamplingInStreaming() {
// Test that when writing on one thread and reading from another, updates always eventually
// reach the reading thread.
StreamingModeExecutionState state = new StreamingModeExecutionState(NameContextsForTests.nameContextForTest(), "testState", null, NoopProfileScope.NOOP, null);
ExecutionStateSampler sampler = ExecutionStateSampler.newForTest();
try {
sampler.start();
ExecutionStateTracker tracker = new ExecutionStateTracker(sampler);
Thread executionThread = new Thread();
executionThread.setName("looping-thread-for-test");
tracker.activate(executionThread);
tracker.enterState(state);
// Wait for the state to be incremented 3 times
for (int i = 0; i < 3; i++) {
CounterUpdate update = null;
while (update == null) {
update = state.extractUpdate(false);
}
long newValue = splitIntToLong(update.getInteger());
assertThat(newValue, Matchers.greaterThan(0L));
}
} finally {
sampler.stop();
}
}
use of org.apache.beam.runners.core.metrics.ExecutionStateSampler in project beam by apache.
the class BatchModeExecutionContextTest method stateSamplingInBatch.
@Test(timeout = 2000)
public void stateSamplingInBatch() {
// Test that when writing on one thread and reading from another, updates always eventually
// reach the reading thread.
BatchModeExecutionState state = new BatchModeExecutionState(NameContextsForTests.nameContextForTest(), "testState", null, /* requestingStepName */
null, /* inputIndex */
null, /* metricsContainer */
NoopProfileScope.NOOP);
ExecutionStateSampler sampler = ExecutionStateSampler.newForTest();
try {
sampler.start();
ExecutionStateTracker tracker = new ExecutionStateTracker(sampler);
Thread executionThread = new Thread();
executionThread.setName("looping-thread-for-test");
tracker.activate(executionThread);
tracker.enterState(state);
// Wait for the state to be incremented 3 times
long value = 0;
for (int i = 0; i < 3; i++) {
CounterUpdate update = null;
while (update == null) {
update = state.extractUpdate(false);
}
long newValue = splitIntToLong(update.getInteger());
assertThat(newValue, Matchers.greaterThan(value));
value = newValue;
}
} finally {
sampler.stop();
}
}
Aggregations