Skip to content

Commit

Permalink
[PR #9844/fabf3884 backport][3.10] Fix compressed get request benchma…
Browse files Browse the repository at this point in the history
…rk payload length (#9845)

Co-authored-by: J. Nick Koston <nick@koston.org>
  • Loading branch information
patchback[bot] and bdraco authored Nov 13, 2024
1 parent 68a1f42 commit e5917cd
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tests/test_benchmarks_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,23 @@ def _run() -> None:
loop.run_until_complete(run_client_benchmark())


def test_five_get_requests_with_567296_compressed_chunked_payload(
def test_get_request_with_251308_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
"""Benchmark compressed GET requests with a payload of 251308."""
# This payload compresses to 251308 bytes
payload = b"".join(
[
bytes((*range(0, i), *range(i, 0, -1)))
for _ in range(255)
for i in range(255)
]
)

async def handler(request: web.Request) -> web.Response:
resp = web.Response(body=payload)
resp = web.Response(body=payload, zlib_executor_size=16384)
resp.enable_compression()
return resp

Expand All @@ -145,9 +145,8 @@ async def handler(request: web.Request) -> web.Response:

async def run_client_benchmark() -> None:
client = await aiohttp_client(app)
for _ in range(message_count):
resp = await client.get("/")
await resp.read()
resp = await client.get("/")
await resp.read()
await client.close()

@benchmark
Expand Down

0 comments on commit e5917cd

Please sign in to comment.