Skip to content

Commit

Permalink
Add benchmark for roundtrip of 100 large WebSocket messages (#9645)
Browse files Browse the repository at this point in the history
(cherry picked from commit 541b149)
  • Loading branch information
bdraco authored and patchback[bot] committed Nov 3, 2024
1 parent 6fff131 commit f501ac7
Showing 1 changed file with 33 additions and 0 deletions.
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._websocket.helpers 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())

0 comments on commit f501ac7

Please sign in to comment.