From 12c8c5b0bf49b206153507e8f822ee74cb413c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=B6rpel?= Date: Fri, 29 Nov 2024 09:11:31 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=90=20Add=20async=20test=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- async_ddos.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 async_ddos.py diff --git a/async_ddos.py b/async_ddos.py new file mode 100644 index 0000000..9fd4bc6 --- /dev/null +++ b/async_ddos.py @@ -0,0 +1,21 @@ +import asyncio + +import requests +from codetiming import Timer + +URL = "http://localhost:8000/entities?schema=Membership&nested=1&page={i}&limit=100" + + +async def task(i): + with Timer(text=f"Page {i} elapsed time: {{:.1f}}"): + res = requests.get(URL.format(i=i)) + assert res.ok + + +async def main(): + tasks = [asyncio.create_task(task(i)) for i in range(1, 100)] + await asyncio.gather(*tasks) + + +if __name__ == "__main__": + asyncio.run(main())