From d5d9bc0a0d5098d9b6fdff8357baf5fc369f7676 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Wed, 23 Oct 2019 12:45:13 -0700 Subject: [PATCH] Whitespace-sensitive languages are the worst --- .../tests/stress/unary_stream_benchmark.py | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/python/grpcio_tests/tests/stress/unary_stream_benchmark.py b/src/python/grpcio_tests/tests/stress/unary_stream_benchmark.py index ca439af102b..98fe75fe756 100644 --- a/src/python/grpcio_tests/tests/stress/unary_stream_benchmark.py +++ b/src/python/grpcio_tests/tests/stress/unary_stream_benchmark.py @@ -21,36 +21,37 @@ import sys import time import contextlib -try: - from src.python.grpcio_tests.tests.stress import unary_stream_benchmark_pb2 - from src.python.grpcio_tests.tests.stress import unary_stream_benchmark_pb2_grpc +_PORT = 5741 +_MESSAGE_SIZE = 4 +_RESPONSE_COUNT = 32 * 1024 + +_SERVER_CODE = """ +import datetime +import threading +import grpc +from concurrent import futures +from src.python.grpcio_tests.tests.stress import unary_stream_benchmark_pb2 +from src.python.grpcio_tests.tests.stress import unary_stream_benchmark_pb2_grpc - _PORT = 5741 - _MESSAGE_SIZE = 4 - _RESPONSE_COUNT = 32 * 1024 +class Handler(unary_stream_benchmark_pb2_grpc.UnaryStreamBenchmarkServiceServicer): - _SERVER_CODE = """ - import datetime - import threading - import grpc - from concurrent import futures - from src.python.grpcio_tests.tests.stress import unary_stream_benchmark_pb2 - from src.python.grpcio_tests.tests.stress import unary_stream_benchmark_pb2_grpc + def Benchmark(self, request, context): + payload = b'\\x00\\x01' * int(request.message_size / 2) + for _ in range(request.response_count): + yield unary_stream_benchmark_pb2.BenchmarkResponse(response=payload) - class Handler(unary_stream_benchmark_pb2_grpc.UnaryStreamBenchmarkServiceServicer): - def Benchmark(self, request, context): - payload = b'\\x00\\x01' * int(request.message_size / 2) - for _ in range(request.response_count): - yield unary_stream_benchmark_pb2.BenchmarkResponse(response=payload) +server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) +server.add_insecure_port('[::]:%d') +unary_stream_benchmark_pb2_grpc.add_UnaryStreamBenchmarkServiceServicer_to_server(Handler(), server) +server.start() +server.wait_for_termination() +""" % _PORT +try: + from src.python.grpcio_tests.tests.stress import unary_stream_benchmark_pb2 + from src.python.grpcio_tests.tests.stress import unary_stream_benchmark_pb2_grpc - server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) - server.add_insecure_port('[::]:%d') - unary_stream_benchmark_pb2_grpc.add_UnaryStreamBenchmarkServiceServicer_to_server(Handler(), server) - server.start() - server.wait_for_termination() - """ % _PORT _GRPC_CHANNEL_OPTIONS = [ ('grpc.max_metadata_size', 16 * 1024 * 1024),