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

[Core] Support the reduction of Port rate limit in the integrations #1155

Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 6 additions & 2 deletions port_ocean/clients/port/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# period of time, before raising an exception.
# The max_connections value can't be too high, as it will cause the application to run out of memory.
# The max_keepalive_connections can't be too high, as it will cause the application to run out of available connections.
PORT_HTTP_MAX_CONNECTIONS_LIMIT = 200
PORT_HTTP_MAX_CONNECTIONS_LIMIT = 100
Copy link
Member

Choose a reason for hiding this comment

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

Wonder if it's worth having this configurable by env var for quick patches/tests later on

PORT_HTTP_MAX_KEEP_ALIVE_CONNECTIONS = 50
PORT_HTTP_TIMEOUT = 60.0

Expand All @@ -34,7 +34,11 @@ def _get_http_client_context(port_client: "PortClient") -> httpx.AsyncClient:
if client is None:
client = OceanAsyncClient(
TokenRetryTransport,
transport_kwargs={"port_client": port_client},
transport_kwargs={
"port_client": port_client,
"max_backoff_wait": 60 * 5,
shalev007 marked this conversation as resolved.
Show resolved Hide resolved
"base_delay": 0.3,
},
timeout=PORT_HTTPX_TIMEOUT,
limits=PORT_HTTPX_LIMITS,
)
Expand Down
12 changes: 6 additions & 6 deletions port_ocean/helpers/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class RetryTransport(httpx.AsyncBaseTransport, httpx.BaseTransport):
HTTPStatus.GATEWAY_TIMEOUT,
]
)
MAX_BACKOFF_WAIT = 60
MAX_BACKOFF_WAIT_IN_SECONDS = 60

def __init__(
self,
wrapped_transport: Union[httpx.BaseTransport, httpx.AsyncBaseTransport],
max_attempts: int = 10,
max_backoff_wait: float = MAX_BACKOFF_WAIT,
backoff_factor: float = 0.1,
max_backoff_wait: float = MAX_BACKOFF_WAIT_IN_SECONDS,
base_delay: float = 0.1,
jitter_ratio: float = 0.1,
respect_retry_after_header: bool = True,
retryable_methods: Iterable[str] | None = None,
Expand All @@ -81,7 +81,7 @@ def __init__(
max_backoff_wait (float, optional):
The maximum amount of time (in seconds) to wait before retrying a request.
Defaults to 60.
backoff_factor (float, optional):
base_delay (float, optional):
The factor by which the waiting time will be multiplied in each retry attempt.
Defaults to 0.1.
jitter_ratio (float, optional):
Expand All @@ -105,7 +105,7 @@ def __init__(
)

self._max_attempts = max_attempts
self._backoff_factor = backoff_factor
self._base_delay = base_delay
self._respect_retry_after_header = respect_retry_after_header
self._retryable_methods = (
frozenset(retryable_methods)
Expand Down Expand Up @@ -255,7 +255,7 @@ def _calculate_sleep(
except ValueError:
pass

backoff = self._backoff_factor * (2 ** (attempts_made - 1))
backoff = self._base_delay * (2 ** (attempts_made - 1))
jitter = (backoff * self._jitter_ratio) * random.choice([1, -1])
total_backoff = backoff + jitter
return min(total_backoff, self._max_backoff_wait)
Expand Down