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

feat: add grpc compression #2007

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check if compression_type is valid and raise meaningful exception, or the following dict[xxx] might raise KeyError exception

self._set_authorization(**kwargs)
self._setup_db_interceptor(kwargs.get("db_name", None))
self._setup_grpc_channel()
Expand Down Expand Up @@ -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 != "":
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions pymilvus/orm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``) --
Expand Down