damccorm commented on code in PR #27610: URL: https://github.com/apache/beam/pull/27610#discussion_r1272304296
########## .test-infra/pubsub/README.md: ########## @@ -0,0 +1,36 @@ +<!-- + 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. +--> + +# Overview + +This folder contains Python scripts to create a Pub/Sub topic under +the GCP project `apache-beam-testing` and test the topic. Review Comment: How do you anticipate this being used? In benchmarks by us? In benchmarks by a user? In streaming test scenarios for us? I'm a little worried that this will get lost as it currently stands, so I'm trying to figure out the best way to make it more visible/targeted at its use cases. Maybe we can just rename the folder to benchmark_pubsub_source or something? ########## .test-infra/pubsub/gcs_image_looper.py: ########## @@ -0,0 +1,69 @@ +# +# 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. +# +"""This executable loops image filepaths from a gcs bucket file.""" +import random +import time + +from google.api_core.exceptions import AlreadyExists +from google.cloud import pubsub_v1 +from google.cloud import storage + +# use the eou project and gcs to run the word looper +project_id = "apache-beam-testing" +gcs_bucket = "apache-beam-ml" +num_images_per_second = 5 + +publisher = pubsub_v1.PublisherClient() +image_file_path = "testing/inputs/openimage_50k_benchmark.txt" +topic_name = "Imagenet_openimage_50k_benchmark" +topic_path = publisher.topic_path(project_id, topic_name) + + +class ImageLooper(object): + """Loop the images in a gcs bucket file and publish them to a pubsub topic. + """ + content = "" + cursor = 0 + + def __init__(self, filename): + self._read_gcs_file(filename) + + def get_next_image(self): + """Returns the next image randomly.""" + next_image = "" + while not next_image: + image_id = random.randint(0, len(self.content) - 1) + next_image = self.content[image_id].strip('\n') Review Comment: Do we actually need to strip the `\n`? Shouldn't this already be 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
