diff --git a/python/lib/sift_client/_internal/grpc_transport/transport.py b/python/lib/sift_client/_internal/grpc_transport/transport.py index f982be61c4..11d67e9e95 100644 --- a/python/lib/sift_client/_internal/grpc_transport/transport.py +++ b/python/lib/sift_client/_internal/grpc_transport/transport.py @@ -168,7 +168,14 @@ def _compute_channel_options(opts: SiftChannelConfig) -> list[tuple[str, Any]]: # Primary cannot be overriden: # https://github.com/grpc/grpc/blob/0498194240f55d7f4b12633ad01339fb690621bf/src/core/ext/filters/http/client/http_client_filter.cc#L97 ("grpc.secondary_user_agent", _compute_user_agent()), - ("grpc.max_receive_message_length", MAX_DECODING_MESSAGE_SIZE), + ( + "grpc.max_receive_message_length", + opts.get("max_receive_message_length", MAX_DECODING_MESSAGE_SIZE), + ), + ( + "grpc.max_send_message_length", + opts.get("max_send_message_length", MAX_DECODING_MESSAGE_SIZE), + ), ] enable_keepalive = opts.get("enable_keepalive", True) @@ -251,3 +258,5 @@ class SiftChannelConfig(TypedDict): use_ssl: NotRequired[bool] cert_via_openssl: NotRequired[bool] request_timeout: NotRequired[float | None] + max_receive_message_length: NotRequired[int] + max_send_message_length: NotRequired[int] diff --git a/python/lib/sift_client/_internal/low_level_wrappers/data.py b/python/lib/sift_client/_internal/low_level_wrappers/data.py index 5a2dd522f6..6661a710cb 100644 --- a/python/lib/sift_client/_internal/low_level_wrappers/data.py +++ b/python/lib/sift_client/_internal/low_level_wrappers/data.py @@ -30,7 +30,7 @@ # Configure logging logger = logging.getLogger(__name__) -CHANNELS_DEFAULT_PAGE_SIZE = 10_000 +CHANNELS_DEFAULT_PAGE_SIZE = 100_000 # TODO: There is a pagination issue API side when requesting multiple channels in single request. # If all data points for all channels in a single request don't fit into a single page, then # paging seems to omit all but a single channel. We can increase this batch size once that issue diff --git a/python/lib/sift_client/_tests/_internal/test_transport.py b/python/lib/sift_client/_tests/_internal/test_transport.py index 9d05289c5b..0cac17a87c 100644 --- a/python/lib/sift_client/_tests/_internal/test_transport.py +++ b/python/lib/sift_client/_tests/_internal/test_transport.py @@ -5,10 +5,9 @@ import pytest from sift_client._internal.grpc_transport.transport import ( - MAX_DECODING_MESSAGE_SIZE, _compute_channel_options, ) -from sift_client.transport.grpc_transport import GrpcClient, GrpcConfig +from sift_client.transport.grpc_transport import MAX_DECODING_MESSAGE_SIZE, GrpcClient, GrpcConfig from sift_client.transport.rest_transport import DEFAULT_REST_TIMEOUT, RestClient, RestConfig diff --git a/python/lib/sift_client/transport/grpc_transport.py b/python/lib/sift_client/transport/grpc_transport.py index 07a64b905e..738ba40c36 100644 --- a/python/lib/sift_client/transport/grpc_transport.py +++ b/python/lib/sift_client/transport/grpc_transport.py @@ -20,6 +20,9 @@ use_sift_async_channel, ) +MAX_DECODING_MESSAGE_SIZE = 50 * 1024 * 1024 +"""Largest gRPC message the client will accept or send, in bytes (50 MiB).""" + # Configure logging logger = logging.getLogger(__name__) @@ -48,6 +51,8 @@ def __init__( cert_via_openssl: bool = False, metadata: dict[str, str] | None = None, request_timeout: float | None = DEFAULT_REQUEST_TIMEOUT_SECONDS, + max_receive_message_length: int = MAX_DECODING_MESSAGE_SIZE, + max_send_message_length: int = MAX_DECODING_MESSAGE_SIZE, ): """Initialize the gRPC configuration. @@ -60,6 +65,10 @@ def __init__( metadata: Additional metadata to include in all requests. request_timeout: Default deadline in seconds applied to unary RPCs that don't set their own. Defaults to 60s. Set to None to disable the default deadline. + max_receive_message_length: Maximum gRPC message size the client will accept (bytes). + Defaults to `MAX_DECODING_MESSAGE_SIZE`. + max_send_message_length: Maximum gRPC message size the client will send (bytes). + Defaults to `MAX_DECODING_MESSAGE_SIZE`. """ parsed_url = urlparse(url) normalized_url = url @@ -77,6 +86,8 @@ def __init__( self.cert_via_openssl = cert_via_openssl self.metadata = metadata or {} self.request_timeout = request_timeout + self.max_receive_message_length = max_receive_message_length + self.max_send_message_length = max_send_message_length def _to_sift_channel_config(self) -> SiftChannelConfig: """Convert to a SiftChannelConfig. @@ -90,6 +101,8 @@ def _to_sift_channel_config(self) -> SiftChannelConfig: "use_ssl": self.use_ssl, "cert_via_openssl": self.cert_via_openssl, "request_timeout": self.request_timeout, + "max_receive_message_length": self.max_receive_message_length, + "max_send_message_length": self.max_send_message_length, }