Skip to content

Commit

Permalink
Add benchmark for GET requests with reading a payload (#9824)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 12, 2024
1 parent 0f18900 commit dc7eee6
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/test_benchmarks_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dc7eee6

Please sign in to comment.