Skip to content

Commit

Permalink
add async python bench
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Nov 22, 2021
1 parent b1f02be commit 3abeb65
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python_async_grpc_bench/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3-slim

WORKDIR /app
COPY python_async_grpc_bench /app
COPY proto /app/proto

RUN python -m pip install grpcio grpcio-tools asyncio
RUN python -m grpc_tools.protoc -I/app/proto/helloworld --python_out=. --grpc_python_out=. helloworld.proto

ENTRYPOINT [ "python", "/app/server.py" ]
44 changes: 44 additions & 0 deletions python_async_grpc_bench/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2020 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Python AsyncIO implementation of the GRPC helloworld.Greeter server."""

import asyncio
import logging

import grpc
import helloworld_pb2
import helloworld_pb2_grpc


class Greeter(helloworld_pb2_grpc.GreeterServicer):

async def SayHello(
self, request: helloworld_pb2.HelloRequest,
context: grpc.aio.ServicerContext) -> helloworld_pb2.HelloReply:
return helloworld_pb2.HelloReply(message=request.name)


async def serve() -> None:
server = grpc.aio.server()
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
listen_addr = '[::]:50051'
server.add_insecure_port(listen_addr)
logging.info("Starting server on %s", listen_addr)
await server.start()
await server.wait_for_termination()


if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
asyncio.run(serve())

0 comments on commit 3abeb65

Please sign in to comment.