From 6894d4e19badbac41684933ab25d65763c5d527c Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 04:41:27 +0000 Subject: [PATCH] [PR #9824/dc7eee65 backport][3.11] Add benchmark for GET requests with reading a payload (#9826) Co-authored-by: J. Nick Koston --- tests/test_benchmarks_client.py | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/tests/test_benchmarks_client.py b/tests/test_benchmarks_client.py index 77c9108a657..8c141581266 100644 --- a/tests/test_benchmarks_client.py +++ b/tests/test_benchmarks_client.py @@ -33,6 +33,87 @@ def _run() -> None: loop.run_until_complete(run_client_benchmark()) +def test_one_hundred_get_requests_with_2048_payload( + loop: asyncio.AbstractEventLoop, + aiohttp_client: AiohttpClient, + benchmark: BenchmarkFixture, +) -> None: + """Benchmark 100 GET requests with a small payload of 2048 bytes.""" + message_count = 100 + payload = b"a" * 2048 + + async def handler(request: web.Request) -> web.Response: + return web.Response(body=payload) + + app = web.Application() + app.router.add_route("GET", "/", handler) + + async def run_client_benchmark() -> None: + client = await aiohttp_client(app) + for _ in range(message_count): + resp = await client.get("/") + await resp.read() + await client.close() + + @benchmark + def _run() -> None: + loop.run_until_complete(run_client_benchmark()) + + +def test_one_hundred_get_requests_with_32768_payload( + loop: asyncio.AbstractEventLoop, + aiohttp_client: AiohttpClient, + benchmark: BenchmarkFixture, +) -> None: + """Benchmark 100 GET requests with a payload of 32768 bytes.""" + message_count = 100 + payload = b"a" * 32768 + + async def handler(request: web.Request) -> web.Response: + return web.Response(body=payload) + + app = web.Application() + app.router.add_route("GET", "/", handler) + + async def run_client_benchmark() -> None: + client = await aiohttp_client(app) + for _ in range(message_count): + resp = await client.get("/") + await resp.read() + await client.close() + + @benchmark + def _run() -> None: + loop.run_until_complete(run_client_benchmark()) + + +def test_one_hundred_get_requests_with_1mib_payload( + loop: asyncio.AbstractEventLoop, + aiohttp_client: AiohttpClient, + benchmark: BenchmarkFixture, +) -> None: + """Benchmark 100 GET requests with a payload of 1MiB bytes.""" + message_count = 100 + payload = b"a" * 1024**2 + + async def handler(request: web.Request) -> web.Response: + return web.Response(body=payload) + + app = web.Application() + app.router.add_route("GET", "/", handler) + + async def run_client_benchmark() -> None: + client = await aiohttp_client(app) + for _ in range(message_count): + resp = await client.get("/") + await resp.read() + await client.close() + + @benchmark + def _run() -> None: + loop.run_until_complete(run_client_benchmark()) + + def test_one_hundred_simple_post_requests( loop: asyncio.AbstractEventLoop, aiohttp_client: AiohttpClient,