openeo-python-client icon indicating copy to clipboard operation
openeo-python-client copied to clipboard

Automatic backoff/retry on `HTTP 429 Too Many Requests`

Open soxofaan opened this issue 2 years ago • 3 comments

Some backends have middleware to throttle the number of concurrent requests, returning a 429 Too Many Requests if some limit is exceeded. The python client could provide automatic retry with (e.g. exponential) backoff functionality.

related to #440

soxofaan avatar Jun 15 '23 09:06 soxofaan

The python requests library even supports this quite easily

from requests.adapters import HTTPAdapter, Retry
retries = Retry(total=5,read=10,other=10,status=10,
                backoff_factor=0.1,
                status_forcelist=[ 502, 503, 504,404,429],
                method_whitelist=["HEAD", "GET", "OPTIONS","POST"])
session.mount('https://', HTTPAdapter(max_retries=retries))
session.mount('http://', HTTPAdapter(max_retries=retries))

jdries avatar Jun 30 '23 13:06 jdries

indeed, we might consider moving this helper from python driver to python client: https://github.com/Open-EO/openeo-python-driver/blob/b9f465dc276a3d0b0217d7f76a416b7cb943cd38/openeo_driver/util/http.py#L7-L31

and we apparently also have it in MultiBackendJobManager: https://github.com/Open-EO/openeo-python-client/blob/95b89d5a8ae55d24ed3ba42b70a8abb3d6fa56b7/openeo/extra/job_management.py#L148-L167

soxofaan avatar Jun 30 '23 15:06 soxofaan