kamilwu commented on a change in pull request #11274: URL: https://github.com/apache/beam/pull/11274#discussion_r412231112
########## File path: sdks/python/apache_beam/io/gcp/pubsub_read_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 Read 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> + }'" +""" + +# 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 ReadFromPubSub, WriteToPubSub, PubsubMessage +from apache_beam.io.gcp.tests.pubsub_matcher import PubSubMessageMatcher +from apache_beam.options.pipeline_options import PipelineOptions +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 +from apache_beam.testing.test_pipeline import TestPipeline + +PUBSUB_NAME = 'pubsub_read_performance' + + +class PubsubReadPerfTest(LoadTest): + + def __init__(self): + super(PubsubReadPerfTest, self).__init__() + self._setup_env() + self._setup_pubsub() + self._setup_pipeline() + + def test(self): + ( + self.pipeline + | 'Read from pubsub' >> ReadFromPubSub( + subscription=self.subscription.name, + with_attributes=True, + id_label='ack_id') + | 'Measure time' >> beam.ParDo(MeasureTime(self.metrics_namespace)) + ) + + def cleanup(self): + test_utils.cleanup_subscriptions( + self.sub_client, [self.subscription, self.matcher_subscription]) + test_utils.cleanup_topics( + self.pub_client, [self.topic]) + + def _setup_env(self): + if not self.pipeline.get_option('timeout'): + logging.error('--timeout argument is required.') + sys.exit(1) + + self.num_of_messages = int(self.input_options.get('num_records')) + self.timeout = int(self.pipeline.get_option('timeout')) + + def _setup_pubsub(self): + def init_input(number_of_messages): Review comment: What about changing the name of this function so it would be more descriptive? What do you think about `_inject_input_data`? ---------------------------------------------------------------- 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]
