Merge pull request #24350 from codeblooded/python/bug/add-server-port

Add --server_port flag to python benchmark worker
pull/24360/head
Benjamin Reed 4 years ago committed by GitHub
commit 9757a09ec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/python/grpcio_tests/tests/qps/qps_worker.py
  2. 8
      src/python/grpcio_tests/tests/qps/worker_server.py

@ -23,12 +23,12 @@ from tests.qps import worker_server
from tests.unit import test_common
def run_worker_server(port):
def run_worker_server(driver_port, server_port):
server = test_common.test_server()
servicer = worker_server.WorkerServer()
servicer = worker_server.WorkerServer(server_port)
worker_service_pb2_grpc.add_WorkerServiceServicer_to_server(
servicer, server)
server.add_insecure_port('[::]:{}'.format(port))
server.add_insecure_port('[::]:{}'.format(driver_port))
server.start()
servicer.wait_for_quit()
server.stop(0)
@ -39,8 +39,13 @@ if __name__ == '__main__':
description='gRPC Python performance testing worker')
parser.add_argument('--driver_port',
type=int,
dest='port',
dest='driver_port',
help='The port the worker should listen on')
parser.add_argument('--server_port',
type=int,
default=None,
dest='server_port',
help='The port the server should accept traffic on')
args = parser.parse_args()
run_worker_server(args.port)
run_worker_server(args.driver_port, args.server_port)

@ -35,8 +35,9 @@ from tests.unit import test_common
class WorkerServer(worker_service_pb2_grpc.WorkerServiceServicer):
"""Python Worker Server implementation."""
def __init__(self):
def __init__(self, server_port=None):
self._quit_event = threading.Event()
self._server_port = server_port
def RunServer(self, request_iterator, context):
config = next(request_iterator).setup #pylint: disable=stop-iteration-return
@ -91,13 +92,14 @@ class WorkerServer(worker_service_pb2_grpc.WorkerServiceServicer):
raise Exception('Unsupported server type {}'.format(
config.server_type))
server_port = config.port if self._server_port is None else self._server_port
if config.HasField('security_params'): # Use SSL
server_creds = grpc.ssl_server_credentials(
((resources.private_key(), resources.certificate_chain()),))
port = server.add_secure_port('[::]:{}'.format(config.port),
port = server.add_secure_port('[::]:{}'.format(server_port),
server_creds)
else:
port = server.add_insecure_port('[::]:{}'.format(config.port))
port = server.add_insecure_port('[::]:{}'.format(server_port))
return (server, port)

Loading…
Cancel
Save