Skip to content

Commit

Permalink
Add benchmark for streaming API iter_chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Feb 6, 2025
1 parent 0d44b6a commit bb24ebd
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/test_benchmarks_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_one_hundred_get_requests_with_512kib_chunked_payload(
aiohttp_client: AiohttpClient,
benchmark: BenchmarkFixture,
) -> None:
"""Benchmark 100 GET requests with a payload of 512KiB."""
"""Benchmark 100 GET requests with a payload of 512KiB using read."""
message_count = 100
payload = b"a" * (2**19)

Expand All @@ -148,6 +148,36 @@ def _run() -> None:
loop.run_until_complete(run_client_benchmark())


def test_one_hundred_get_requests_iter_chunks_on_512kib_chunked_payload(
loop: asyncio.AbstractEventLoop,
aiohttp_client: AiohttpClient,
benchmark: BenchmarkFixture,
) -> None:
"""Benchmark 100 GET requests with a payload of 512KiB using iter_chunks."""
message_count = 100
payload = b"a" * (2**19)

async def handler(request: web.Request) -> web.Response:
resp = web.Response(body=payload)
resp.enable_chunked_encoding()
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("/")
async for _ in resp.content.iter_chunks():
pass
await client.close()

@benchmark
def _run() -> None:
loop.run_until_complete(run_client_benchmark())


def test_get_request_with_251308_compressed_chunked_payload(
loop: asyncio.AbstractEventLoop,
aiohttp_client: AiohttpClient,
Expand Down

0 comments on commit bb24ebd

Please sign in to comment.