Y
Y
YuriyCherniy2021-03-08 22:51:15
Django
YuriyCherniy, 2021-03-08 22:51:15

How to solve the problem of requests using the requests library to unresponsive servers?

Greetings. The documentation for requests recommends using a timeout of slightly more than 3 seconds.

It’s a good practice to set connect timeouts to slightly larger than a multiple of 3, which is the default TCP packet retransmission window.
r = requests.get('https://github.com', timeout=3.05)

My understanding is that if ten users send a request to unresponsive servers, the eleventh user will wait over 30 seconds for their request to be processed. How do you solve such a problem in the context of a Django application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-03-09
@YuriyCherniy

1. Make the check a background task
2. Use the async feature in django, you will step on a bunch of rakes, not all places are async there yet
3. Move it to a separate service, where instead of django you can take some async framework.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question