[GitHub] [beam] kennknowles commented on a change in pull request #10949: [BEAM-9371] Add SideInputLoadTest to Java SDK

2020-03-02 Thread GitBox
kennknowles commented on a change in pull request #10949: [BEAM-9371] Add 
SideInputLoadTest to Java SDK
URL: https://github.com/apache/beam/pull/10949#discussion_r386745270
 
 

 ##
 File path: 
sdks/java/testing/load-tests/src/main/java/org/apache/beam/sdk/loadtests/SideInputLoadTest.java
 ##
 @@ -0,0 +1,243 @@
+/*
+ * 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.sdk.loadtests;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Random;
+import org.apache.beam.sdk.io.synthetic.SyntheticStep;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.testutils.metrics.ByteMonitor;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.View;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+
+/**
+ * Load test for operations involving side inputs.
+ *
+ * The purpose of this test is to measure cost of materialization or lookup 
of side inputs. It
+ * uses synthetic sources and {@link SyntheticStep} which can be parametrized 
to generate records
+ * with various sizes of keys and values, impose delays in the pipeline and 
simulate other
+ * performance challenges.
+ *
+ * To run the test manually, use the following command:
+ *
+ * 
+ *   ./gradlew :sdks:java:testing:load-tests:run -PloadTest.args='
+ *--sourceOptions={"numRecords":2000, ...}
+ *--sideInputType=ITERABLE
+ *--accessPercentage=1
+ *--windowCount=200
+ * 
+ */
+public class SideInputLoadTest extends LoadTest {
+
+  private static final String METRICS_NAMESPACE = "sideinput";
+  private static final Instant TIME = new Instant();
+
+  public SideInputLoadTest(String[] args) throws IOException {
+super(args, Options.class, METRICS_NAMESPACE);
+  }
+
+  @Override
+  void loadTest() throws IOException {
+Optional syntheticStep = 
createStep(options.getStepOptions());
+PCollection> input =
+pipeline
+.apply(readFromSource(sourceOptions))
+.apply(ParDo.of(new AddTimestamps()))
+.apply("Collect start time metrics", ParDo.of(runtimeMonitor))
+.apply(ParDo.of(new ByteMonitor(METRICS_NAMESPACE, 
"totalBytes.count")));
+
+performTestWithSideInput(
+input, 
SideInputMaterializationType.valueOf(options.getSideInputType()), 
syntheticStep);
+  }
+
+  private void performTestWithSideInput(
+  PCollection> input,
+  SideInputMaterializationType sideInputType,
+  Optional syntheticStep) {
+switch (sideInputType) {
+  case ITERABLE:
+performTestWithIterable(input, syntheticStep);
+break;
+  case HASHMAP:
+performTestWithHashMap(input, syntheticStep);
+break;
+  case LIST:
+performTestWithList(input, syntheticStep);
+break;
+}
+  }
+
+  private void performTestWithList(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView>> sideInput = 
input.apply(View.asList());
+input
+.apply(ParDo.of(new 
SideInputTestWithList(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithHashMap(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView> sideInput = input.apply(View.asMap());
+input
+.apply(ParDo.of(new 
SideInputTestWithHashMap(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithIterable(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, 

[GitHub] [beam] kennknowles commented on a change in pull request #10949: [BEAM-9371] Add SideInputLoadTest to Java SDK

2020-03-02 Thread GitBox
kennknowles commented on a change in pull request #10949: [BEAM-9371] Add 
SideInputLoadTest to Java SDK
URL: https://github.com/apache/beam/pull/10949#discussion_r386744848
 
 

 ##
 File path: 
sdks/java/testing/load-tests/src/main/java/org/apache/beam/sdk/loadtests/SideInputLoadTest.java
 ##
 @@ -0,0 +1,243 @@
+/*
+ * 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.sdk.loadtests;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Random;
+import org.apache.beam.sdk.io.synthetic.SyntheticStep;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.testutils.metrics.ByteMonitor;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.View;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+
+/**
+ * Load test for operations involving side inputs.
+ *
+ * The purpose of this test is to measure cost of materialization or lookup 
of side inputs. It
+ * uses synthetic sources and {@link SyntheticStep} which can be parametrized 
to generate records
+ * with various sizes of keys and values, impose delays in the pipeline and 
simulate other
+ * performance challenges.
+ *
+ * To run the test manually, use the following command:
+ *
+ * 
+ *   ./gradlew :sdks:java:testing:load-tests:run -PloadTest.args='
+ *--sourceOptions={"numRecords":2000, ...}
+ *--sideInputType=ITERABLE
+ *--accessPercentage=1
+ *--windowCount=200
+ * 
+ */
+public class SideInputLoadTest extends LoadTest {
+
+  private static final String METRICS_NAMESPACE = "sideinput";
+  private static final Instant TIME = new Instant();
+
+  public SideInputLoadTest(String[] args) throws IOException {
+super(args, Options.class, METRICS_NAMESPACE);
+  }
+
+  @Override
+  void loadTest() throws IOException {
+Optional syntheticStep = 
createStep(options.getStepOptions());
+PCollection> input =
+pipeline
+.apply(readFromSource(sourceOptions))
+.apply(ParDo.of(new AddTimestamps()))
+.apply("Collect start time metrics", ParDo.of(runtimeMonitor))
+.apply(ParDo.of(new ByteMonitor(METRICS_NAMESPACE, 
"totalBytes.count")));
+
+performTestWithSideInput(
+input, 
SideInputMaterializationType.valueOf(options.getSideInputType()), 
syntheticStep);
+  }
+
+  private void performTestWithSideInput(
+  PCollection> input,
+  SideInputMaterializationType sideInputType,
+  Optional syntheticStep) {
+switch (sideInputType) {
+  case ITERABLE:
+performTestWithIterable(input, syntheticStep);
+break;
+  case HASHMAP:
+performTestWithHashMap(input, syntheticStep);
+break;
+  case LIST:
+performTestWithList(input, syntheticStep);
+break;
+}
+  }
+
+  private void performTestWithList(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView>> sideInput = 
input.apply(View.asList());
+input
+.apply(ParDo.of(new 
SideInputTestWithList(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithHashMap(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView> sideInput = input.apply(View.asMap());
+input
+.apply(ParDo.of(new 
SideInputTestWithHashMap(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithIterable(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, 

[GitHub] [beam] kennknowles commented on a change in pull request #10949: [BEAM-9371] Add SideInputLoadTest to Java SDK

2020-03-02 Thread GitBox
kennknowles commented on a change in pull request #10949: [BEAM-9371] Add 
SideInputLoadTest to Java SDK
URL: https://github.com/apache/beam/pull/10949#discussion_r386743300
 
 

 ##
 File path: 
sdks/java/testing/load-tests/src/main/java/org/apache/beam/sdk/loadtests/SideInputLoadTest.java
 ##
 @@ -0,0 +1,243 @@
+/*
+ * 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.sdk.loadtests;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Random;
+import org.apache.beam.sdk.io.synthetic.SyntheticStep;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.testutils.metrics.ByteMonitor;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.View;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+
+/**
+ * Load test for operations involving side inputs.
+ *
+ * The purpose of this test is to measure cost of materialization or lookup 
of side inputs. It
+ * uses synthetic sources and {@link SyntheticStep} which can be parametrized 
to generate records
+ * with various sizes of keys and values, impose delays in the pipeline and 
simulate other
+ * performance challenges.
+ *
+ * To run the test manually, use the following command:
+ *
+ * 
+ *   ./gradlew :sdks:java:testing:load-tests:run -PloadTest.args='
+ *--sourceOptions={"numRecords":2000, ...}
+ *--sideInputType=ITERABLE
+ *--accessPercentage=1
+ *--windowCount=200
+ * 
+ */
+public class SideInputLoadTest extends LoadTest {
+
+  private static final String METRICS_NAMESPACE = "sideinput";
+  private static final Instant TIME = new Instant();
+
+  public SideInputLoadTest(String[] args) throws IOException {
+super(args, Options.class, METRICS_NAMESPACE);
+  }
+
+  @Override
+  void loadTest() throws IOException {
+Optional syntheticStep = 
createStep(options.getStepOptions());
+PCollection> input =
+pipeline
+.apply(readFromSource(sourceOptions))
+.apply(ParDo.of(new AddTimestamps()))
+.apply("Collect start time metrics", ParDo.of(runtimeMonitor))
+.apply(ParDo.of(new ByteMonitor(METRICS_NAMESPACE, 
"totalBytes.count")));
+
+performTestWithSideInput(
+input, 
SideInputMaterializationType.valueOf(options.getSideInputType()), 
syntheticStep);
+  }
+
+  private void performTestWithSideInput(
+  PCollection> input,
+  SideInputMaterializationType sideInputType,
+  Optional syntheticStep) {
+switch (sideInputType) {
+  case ITERABLE:
+performTestWithIterable(input, syntheticStep);
+break;
+  case HASHMAP:
+performTestWithHashMap(input, syntheticStep);
+break;
+  case LIST:
+performTestWithList(input, syntheticStep);
+break;
+}
+  }
+
+  private void performTestWithList(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView>> sideInput = 
input.apply(View.asList());
+input
+.apply(ParDo.of(new 
SideInputTestWithList(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithHashMap(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView> sideInput = input.apply(View.asMap());
+input
+.apply(ParDo.of(new 
SideInputTestWithHashMap(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithIterable(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, 

[GitHub] [beam] kennknowles commented on a change in pull request #10949: [BEAM-9371] Add SideInputLoadTest to Java SDK

2020-03-02 Thread GitBox
kennknowles commented on a change in pull request #10949: [BEAM-9371] Add 
SideInputLoadTest to Java SDK
URL: https://github.com/apache/beam/pull/10949#discussion_r386745742
 
 

 ##
 File path: 
sdks/java/testing/load-tests/src/main/java/org/apache/beam/sdk/loadtests/SideInputLoadTest.java
 ##
 @@ -0,0 +1,243 @@
+/*
+ * 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.sdk.loadtests;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Random;
+import org.apache.beam.sdk.io.synthetic.SyntheticStep;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.testutils.metrics.ByteMonitor;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.View;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+
+/**
+ * Load test for operations involving side inputs.
+ *
+ * The purpose of this test is to measure cost of materialization or lookup 
of side inputs. It
+ * uses synthetic sources and {@link SyntheticStep} which can be parametrized 
to generate records
+ * with various sizes of keys and values, impose delays in the pipeline and 
simulate other
+ * performance challenges.
+ *
+ * To run the test manually, use the following command:
+ *
+ * 
+ *   ./gradlew :sdks:java:testing:load-tests:run -PloadTest.args='
+ *--sourceOptions={"numRecords":2000, ...}
+ *--sideInputType=ITERABLE
+ *--accessPercentage=1
+ *--windowCount=200
+ * 
+ */
+public class SideInputLoadTest extends LoadTest {
+
+  private static final String METRICS_NAMESPACE = "sideinput";
+  private static final Instant TIME = new Instant();
+
+  public SideInputLoadTest(String[] args) throws IOException {
+super(args, Options.class, METRICS_NAMESPACE);
+  }
+
+  @Override
+  void loadTest() throws IOException {
+Optional syntheticStep = 
createStep(options.getStepOptions());
+PCollection> input =
+pipeline
+.apply(readFromSource(sourceOptions))
+.apply(ParDo.of(new AddTimestamps()))
+.apply("Collect start time metrics", ParDo.of(runtimeMonitor))
+.apply(ParDo.of(new ByteMonitor(METRICS_NAMESPACE, 
"totalBytes.count")));
+
+performTestWithSideInput(
+input, 
SideInputMaterializationType.valueOf(options.getSideInputType()), 
syntheticStep);
+  }
+
+  private void performTestWithSideInput(
+  PCollection> input,
+  SideInputMaterializationType sideInputType,
+  Optional syntheticStep) {
+switch (sideInputType) {
+  case ITERABLE:
+performTestWithIterable(input, syntheticStep);
+break;
+  case HASHMAP:
+performTestWithHashMap(input, syntheticStep);
+break;
+  case LIST:
+performTestWithList(input, syntheticStep);
+break;
+}
+  }
+
+  private void performTestWithList(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView>> sideInput = 
input.apply(View.asList());
+input
+.apply(ParDo.of(new 
SideInputTestWithList(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithHashMap(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView> sideInput = input.apply(View.asMap());
+input
+.apply(ParDo.of(new 
SideInputTestWithHashMap(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithIterable(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, 

[GitHub] [beam] kennknowles commented on a change in pull request #10949: [BEAM-9371] Add SideInputLoadTest to Java SDK

2020-03-02 Thread GitBox
kennknowles commented on a change in pull request #10949: [BEAM-9371] Add 
SideInputLoadTest to Java SDK
URL: https://github.com/apache/beam/pull/10949#discussion_r386740644
 
 

 ##
 File path: 
sdks/java/testing/load-tests/src/main/java/org/apache/beam/sdk/loadtests/SideInputLoadTest.java
 ##
 @@ -0,0 +1,243 @@
+/*
+ * 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.sdk.loadtests;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Random;
+import org.apache.beam.sdk.io.synthetic.SyntheticStep;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.testutils.metrics.ByteMonitor;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.View;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+
+/**
+ * Load test for operations involving side inputs.
+ *
+ * The purpose of this test is to measure cost of materialization or lookup 
of side inputs. It
+ * uses synthetic sources and {@link SyntheticStep} which can be parametrized 
to generate records
+ * with various sizes of keys and values, impose delays in the pipeline and 
simulate other
+ * performance challenges.
+ *
+ * To run the test manually, use the following command:
+ *
+ * 
+ *   ./gradlew :sdks:java:testing:load-tests:run -PloadTest.args='
+ *--sourceOptions={"numRecords":2000, ...}
+ *--sideInputType=ITERABLE
+ *--accessPercentage=1
+ *--windowCount=200
+ * 
+ */
+public class SideInputLoadTest extends LoadTest {
+
+  private static final String METRICS_NAMESPACE = "sideinput";
 
 Review comment:
   What are the metrics? Should they be described in the Javadoc? I read the 
superclass and did not see much explanation there either.
   
   The code here makes OK sense but is not enough information to use it. So I 
am just wondering what the experience is for someone who wants to use the class 
to build a new load test.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [beam] kennknowles commented on a change in pull request #10949: [BEAM-9371] Add SideInputLoadTest to Java SDK

2020-03-02 Thread GitBox
kennknowles commented on a change in pull request #10949: [BEAM-9371] Add 
SideInputLoadTest to Java SDK
URL: https://github.com/apache/beam/pull/10949#discussion_r386743669
 
 

 ##
 File path: 
sdks/java/testing/load-tests/src/main/java/org/apache/beam/sdk/loadtests/SideInputLoadTest.java
 ##
 @@ -0,0 +1,243 @@
+/*
+ * 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.sdk.loadtests;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Random;
+import org.apache.beam.sdk.io.synthetic.SyntheticStep;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.testutils.metrics.ByteMonitor;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.View;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionView;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+
+/**
+ * Load test for operations involving side inputs.
+ *
+ * The purpose of this test is to measure cost of materialization or lookup 
of side inputs. It
+ * uses synthetic sources and {@link SyntheticStep} which can be parametrized 
to generate records
+ * with various sizes of keys and values, impose delays in the pipeline and 
simulate other
+ * performance challenges.
+ *
+ * To run the test manually, use the following command:
+ *
+ * 
+ *   ./gradlew :sdks:java:testing:load-tests:run -PloadTest.args='
+ *--sourceOptions={"numRecords":2000, ...}
+ *--sideInputType=ITERABLE
+ *--accessPercentage=1
+ *--windowCount=200
+ * 
+ */
+public class SideInputLoadTest extends LoadTest {
+
+  private static final String METRICS_NAMESPACE = "sideinput";
+  private static final Instant TIME = new Instant();
+
+  public SideInputLoadTest(String[] args) throws IOException {
+super(args, Options.class, METRICS_NAMESPACE);
+  }
+
+  @Override
+  void loadTest() throws IOException {
+Optional syntheticStep = 
createStep(options.getStepOptions());
+PCollection> input =
+pipeline
+.apply(readFromSource(sourceOptions))
+.apply(ParDo.of(new AddTimestamps()))
+.apply("Collect start time metrics", ParDo.of(runtimeMonitor))
+.apply(ParDo.of(new ByteMonitor(METRICS_NAMESPACE, 
"totalBytes.count")));
+
+performTestWithSideInput(
+input, 
SideInputMaterializationType.valueOf(options.getSideInputType()), 
syntheticStep);
+  }
+
+  private void performTestWithSideInput(
+  PCollection> input,
+  SideInputMaterializationType sideInputType,
+  Optional syntheticStep) {
+switch (sideInputType) {
+  case ITERABLE:
+performTestWithIterable(input, syntheticStep);
+break;
+  case HASHMAP:
+performTestWithHashMap(input, syntheticStep);
+break;
+  case LIST:
+performTestWithList(input, syntheticStep);
+break;
+}
+  }
+
+  private void performTestWithList(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView>> sideInput = 
input.apply(View.asList());
+input
+.apply(ParDo.of(new 
SideInputTestWithList(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithHashMap(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input, "Synthetic step", syntheticStep);
+PCollectionView> sideInput = input.apply(View.asMap());
+input
+.apply(ParDo.of(new 
SideInputTestWithHashMap(sideInput)).withSideInputs(sideInput))
+.apply("Collect end time metrics", ParDo.of(runtimeMonitor));
+  }
+
+  private void performTestWithIterable(
+  PCollection> input, Optional 
syntheticStep) {
+applyStepIfPresent(input,