python-asyncio: update retry factors for actual exponential retries (#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]: ba2169891f/aiohttp_retry/retry_options.py (L38-L65)

* updated example
This commit is contained in:
Gergely Imreh 2024-08-12 17:35:00 +08:00 committed by GitHub
parent d1b9f9284a
commit fdd2dc9651
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -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
)
)

View File

@ -89,8 +89,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
)
)