From de0b21ee3a4c07f9d43d57ebdf6d6909ae6aa8ae Mon Sep 17 00:00:00 2001 From: PowderLi Date: Thu, 28 Mar 2024 15:09:34 +0800 Subject: [PATCH] add grpc compression Signed-off-by: PowderLi --- pymilvus/client/grpc_handler.py | 10 ++++++++++ pymilvus/orm/connections.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/pymilvus/client/grpc_handler.py b/pymilvus/client/grpc_handler.py index af36b1449..ba8013ee3 100644 --- a/pymilvus/client/grpc_handler.py +++ b/pymilvus/client/grpc_handler.py @@ -64,6 +64,13 @@ len_of, ) +_DESCRIPTION = "A client capable of compression." +_COMPRESSION_OPTIONS = { + "none": grpc.Compression.NoCompression, + "deflate": grpc.Compression.Deflate, + "gzip": grpc.Compression.Gzip, +} + class GrpcHandler: # pylint: disable=too-many-instance-attributes @@ -84,6 +91,7 @@ def __init__( self._log_level = None self._request_id = None self._user = kwargs.get("user", None) + self._compression_type = kwargs.get("compression_type", "none") self._set_authorization(**kwargs) self._setup_db_interceptor(kwargs.get("db_name", None)) self._setup_grpc_channel() @@ -193,6 +201,7 @@ def _setup_grpc_channel(self): self._channel = grpc.insecure_channel( self._address, options=opts, + compression=_COMPRESSION_OPTIONS[self._compression_type], ) else: if self._server_name != "": @@ -223,6 +232,7 @@ def _setup_grpc_channel(self): self._address, creds, options=opts, + compression=_COMPRESSION_OPTIONS[self._compression_type], ) # avoid to add duplicate headers. diff --git a/pymilvus/orm/connections.py b/pymilvus/orm/connections.py index 1373f93c2..2d0076a85 100644 --- a/pymilvus/orm/connections.py +++ b/pymilvus/orm/connections.py @@ -332,6 +332,8 @@ def connect( to each RPC call. * *keep_alive* (``bool``) -- Optional. Default is false. If set to true, client will keep an alive connection. + * *compression_type* (``str``) -- + Optional. Default is none. ["none", "deflate", "gzip"] * *db_name* (``str``) -- Optional. default database name of this connection * *client_key_path* (``str``) --