From 3b1c76c0977f96dfa8a734d431c9b6936d0346a9 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:46:50 +0000 Subject: [PATCH] [PR #9840/cc5fa316 backport][3.11] Add benchmark for sending compressed payload with chunks (#9842) Co-authored-by: J. Nick Koston --- tests/test_benchmarks_client.py | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_benchmarks_client.py b/tests/test_benchmarks_client.py index 7292e4d647f..2712b52f046 100644 --- a/tests/test_benchmarks_client.py +++ b/tests/test_benchmarks_client.py @@ -120,6 +120,41 @@ def _run() -> None: loop.run_until_complete(run_client_benchmark()) +def test_five_get_requests_with_567296_compressed_chunked_payload( + loop: asyncio.AbstractEventLoop, + aiohttp_client: AiohttpClient, + benchmark: BenchmarkFixture, +) -> None: + """Benchmark 5 compressed GET requests with a payload of 567296.""" + message_count = 5 + # This payload compresses poorly to ~567296 bytes. + payload = ( + bytes(range(0, 256)) + + bytes(range(255, 0, -1)) + + bytes(range(0, 128)) + + bytes(range(255, 0, -1)) + ) * 1024 + + async def handler(request: web.Request) -> web.Response: + resp = web.Response(body=payload) + resp.enable_compression() + return resp + + 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_1024_content_length_payload( loop: asyncio.AbstractEventLoop, aiohttp_client: AiohttpClient,