scwhittle commented on code in PR #41544:
URL: https://github.com/apache/beam/pull/41544#discussion_r4737816213


##########
runners/google-cloud-dataflow-java/worker/jmh/build.gradle:
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one

Review Comment:
   for the fnapi benchmarks, it seemed to run them every presubmit.  Do you 
know if that is the case here? If so can we change it so that it only runs with 
some specific option



##########
runners/google-cloud-dataflow-java/worker/jmh/src/main/java/org/apache/beam/runners/dataflow/worker/jmh/ParDoDispatchBenchmark.java:
##########
@@ -0,0 +1,647 @@
+/*
+ * 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 static org.apache.beam.runners.dataflow.util.Structs.addString;
+
+import com.google.api.services.dataflow.model.InstructionInput;
+import com.google.api.services.dataflow.model.InstructionOutput;
+import com.google.api.services.dataflow.model.MapTask;
+import com.google.api.services.dataflow.model.MultiOutputInfo;
+import com.google.api.services.dataflow.model.ParDoInstruction;
+import com.google.api.services.dataflow.model.ParallelInstruction;
+import com.google.api.services.dataflow.model.ReadInstruction;
+import com.google.api.services.dataflow.model.Source;
+import com.google.api.services.dataflow.model.WriteInstruction;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import org.apache.beam.runners.core.DoFnRunner;
+import org.apache.beam.runners.core.DoFnRunners;
+import org.apache.beam.runners.core.NullSideInputReader;
+import org.apache.beam.runners.dataflow.util.CloudObject;
+import org.apache.beam.runners.dataflow.util.CloudObjects;
+import org.apache.beam.runners.dataflow.util.PropertyNames;
+import org.apache.beam.runners.dataflow.worker.BatchModeExecutionContext;
+import org.apache.beam.runners.dataflow.worker.DataflowExecutionContext;
+import org.apache.beam.runners.dataflow.worker.DataflowMapTaskExecutor;
+import org.apache.beam.runners.dataflow.worker.DataflowOperationContext;
+import org.apache.beam.runners.dataflow.worker.IntrinsicMapTaskExecutorFactory;
+import org.apache.beam.runners.dataflow.worker.ReaderFactory;
+import org.apache.beam.runners.dataflow.worker.ReaderRegistry;
+import org.apache.beam.runners.dataflow.worker.SinkFactory;
+import org.apache.beam.runners.dataflow.worker.SinkRegistry;
+import 
org.apache.beam.runners.dataflow.worker.apiary.FixMultiOutputInfosOnParDoInstructions;
+import org.apache.beam.runners.dataflow.worker.counters.CounterSet;
+import org.apache.beam.runners.dataflow.worker.counters.NameContext;
+import org.apache.beam.runners.dataflow.worker.graph.Edges.Edge;
+import org.apache.beam.runners.dataflow.worker.graph.MapTaskToNetworkFunction;
+import org.apache.beam.runners.dataflow.worker.graph.Nodes.Node;
+import org.apache.beam.runners.dataflow.worker.util.common.worker.NativeReader;
+import org.apache.beam.runners.dataflow.worker.util.common.worker.Operation;
+import 
org.apache.beam.runners.dataflow.worker.util.common.worker.OutputObjectAndByteCounter;
+import 
org.apache.beam.runners.dataflow.worker.util.common.worker.ParDoOperation;
+import 
org.apache.beam.runners.dataflow.worker.util.common.worker.ReadOperation;
+import org.apache.beam.runners.dataflow.worker.util.common.worker.Sink;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.StringUtf8Coder;
+import org.apache.beam.sdk.extensions.gcp.util.Transport;
+import org.apache.beam.sdk.fn.IdGenerator;
+import org.apache.beam.sdk.fn.IdGenerators;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.DoFnSchemaInformation;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.IntervalWindow;
+import org.apache.beam.sdk.transforms.windowing.PaneInfo;
+import org.apache.beam.sdk.util.DoFnInfo;
+import org.apache.beam.sdk.util.SerializableUtils;
+import org.apache.beam.sdk.util.StringUtils;
+import org.apache.beam.sdk.util.WindowedValueMultiReceiver;
+import org.apache.beam.sdk.values.TupleTag;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.apache.beam.sdk.values.WindowingStrategy;
+import 
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.graph.MutableNetwork;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+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 org.apache.beam.runners.core.SimpleDoFnRunner} 
and fused Dataflow Java
+ * Runner {@link ParDoOperation} chains built via {@link 
IntrinsicMapTaskExecutorFactory}.
+ */
+@BenchmarkMode(Mode.Throughput)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+public class ParDoDispatchBenchmark {
+
+  private static final TupleTag<String> MAIN_TAG = new TupleTag<>("main");
+  private static final TupleTag<String> SIDE_TAG = new TupleTag<>("side");
+
+  private static final class PassThroughDoFn extends DoFn<String, String> {
+    @ProcessElement
+    public void processElement(@Element String elem, 
DoFn.OutputReceiver<String> out) {
+      out.output(elem);
+    }
+  }
+
+  private static final class MultiOutDoFn extends DoFn<String, String> {
+    @ProcessElement
+    public void processElement(@Element String elem, MultiOutputReceiver out) {
+      out.get(MAIN_TAG).output(elem);
+      out.get(SIDE_TAG).output(elem);
+    }
+  }
+
+  private static final class WindowObservingDoFn extends DoFn<String, String> {
+    @ProcessElement
+    public void processElement(
+        @Element String elem, BoundedWindow window, 
DoFn.OutputReceiver<String> out) {
+      if (window != null) {
+        out.output(elem);
+      }
+    }
+  }
+
+  private static final class SkewTimestampDoFn extends DoFn<String, String> {
+    private static final Duration SKEW = Duration.standardHours(1);
+
+    @Override
+    public Duration getAllowedTimestampSkew() {
+      return SKEW;
+    }
+
+    @ProcessElement
+    public void processElement(
+        @Element String elem, @Timestamp Instant ts, 
DoFn.OutputReceiver<String> out) {
+      out.outputWithTimestamp(elem, ts);
+    }
+  }
+
+  /** Minimal {@link ReaderFactory} used to root a fused {@link MapTask} 
instruction graph. */
+  private static final class EmptyReaderFactory implements ReaderFactory {
+    @Override
+    @SuppressWarnings("rawtypes")
+    public NativeReader<?> create(
+        CloudObject spec,
+        @Nullable Coder<?> coder,
+        @Nullable PipelineOptions options,
+        @Nullable DataflowExecutionContext executionContext,
+        DataflowOperationContext operationContext) {
+      return new NativeReader<WindowedValue<String>>() {
+        @Override
+        public boolean supportsRestart() {
+          return true;
+        }
+
+        @Override
+        public NativeReaderIterator<WindowedValue<String>> iterator() {
+          return new NativeReaderIterator<WindowedValue<String>>() {
+            @Override
+            public boolean start() {
+              return false;
+            }
+
+            @Override
+            public boolean advance() {
+              return false;
+            }
+
+            @Override
+            public WindowedValue<String> getCurrent() {
+              throw new NoSuchElementException();
+            }
+
+            @Override
+            public void close() {}
+          };
+        }
+      };
+    }
+  }
+
+  /** Minimal {@link SinkFactory} that counts emitted elements at the tail of 
a fused chain. */
+  private static final class CountingSinkFactory implements SinkFactory {
+    private final long[] outputCounter;
+
+    CountingSinkFactory(long[] outputCounter) {
+      this.outputCounter = outputCounter;

Review Comment:
   assert there is a single element of array (since used blindly below)



-- 
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]

Reply via email to