I'm trying to achieve fine-grained throttling with aiohttp.
By fine-grained, I mean that controlling how many requests are simultaneously executed is not enough, I want to rate-limit the number of requests to match 100 requests per 10 seconds interval.
The interesting part resides in throttled_coroutine
which acquires/releases a lock at a speed which is exactly the rate-limit I want to enforce by either:
- waiting a delay once requests performing very quickly are completed
- releasing lock before completion of requests performing poorly
At the end of a batch of requests, last coroutines tend to wait for no reason. This behaviour amplifies when timeout increases.