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

Add benchmark for sending large WebSocket messages #9635

Merged
merged 5 commits into from
Nov 3, 2024
Merged
Changes from 2 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
20 changes: 19 additions & 1 deletion tests/test_benchmarks_http_websocket.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""codspeed benchmarks for http websocket."""

import asyncio
from typing import Iterable, Union
Fixed Show fixed Hide fixed
bdraco marked this conversation as resolved.
Show resolved Hide resolved

from pytest_codspeed import BenchmarkFixture

from aiohttp import DataQueue
from aiohttp._websocket.helpers import MSG_SIZE
from aiohttp.base_protocol import BaseProtocol
from aiohttp.http_websocket import (
WebSocketReader,
Expand Down Expand Up @@ -41,7 +43,7 @@
"""Swallow is_closing."""
return False

def write(self, data: bytes) -> None:
def write(self, data: Union[bytes, bytearray, memoryview]) -> None:
"""Swallow writes."""


Expand All @@ -67,6 +69,22 @@
loop.run_until_complete(_send_one_hundred_websocket_text_messages())


def test_send_one_hundred_large_websocket_text_messages(
loop: asyncio.AbstractEventLoop, benchmark: BenchmarkFixture
) -> None:
"""Benchmark sending 100 WebSocket text messages."""
writer = WebSocketWriter(MockProtocol(loop=loop), MockTransport())
raw_message = b"x" * MSG_SIZE * 2
bdraco marked this conversation as resolved.
Show resolved Hide resolved

async def _send_one_hundred_websocket_text_messages() -> None:
for _ in range(100):
await writer.send_frame(raw_message, WSMsgType.TEXT)

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


def test_send_one_hundred_websocket_text_messages_with_mask(
loop: asyncio.AbstractEventLoop, benchmark: BenchmarkFixture
) -> None:
Expand Down
Loading