Skip to content

Commit

Permalink
Merge pull request #914 from vespa-engine/thomasht86/compress-syncio
Browse files Browse the repository at this point in the history
feat: expose "compress" argument
  • Loading branch information
thomasht86 authored Sep 17, 2024
2 parents 0dc28ed + 6d7279f commit 3d826b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/integration/test_integration_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def setUp(self) -> None:
for i in range(10)
]
self.queries_first_hit = ["this is title 1", "this is title 2"]
self.compress_args = [True, False, "auto", None]
self.compress_args = [True, False, "auto"]

def test_is_using_http2_client(self):
asyncio.run(self.async_is_http2_client(app=self.app))
Expand Down
20 changes: 17 additions & 3 deletions vespa/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ def syncio(
:return: Instance of Vespa asynchronous layer.
"""
return VespaSync(
app=self, pool_connections=connections, pool_maxsize=connections
app=self,
pool_connections=connections,
pool_maxsize=connections,
compress=compress,
)

@staticmethod
Expand Down Expand Up @@ -299,6 +302,7 @@ def feed_data_point(
fields: Dict,
namespace: str = None,
groupname: str = None,
compress: Union[str, bool] = "auto",
**kwargs,
) -> VespaResponse:
"""
Expand All @@ -325,13 +329,16 @@ def feed_data_point(
:param fields: Dict containing all the fields required by the `schema`.
:param namespace: The namespace that we are sending data to.
:param groupname: The groupname that we are sending data
:param compress (Union[str, bool], optional): Whether to compress the request body. Defaults to "auto", which will compress if the body is larger than 1024 bytes.
:return: VespaResponse of the HTTP POST request.
"""
if not namespace:
namespace = schema
# Use low low connection settings to avoid too much overhead for a
# single data point
with VespaSync(app=self, pool_connections=1, pool_maxsize=1) as sync_app:
with VespaSync(
app=self, pool_connections=1, pool_maxsize=1, compress=compress
) as sync_app:
return sync_app.feed_data_point(
schema=schema,
data_id=data_id,
Expand All @@ -351,6 +358,7 @@ def feed_iterable(
max_queue_size: int = 1000,
max_workers: int = 8,
max_connections: int = 16,
compress: Union[str, bool] = "auto",
**kwargs,
):
"""
Expand Down Expand Up @@ -378,6 +386,7 @@ def callback(response, id):
:param max_queue_size: The maximum size of the blocking queue and max in-flight operations.
:param max_workers: The maximum number of workers in the threadpool executor.
:param max_connections: The maximum number of persisted connections to the Vespa endpoint.
:param compress (Union[str, bool], optional): Whether to compress the request body. Defaults to "auto", which will compress if the body is larger than 1024 bytes.
:param kwargs: Additional parameters are passed to the respective operation type specific :func:`_data_point`.
"""
if operation_type not in ["feed", "update", "delete"]:
Expand Down Expand Up @@ -519,6 +528,7 @@ def _handle_result_callback(
app=self,
pool_maxsize=max_connections,
pool_connections=max_connections,
compress=compress,
) as session:
queue = Queue(maxsize=max_queue_size)
with ThreadPoolExecutor(max_workers=max_workers) as executor:
Expand Down Expand Up @@ -829,6 +839,7 @@ def update_data(
create: bool = False,
namespace: str = None,
groupname: str = None,
compress: Union[str, bool] = "auto",
**kwargs,
) -> VespaResponse:
"""
Expand All @@ -852,11 +863,14 @@ def update_data(
:param auto_assign: Assumes `fields`-parameter is an assignment operation. (https://docs.vespa.ai/en/reference/document-json-format.html#assign). If set to false, the fields parameter should be a dictionary including the update operation.
:param namespace: The namespace that we are updating data. If no namespace is provided the schema is used.
:param groupname: The groupname that we are updating data.
:param compress (Union[str, bool], optional): Whether to compress the request body. Defaults to "auto", which will compress if the body is larger than 1024 bytes.
:param kwargs: Additional arguments to be passed to the HTTP PUT request. https://docs.vespa.ai/en/reference/document-v1-api-reference.html#request-parameters
:return: Response of the HTTP PUT request.
"""

with VespaSync(self, pool_connections=1, pool_maxsize=1) as sync_app:
with VespaSync(
self, pool_connections=1, pool_maxsize=1, compress=compress
) as sync_app:
return sync_app.update_data(
schema=schema,
data_id=data_id,
Expand Down

0 comments on commit 3d826b3

Please sign in to comment.