Skip to content

Instantly share code, notes, and snippets.

@im-noob
Created August 20, 2020 04:36
Show Gist options
  • Save im-noob/0035d97b876bf33a38763c91d35eb6f6 to your computer and use it in GitHub Desktop.
Save im-noob/0035d97b876bf33a38763c91d35eb6f6 to your computer and use it in GitHub Desktop.
Generating 1 Million Request With A sync request with aiohttp
'''
Reuire More than 12 GB ram to process all the request..
'''
import asyncio
from aiohttp import ClientSession
import nest_asyncio
nest_asyncio.apply()
async def hello(url):
async with ClientSession() as session:
async with session.get(url) as response:
response = response.read()
loop = asyncio.get_event_loop()
tasks = []
url = "http://example.com/"
for i in range(1000_000):
print('Request no',i)
task = asyncio.ensure_future(hello(url.format(i)))
tasks.append(task)
loop.run_until_complete(asyncio.wait(tasks))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment