Skip to content

Commit

Permalink
fix: Cap LimitedConcurrencyClient.max_concurrency at 10.
Browse files Browse the repository at this point in the history
 * Fix port of trace viewer in docker-compose.yml
 * Increase error bound for highlighting test
TASK: PHS-524
  • Loading branch information
SebastianNiehusAA committed Jun 10, 2024
1 parent accd7bb commit 0096124
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
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

0 comments on commit 0096124

Please sign in to comment.