You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
868 B
40 lines
868 B
2 years ago
|
import asyncio
|
||
|
import sys
|
||
|
import time
|
||
|
|
||
|
import aiohttp
|
||
|
import uvloop
|
||
|
|
||
|
|
||
|
async def do_req(sesh, url):
|
||
|
async with sesh.get(url, allow_redirects=False) as resp:
|
||
|
assert resp.status == 302
|
||
|
|
||
|
|
||
|
async def main():
|
||
|
if len(sys.argv) < 2:
|
||
|
exit("usage: python performance.py <url>")
|
||
|
url = sys.argv[1]
|
||
|
async with aiohttp.ClientSession() as sesh:
|
||
|
await do_req(sesh, url)
|
||
|
|
||
|
await asyncio.sleep(1)
|
||
|
|
||
|
tasks = []
|
||
|
for i in range(10000):
|
||
|
tasks.append(do_req(sesh, url))
|
||
|
|
||
|
# aaand liftoff!
|
||
|
before = time.time()
|
||
|
await asyncio.gather(*tasks)
|
||
|
after = time.time()
|
||
|
|
||
|
return after - before
|
||
|
|
||
|
uvloop.install()
|
||
|
t = asyncio.run(main())
|
||
|
|
||
|
print(f"completed 10k requests in {t:.4f} seconds")
|
||
|
if t > 10:
|
||
|
print('if that was a redirect endpoint something seems off here. go optimize performance')
|