From 9e81b28b2cbd74203101537534e4ff29b8cdb678 Mon Sep 17 00:00:00 2001 From: Sebastian Niehus Date: Mon, 10 Jun 2024 16:46:21 +0200 Subject: [PATCH] fix: Cap LimitedConcurrencyClient.max_concurrency at 10 * Fix port of trace viewer in docker-compose.yml * Increase error bound for highlighting tests TASK: PHS-524 --- CHANGELOG.md | 2 ++ docker-compose.yaml | 2 +- .../connectors/limited_concurrency_client.py | 17 +++++++++++++---- tests/core/test_text_highlight.py | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7220985a..88677344f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ ### Fixes - ControlModels throw warning instead of error in case a not recommended model is selected. + - Cap `LimitedConcurrencyClient.max_concurrency` at 10 and set default to 10. + ### Deprecations ... diff --git a/docker-compose.yaml b/docker-compose.yaml index 7aae3e227..8b19412bf 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -37,4 +37,4 @@ services: trace_viewer: image: ghcr.io/aleph-alpha/trace-viewer-trace-viewer:main ports: - - 3000:3000 + - 5173:3000 diff --git a/src/intelligence_layer/connectors/limited_concurrency_client.py b/src/intelligence_layer/connectors/limited_concurrency_client.py index 189269dfa..f306d89af 100644 --- a/src/intelligence_layer/connectors/limited_concurrency_client.py +++ b/src/intelligence_layer/connectors/limited_concurrency_client.py @@ -1,4 +1,5 @@ import time +import warnings from functools import lru_cache from os import getenv from threading import Semaphore @@ -98,12 +99,12 @@ class LimitedConcurrencyClient: """An Aleph Alpha Client wrapper that limits the number of concurrent requests. This just delegates each call to the wrapped Aleph Alpha Client and ensures that - never more then a given number of concurrent calls are executed against the API. + never more than a given number of concurrent calls are executed against the API. Args: client: The wrapped `Client`. max_concurrency: the maximal number of requests that may run concurrently - against the API. + against the API. Defaults to 10, which is also the maximum. max_retry_time: the maximal time in seconds a complete is retried in case a `BusyError` is raised. """ @@ -111,11 +112,19 @@ class LimitedConcurrencyClient: def __init__( self, client: AlephAlphaClientProtocol, - max_concurrency: int = 20, + max_concurrency: int = 10, max_retry_time: int = 24 * 60 * 60, # one day in seconds ) -> None: self._client = client - self._concurrency_limit_semaphore = Semaphore(max_concurrency) + + limit_for_max_concurrency = 10 + capped_max_concurrency = min(limit_for_max_concurrency, max_concurrency) + if max_concurrency > capped_max_concurrency: + warnings.warn( + f"Selected a value greater than the maximum allowed number. max_concurrency will be reduced to {limit_for_max_concurrency}." + ) + self._concurrency_limit_semaphore = Semaphore(capped_max_concurrency) + self._max_retry_time = max_retry_time @classmethod diff --git a/tests/core/test_text_highlight.py b/tests/core/test_text_highlight.py index 2a535d20f..443bff913 100644 --- a/tests/core/test_text_highlight.py +++ b/tests/core/test_text_highlight.py @@ -309,4 +309,4 @@ def test_highlight_clamps_end_correctly( # then assert result.highlights[0].start == start assert result.highlights[0].end == end - assert abs(result.highlights[0].score - score) <= 0.01 + assert abs(result.highlights[0].score - score) <= 0.02