This Web tutorial and also this SO answer recommend the use of semaphores to limit the number of concurrent requests made with aiohttp.
I am confused because aiohttp
provides on its own a facility to limit the number of concurrent connections (limit
and limit_per_host
, documented here) - so is using semaphores not reinventing the wheel?
Perhaps it's not. Can there be multiple concurrent requests per connection? It appears there can, as per this Wikipedia article and also this SO answer. So perhaps setting limit
and/or limit_per_host
in aiohttp
, which as per the docs I linked to limits concurrent connections, does not have the effect of limiting concurrent requests.
I'm still confused because if this is the case, what's the use of these parameters aiohttp
provides? Why would a user want to limit connections rather than requests? But such reasoning of course doesn't entail anything so I was ready to move on and use semaphores.
Then I stumbled upon this SO question. It has two relatively highly upvoted answers. One of these answers again recommends using semaphores. But the other answer recommends making use of the aiohttp
facilities limit
and limit_per_host
. If this answer is correct then limiting connections in aiohttp
also limits requests - so no semaphores are necessary (unless one also wishes to limit the rate of requests per second, which is not what I'm tackling here)
And this is what I'd like to ask in this question. Does limiting concurrent connections in aiohttp
via limit
and/or limit_per_host
also limit concurrent requests? I suppose that the answer depends on whether aiohttp
does or does not use only one connection per request, which I don't know either.
Does aiohttp
only use one connection per request? Does limiting concurrent connections also limit concurrent requests?