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

fix: Cap LimitedConcurrencyClient.max_concurrency at 10 #900

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
...

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ services:
trace_viewer:
image: ghcr.io/aleph-alpha/trace-viewer-trace-viewer:main
ports:
- 3000:3000
- 5173:3000
17 changes: 13 additions & 4 deletions src/intelligence_layer/connectors/limited_concurrency_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import warnings
from functools import lru_cache
from os import getenv
from threading import Semaphore
Expand Down Expand Up @@ -98,24 +99,32 @@ 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.

"""

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
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_text_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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