[ 
https://issues.apache.org/jira/browse/BEAM-5993?focusedWorklogId=172475&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-172475
 ]

ASF GitHub Bot logged work on BEAM-5993:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Dec/18 20:59
            Start Date: 05/Dec/18 20:59
    Worklog Time Spent: 10m 
      Work Description: pabloem commented on a change in pull request #7020: 
BEAM-5993 Create SideInput Load test
URL: https://github.com/apache/beam/pull/7020#discussion_r239234878
 
 

 ##########
 File path: sdks/python/apache_beam/testing/load_tests/sideinput_test.py
 ##########
 @@ -0,0 +1,158 @@
+#
+# 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.
+#
+"""
+To run test on DirectRunner
+
+python setup.py nosetests \
+    --test-pipeline-options="
+    --number_of_counter_operations=1000
+    --input_options='{
+    \"num_records\": 300,
+    \"key_size\": 5,
+    \"value_size\":15,
+    \"bundle_size_distribution_type\": \"const\",
+    \"bundle_size_distribution_param\": 1,
+    \"force_initial_num_bundles\": 0
+    }'
+   " \
+    --tests apache_beam.testing.load_tests.sideinput_test
+
+To run test on other runner (ex. Dataflow):
+
+python setup.py nosetests \
+    --test-pipeline-options="
+        --runner=TestDataflowRunner
+        --project=...
+        --staging_location=gs://...
+        --temp_location=gs://...
+        --sdk_location=./dist/apache-beam-x.x.x.dev0.tar.gz
+        --number_of_counter_operations=1000
+        --input_options='{
+        \"num_records\": 1,
+        \"key_size\": 1,
+        \"value_size\":1,
+        \"bundle_size_distribution_type\": \"const\",
+        \"bundle_size_distribution_param\": 1,
+        \"force_initial_num_bundles\": 0
+        }'
+        " \
+    --tests apache_beam.testing.load_tests.sideinput_test
+
+"""
+
+from __future__ import absolute_import
+
+import json
+import logging
+import unittest
+
+import apache_beam as beam
+from apache_beam.pvalue import AsIter
+from apache_beam.testing import synthetic_pipeline
+from apache_beam.testing.load_tests.load_test_metrics_utils import MeasureTime
+from apache_beam.testing.test_pipeline import TestPipeline
+
+
+class SideInputTest(unittest.TestCase):
+  def _parseTestPipelineOptions(self):
+    return {
+        'numRecords': self.inputOptions.get('num_records'),
+        'keySizeBytes': self.inputOptions.get('key_size'),
+        'valueSizeBytes': self.inputOptions.get('value_size'),
+        'bundleSizeDistribution': {
+            'type': self.inputOptions.get(
+                'bundle_size_distribution_type', 'const'
+            ),
+            'param': self.inputOptions.get('bundle_size_distribution_param', 0)
+        },
+        'forceNumInitialBundles': self.inputOptions.get(
+            'force_initial_num_bundles', 0
+        )
+    }
+
+  def _getSideInput(self):
+    side_input = self._parseTestPipelineOptions()
+    side_input['numRecords'] = side_input['numRecords']
+    side_input['keySizeBytes'] = side_input['keySizeBytes']
+    side_input['valueSizeBytes'] = side_input['valueSizeBytes']
+    return side_input
+
+  def _getPerElementDelaySec(self):
+    return self.syntheticStepOptions.get('per_element_delay_sec', 0)
+
+  def _getPerBundleDelaySec(self):
+    return self.syntheticStepOptions.get('per_bundle_delay_sec', 0)
+
+  def _getOutputRecordsPerInputRecords(self):
+    return self.syntheticStepOptions.get('output_records_per_input_records', 0)
+
+  def setUp(self):
+    self.pipeline = TestPipeline()
+    self.inputOptions = json.loads(self.pipeline.get_option('input_options'))
+    self.iterations = self.pipeline.get_option('number_of_counter_operations')
+    if self.iterations is None:
+      self.iterations = 1
+
+  class Consume(beam.DoFn):
+    def process(self, element, *args, **kwargs):
+      values_list = []
+      for i in element:
+        for _, value in i.iteritems():
+          values_list.append(value)
+      yield values_list
+
+  def testSideInput(self):
+    def join_fn(element, side_input, iterations):
+      list = []
+      for i in range(iterations):
+        for key, value in side_input:
+          if i == iterations - 1:
+            list.append({key: element[1]+value})
+      yield list
+
+    with self.pipeline as p:
+      main_input = (p
+                    | "Read pcoll 1" >> beam.io.Read(
+                        synthetic_pipeline.SyntheticSource(
+                            self._parseTestPipelineOptions()))
+                   )
+
+      side_input = (p
+                    | "Read pcoll 2" >> beam.io.Read(
+                        synthetic_pipeline.SyntheticSource(
+                            self._getSideInput()))
+                   )
+      # pylint: disable=expression-not-assigned
+      (main_input
+       | "Merge" >> beam.ParDo(
 
 Review comment:
   By iterating through the side input in `"Merge"`, you will consume it, and 
no longer need to iterate through it in `"Consume"` - so it may be fine if you 
just drop the `Consume` transform. Other than that, I think this must be fine : 
)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 172475)
    Time Spent: 40m  (was: 0.5h)

> Create SideInput Load test
> --------------------------
>
>                 Key: BEAM-5993
>                 URL: https://issues.apache.org/jira/browse/BEAM-5993
>             Project: Beam
>          Issue Type: Sub-task
>          Components: testing
>            Reporter: Kasia Kucharczyk
>            Assignee: Kasia Kucharczyk
>            Priority: Major
>          Time Spent: 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to