reuvenlax commented on code in PR #41544: URL: https://github.com/apache/beam/pull/41544#discussion_r4672779912
########## runners/google-cloud-dataflow-java/worker/jmh/src/main/java/org/apache/beam/runners/dataflow/worker/jmh/ExecutionStateTrackerBenchmark.java: ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.runners.dataflow.worker.jmh; + +import java.io.Closeable; +import java.util.concurrent.TimeUnit; +import org.apache.beam.runners.core.metrics.ExecutionStateSampler; +import org.apache.beam.runners.core.metrics.ExecutionStateTracker; +import org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState; +import org.apache.beam.runners.dataflow.options.DataflowPipelineOptions; +import org.apache.beam.runners.dataflow.worker.BatchModeExecutionContext; +import org.apache.beam.runners.dataflow.worker.DataflowOperationContext; +import org.apache.beam.runners.dataflow.worker.counters.NameContext; +import org.apache.beam.sdk.options.PipelineOptions; +import org.apache.beam.sdk.options.PipelineOptionsFactory; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; + +/** + * Microbenchmarks for {@link ExecutionStateTracker} and {@link DataflowOperationContext} state + * transitions on the per-element hot path. + */ +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +public class ExecutionStateTrackerBenchmark { + + private static final class SimpleExecutionState extends ExecutionState { + SimpleExecutionState(String stateName) { + super(stateName); + } + + @Override + public void takeSample(long millisSinceLastSample) {} + + @Override + public void reportLull(Thread trackedThread, long millis) {} + } + + @State(Scope.Thread) + public static class BatchTrackerState { + DataflowOperationContext op1; + DataflowOperationContext op2; + DataflowOperationContext op3; + DataflowOperationContext op4; + Closeable batchActivation; + + @Setup + public void setUp() { + PipelineOptions options = PipelineOptionsFactory.create(); + BatchModeExecutionContext execContext = BatchModeExecutionContext.forTesting(options, "S01"); + batchActivation = execContext.getExecutionStateTracker().activate(); + op1 = execContext.createOperationContext(NameContext.create("S01", "s1", "s1", "Step1")); + op2 = execContext.createOperationContext(NameContext.create("S01", "s2", "s2", "Step2")); + op3 = execContext.createOperationContext(NameContext.create("S01", "s3", "s3", "Step3")); + op4 = execContext.createOperationContext(NameContext.create("S01", "s4", "s4", "Step4")); + } + + @TearDown + public void tearDown() throws Exception { + if (batchActivation != null) { + batchActivation.close(); + } + } + } + + @State(Scope.Thread) + public static class StreamingTrackerState { + DataflowOperationContext op1; + DataflowOperationContext op2; + DataflowOperationContext op3; + DataflowOperationContext op4; + Closeable streamingActivation; + + @Setup + public void setUp() { + DataflowPipelineOptions options = PipelineOptionsFactory.as(DataflowPipelineOptions.class); + options.setStreaming(true); + BatchModeExecutionContext execContext = BatchModeExecutionContext.forTesting(options, "S01"); Review Comment: Done — updated StreamingTrackerState to use a real StreamingModeExecutionContext (with StreamingModeExecutionStateRegistry, streaming-enabled DataflowExecutionStateTracker, FixedGlobalConfigHandle, and a direct-executor ReaderCache) via WorkerJmhAccess.createStreamingExecutionContext(...). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
