Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serve] Config Serve's gRPC proxy to allow large payload #43114

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/ray/serve/_private/grpc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import grpc
from grpc.aio._server import Server

from ray.util.client.common import GRPC_OPTIONS


class gRPCServer(Server):
"""Custom gRPC server to override gRPC method methods.
Expand Down Expand Up @@ -61,7 +63,7 @@ def create_serve_grpc_server(service_handler_factory):
thread_pool=None,
generic_handlers=(),
interceptors=(),
options=(),
options=GRPC_OPTIONS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the options supported here? are we sure we want to share the configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a whole list of options that Ray currently supported

GRPC_OPTIONS = [
But good point let me make a Serve specific ones that's configurable as well. Will start with just the message size related ones.

maximum_concurrent_rpcs=None,
compression=None,
service_handler_factory=service_handler_factory,
Expand Down
37 changes: 37 additions & 0 deletions python/ray/serve/tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,5 +804,42 @@ def Streaming(
assert "extra_required_arg" in rpc_error.details()


def test_grpc_client_sending_large_payload(ray_instance, ray_shutdown):
"""Test gRPC client sending large payload.

Serve's gRPC proxy should be configured to allow the client to send large payloads
without error.
"""
grpc_port = 9000
grpc_servicer_functions = [
"ray.serve.generated.serve_pb2_grpc.add_UserDefinedServiceServicer_to_server",
]

serve.start(
grpc_options=gRPCOptions(
port=grpc_port,
grpc_servicer_functions=grpc_servicer_functions,
),
)
serve.run(target=g)

# This option allows the client to pass larger message.
options = [
("grpc.max_receive_message_length", 1024 * 1024 * 1024),
]
channel = grpc.insecure_channel("localhost:9000", options=options)
stub = serve_pb2_grpc.UserDefinedServiceStub(channel)

# This is a large payload that exists gRPC's default message limit.
large_payload = "foobar" * 1_000_000
request = serve_pb2.UserDefinedMessage(name=large_payload, num=30, foo="bar")
metadata = (("application", "default"),)
response = stub.__call__(request=request, metadata=metadata)
assert response == serve_pb2.UserDefinedResponse(
greeting=f"Hello {large_payload} from bar",
num_x2=60,
)


if __name__ == "__main__":
sys.exit(pytest.main(["-v", "-s", __file__]))
Loading