Created
August 20, 2020 04:36
-
-
Save im-noob/0035d97b876bf33a38763c91d35eb6f6 to your computer and use it in GitHub Desktop.
Generating 1 Million Request With A sync request with aiohttp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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