piotr-szuberski commented on a change in pull request #11274:
URL: https://github.com/apache/beam/pull/11274#discussion_r412089928



##########
File path: sdks/python/apache_beam/io/gcp/pubsub_write_perf_test.py
##########
@@ -0,0 +1,153 @@
+#
+# 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.
+#
+
+"""
+Performance PubsubIO streaming test for Write operation.
+
+Example for TestDataflowRunner:
+
+python -m apache_beam.io.gcp.pubsub_read_perf_test \
+    --test-pipeline-options="
+    --runner=TestDataflowRunner
+    --sdk_location=.../dist/apache-beam-x.x.x.dev0.tar.gz
+    --project=<GCP_PROJECT_ID>
+    --temp_location=gs://<BUCKET_NAME>/tmp
+    --staging_location=gs://<BUCKET_NAME>/staging
+    --timeout=<TIME_IN_SECONDS>
+    --publish_to_big_query=<OPTIONAL><true/false>
+    --metrics_dataset=<OPTIONAL>
+    --metrics_table=<OPTIONAL>
+    --dataflow_worker_jar=<OPTIONAL>
+    --input_options='{
+    \"num_records\": <SIZE_OF_INPUT>,
+    \"key_size\": 1,
+    \"value_size\": <VALUE_SIZE>,
+    }'"
+
+"""
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import argparse
+import logging
+import sys
+import uuid
+
+from hamcrest import all_of
+
+import apache_beam as beam
+from apache_beam.io import WriteToPubSub, PubsubMessage, Read
+from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher
+from apache_beam.options.pipeline_options import PipelineOptions
+from apache_beam.runners import PipelineState
+from apache_beam.testing import test_utils
+from apache_beam.testing.load_tests.load_test import LoadTest
+from apache_beam.testing.load_tests.load_test_metrics_utils import 
MeasureTime, CountMessages
+from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher
+from apache_beam.testing.synthetic_pipeline import SyntheticSource
+from apache_beam.testing.test_pipeline import TestPipeline
+
+PUBSUB_NAME = 'pubsub_write_performance'
+
+
+class PubsubWritePerfTest(LoadTest):
+
+  def __init__(self):
+    super(PubsubWritePerfTest, self).__init__()
+    self._setup_env()
+    self._setup_pubsub()
+    self._setup_pipeline()
+
+  def test(self):
+
+    class ToPubsubMessage(beam.DoFn):
+      counter = 0
+
+      def process(self, element):
+        self.counter += 1
+        from apache_beam.io import WriteToPubSub, PubsubMessage
+        message = PubsubMessage(
+          data=element[1],
+          attributes={'ack_id': bytes(str(self.counter), 'utf-8')})

Review comment:
       Done




----------------------------------------------------------------
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:
[email protected]


Reply via email to