Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #9645/541b1496 backport][3.10] Add benchmark for roundtrip of 100 large WebSocket messages #9647

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/test_benchmarks_client_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pytest_codspeed import BenchmarkFixture

from aiohttp import web
from aiohttp.http_websocket import MSG_SIZE
from aiohttp.pytest_plugin import AiohttpClient


Expand Down Expand Up @@ -37,3 +38,35 @@ async def run_websocket_benchmark() -> None:
@benchmark
def _run() -> None:
loop.run_until_complete(run_websocket_benchmark())


def test_one_thousand_large_round_trip_websocket_text_messages(
loop: asyncio.AbstractEventLoop,
aiohttp_client: AiohttpClient,
benchmark: BenchmarkFixture,
) -> None:
"""Benchmark round trip of 100 large WebSocket text messages."""
message_count = 100
raw_message = "x" * MSG_SIZE * 4

async def handler(request: web.Request) -> web.WebSocketResponse:
ws = web.WebSocketResponse()
await ws.prepare(request)
for _ in range(message_count):
await ws.send_str(raw_message)
await ws.close()
return ws

app = web.Application()
app.router.add_route("GET", "/", handler)

async def run_websocket_benchmark() -> None:
client = await aiohttp_client(app)
resp = await client.ws_connect("/")
for _ in range(message_count):
await resp.receive()
await resp.close()

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