Skip to content

Commit

Permalink
python-asyncio: update retry factors for actual exponential retries (#…
Browse files Browse the repository at this point in the history
…19337)

* python-asyncio: update retry factors for actual exponential retries

As per the `aiohttp-retry` library's code[^1], the timeout is

```python
timeout = self._start_timeout * (self._factor ** attempt)
```

This means the previous setting with "start_timeout=0.0" would have
always just retried right away (0 timeout) regardless of the "factor" value,
and also, "factor=0.0" would never have increased the timeout, rather it
would have resulted in a 0 timeout regardless of the value of "start_timeout".

This double-zeroing effectively rendered exponential backoff to nothing (rather than
"retries" number of retries in quick succession.

The update is a quick fix to set the same default as in `aiohttp-retry`. In
the future this should likely be configurable (through extra Configuration settings perhaps?),
as not all APIs are created equal, but this works as a quick fix for making retries more effective.

[^1]: https://github.com/inyutin/aiohttp_retry/blob/ba2169891f5b32a5c59e48ca185dd8e68e44ded7/aiohttp_retry/retry_options.py#L38-L65

* updated example
  • Loading branch information
imrehg authored Aug 12, 2024
1 parent d1b9f92 commit fdd2dc9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class RESTClientObject:
client_session=self.pool_manager,
retry_options=aiohttp_retry.ExponentialRetry(
attempts=retries,
factor=0.0,
start_timeout=0.0,
factor=2.0,
start_timeout=0.1,
max_timeout=120.0
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def __init__(self, configuration) -> None:
client_session=self.pool_manager,
retry_options=aiohttp_retry.ExponentialRetry(
attempts=retries,
factor=0.0,
start_timeout=0.0,
factor=2.0,
start_timeout=0.1,
max_timeout=120.0
)
)
Expand Down

0 comments on commit fdd2dc9

Please sign in to comment.