You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Aiohttp limits the number of simultaneous connections #7
When I tried to run the client/server code locally to benchmark I noticed the server was receiving connections in batches of 100 approx. This seriously limits the performance.
I found this answer on stackoverflow on why it's happening - https://stackoverflow.com/a/43857526
The script in blog can be modified to following to fix this
# modified fetch function with semaphoreimportasynciofromaiohttpimportTCPConnector, ClientSessionasyncdeffetch(url, session):
asyncwithsession.get(url) asresponse:
delay=response.headers.get("DELAY")
date=response.headers.get("DATE")
print("{}:{} with delay {}".format(date, response.url, delay))
returnawaitresponse.text()
asyncdefbound_fetch(sem, url, session):
# Getter function with semaphore.asyncwithsem:
awaitfetch(url, session)
asyncdefrun(r):
url="http://localhost:8000/{}"tasks= []
# create instance of Semaphoresem=asyncio.Semaphore(1000)
# Create client session that will ensure we dont open new connection# per each request.conn=TCPConnector(limit=0)
asyncwithClientSession(connector=conn) assession:
foriinrange(r):
# pass Semaphore and session to every GET requesttask=asyncio.ensure_future(bound_fetch(sem, url.format(i), session))
tasks.append(task)
responses=asyncio.gather(*tasks)
awaitresponsesnumber=10000asyncio.run(run(number))
Activity
[-]Aiohttp limit number of simultaneous connections[/-][+]Aiohttp limits the number of simultaneous connections[/+]