From a556c444988799167994e9e3135c67b35d7156d3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 12 Nov 2024 11:36:46 -0600 Subject: [PATCH 1/3] Add benchmark for sending compressed payload with chunks --- 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..a12a6f498a7 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_one_hundred_get_requests_with_567296_compressed_chunked_payload( + loop: asyncio.AbstractEventLoop, + aiohttp_client: AiohttpClient, + benchmark: BenchmarkFixture, +) -> None: + """Benchmark 100 GET requests with a payload of 567296.""" + message_count = 100 + # 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, From f70b979e4b4c7f4078da1667ab960d56925b9af1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 12 Nov 2024 11:59:38 -0600 Subject: [PATCH 2/3] Apply suggestions from code review --- tests/test_benchmarks_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_benchmarks_client.py b/tests/test_benchmarks_client.py index a12a6f498a7..4bdcd5401db 100644 --- a/tests/test_benchmarks_client.py +++ b/tests/test_benchmarks_client.py @@ -120,13 +120,13 @@ def _run() -> None: loop.run_until_complete(run_client_benchmark()) -def test_one_hundred_get_requests_with_567296_compressed_chunked_payload( +def test_ten_get_requests_with_567296_compressed_chunked_payload( loop: asyncio.AbstractEventLoop, aiohttp_client: AiohttpClient, benchmark: BenchmarkFixture, ) -> None: - """Benchmark 100 GET requests with a payload of 567296.""" - message_count = 100 + """Benchmark 10 compressed GET requests with a payload of 567296.""" + message_count = 10 # This payload compresses poorly to ~567296 bytes. payload = ( bytes(range(0, 256)) From f57070615e27e4b013c295346b1e77bb20032a89 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 12 Nov 2024 12:06:55 -0600 Subject: [PATCH 3/3] Apply suggestions from code review --- tests/test_benchmarks_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_benchmarks_client.py b/tests/test_benchmarks_client.py index 4bdcd5401db..2712b52f046 100644 --- a/tests/test_benchmarks_client.py +++ b/tests/test_benchmarks_client.py @@ -120,13 +120,13 @@ def _run() -> None: loop.run_until_complete(run_client_benchmark()) -def test_ten_get_requests_with_567296_compressed_chunked_payload( +def test_five_get_requests_with_567296_compressed_chunked_payload( loop: asyncio.AbstractEventLoop, aiohttp_client: AiohttpClient, benchmark: BenchmarkFixture, ) -> None: - """Benchmark 10 compressed GET requests with a payload of 567296.""" - message_count = 10 + """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))