|
|
|
|
|
by takeda
3712 days ago
|
|
IMO you should place all requests within a single ClientSession(). This will provide two benefits: 1. You won't need to use a semaphore. To limit connections you will need to create a TCPConnection() object with limit set to the limit you used in the semaphore and pass it to the ClientSession() and aiohttp will not make more connections than the limit set (default behavior is to have unlimited number of connections). 2. With single ClientSession(), aiohttp will make use of keep-alive (i.e. it will reuse same connections for next requests, but it will keep at most the limit of connections you set in TCPConnection() object). This should improve performance further, and (given sane limit) it'll also solve issue with "Cannot assign requested address" error. BTW: Even without limit set aiohttp will try to reduce number of connections open so it might still fix the connection error issue as long as individual requests don't take long. It's still good idea to set limit, just to be nice to the remote server. |
|