1# Copyright 2016 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""The entry point for the qps worker.""" 15 16import argparse 17import logging 18import time 19 20import grpc 21 22from src.proto.grpc.testing import worker_service_pb2_grpc 23from tests.qps import worker_server 24from tests.unit import test_common 25 26 27def run_worker_server(driver_port, server_port): 28 server = test_common.test_server() 29 servicer = worker_server.WorkerServer(server_port) 30 worker_service_pb2_grpc.add_WorkerServiceServicer_to_server( 31 servicer, server 32 ) 33 server.add_insecure_port("[::]:{}".format(driver_port)) 34 server.start() 35 servicer.wait_for_quit() 36 server.stop(0) 37 38 39if __name__ == "__main__": 40 logging.basicConfig(level=logging.DEBUG) 41 parser = argparse.ArgumentParser( 42 description="gRPC Python performance testing worker" 43 ) 44 parser.add_argument( 45 "--driver_port", 46 type=int, 47 dest="driver_port", 48 help="The port for the worker to expose for driver communication", 49 ) 50 parser.add_argument( 51 "--server_port", 52 type=int, 53 default=None, 54 dest="server_port", 55 help=( 56 "The port for the server if not specified by server config message" 57 ), 58 ) 59 args = parser.parse_args() 60 61 run_worker_server(args.driver_port, args.server_port) 62