I'm trying to create a web traffic simulator using aiohttp
. The following code sample makes 10k requests asynchronously. I want to know how many of them are happening concurrently so I can say this models 10k users requesting a website simultaneously.
How would I determine the number of concurrent network requests or how do I determine how many requests per second are made by aiohttp? Is there a way to debug/profile the number of concurrent requests in real time?
Is there a better way to model a web traffic simulator using any other programming language?
import asyncio
import aiohttp
async def fetch(session, url):
with aiohttp.Timeout(10, loop=session.loop):
async with session.get(url) as response:
return await response.text()
async def run(r):
url = "http://localhost:3000/"
tasks = []
# Create client session that will ensure we dont open new connection
# per each request.
async with aiohttp.ClientSession() as session:
for i in range(r):
html = await fetch(session, url)
print(html)
# make 10k requests per second ?? (not confident this is true)
number = 10000
loop = asyncio.get_event_loop()
loop.run_until_complete(run(number))