def _create_server(self, config):
        if config.server_type == control_pb2.SYNC_SERVER:
            servicer = benchmark_server.BenchmarkServer()
            server = services_pb2.beta_create_BenchmarkService_server(servicer)
        elif config.server_type == control_pb2.ASYNC_GENERIC_SERVER:
            resp_size = config.payload_config.bytebuf_params.resp_size
            servicer = benchmark_server.GenericBenchmarkServer(resp_size)
            method_implementations = {
                ('grpc.testing.BenchmarkService', 'StreamingCall'):
                utilities.stream_stream_inline(servicer.StreamingCall),
                ('grpc.testing.BenchmarkService', 'UnaryCall'):
                utilities.unary_unary_inline(servicer.UnaryCall),
            }
            server = implementations.server(method_implementations)
        else:
            raise Exception('Unsupported server type {}'.format(
                config.server_type))

        if config.HasField('security_params'):  # Use SSL
            server_creds = implementations.ssl_server_credentials([
                (resources.private_key(), resources.certificate_chain())
            ])
            port = server.add_secure_port('[::]:{}'.format(config.port),
                                          server_creds)
        else:
            port = server.add_insecure_port('[::]:{}'.format(config.port))

        return (server, port)
Example #2
0
    def _create_server(self, config):
        if config.async_server_threads == 0:
            # This is the default concurrent.futures thread pool size, but
            # None doesn't seem to work
            server_threads = multiprocessing.cpu_count() * 5
        else:
            server_threads = config.async_server_threads
        server = test_common.test_server(max_workers=server_threads)
        if config.server_type == control_pb2.ASYNC_SERVER:
            servicer = benchmark_server.BenchmarkServer()
            benchmark_service_pb2_grpc.add_BenchmarkServiceServicer_to_server(
                servicer, server)
        elif config.server_type == control_pb2.ASYNC_GENERIC_SERVER:
            resp_size = config.payload_config.bytebuf_params.resp_size
            servicer = benchmark_server.GenericBenchmarkServer(resp_size)
            method_implementations = {
                'StreamingCall':
                    grpc.stream_stream_rpc_method_handler(servicer.StreamingCall
                                                         ),
                'UnaryCall':
                    grpc.unary_unary_rpc_method_handler(servicer.UnaryCall),
            }
            handler = grpc.method_handlers_generic_handler(
                'grpc.testing.BenchmarkService', method_implementations)
            server.add_generic_rpc_handlers((handler,))
        else:
            raise Exception('Unsupported server type {}'.format(
                config.server_type))

        if self._server_port is not None and config.port == 0:
            server_port = self._server_port
        else:
            server_port = config.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(server_port),
                                          server_creds)
        else:
            port = server.add_insecure_port('[::]:{}'.format(server_port))

        return (server, port)