qps_worker.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. import argparse
  16. import logging
  17. import time
  18. import grpc
  19. from src.proto.grpc.testing import worker_service_pb2_grpc
  20. from tests.qps import worker_server
  21. from tests.unit import test_common
  22. def run_worker_server(driver_port, server_port):
  23. server = test_common.test_server()
  24. servicer = worker_server.WorkerServer(server_port)
  25. worker_service_pb2_grpc.add_WorkerServiceServicer_to_server(
  26. servicer, server)
  27. server.add_insecure_port('[::]:{}'.format(driver_port))
  28. server.start()
  29. servicer.wait_for_quit()
  30. server.stop(0)
  31. if __name__ == '__main__':
  32. logging.basicConfig(level=logging.DEBUG)
  33. parser = argparse.ArgumentParser(
  34. description='gRPC Python performance testing worker')
  35. parser.add_argument(
  36. '--driver_port',
  37. type=int,
  38. dest='driver_port',
  39. help='The port for the worker to expose for driver communication')
  40. parser.add_argument(
  41. '--server_port',
  42. type=int,
  43. default=None,
  44. dest='server_port',
  45. help='The port for the server if not specified by server config message'
  46. )
  47. args = parser.parse_args()
  48. run_worker_server(args.driver_port, args.server_port)