Compare commits

...

3 Commits

Author SHA1 Message Date
Marcelo Trylesinski
d6dad8ebd1 Revert "Disable pytest-xdist for CodSpeed benchmark runs"
This reverts commit 56da070f2a.
2026-03-15 17:05:44 +01:00
Marcelo Trylesinski
56da070f2a Disable pytest-xdist for CodSpeed benchmark runs
CodSpeed instrumentation does not work with parallel test execution.
Pass -n 0 to disable xdist workers.
2026-03-15 17:05:09 +01:00
Marcelo Trylesinski
81f0c53c2d Add fragmented body benchmark for chunked body accumulation
Sends 100KB in 390 x 256-byte chunks to exercise the body += path
that triggers O(n^2) allocation with bytes concatenation.
2026-03-15 16:57:25 +01:00
2 changed files with 24 additions and 0 deletions

View File

@ -61,6 +61,20 @@ START_POST_REQUEST = b"\r\n".join(
FINISH_POST_REQUEST = b'{"hello": "world"}'
BODY_CHUNK_SIZE = 256
FRAGMENTED_BODY_SIZE = 100_000
FRAGMENTED_POST_HEADERS = b"\r\n".join(
[
b"POST / HTTP/1.1",
b"Host: example.org",
b"Content-Type: application/octet-stream",
b"Content-Length: " + str(FRAGMENTED_BODY_SIZE).encode(),
b"",
b"",
]
)
FRAGMENTED_BODY_CHUNKS = [b"x" * BODY_CHUNK_SIZE] * (FRAGMENTED_BODY_SIZE // BODY_CHUNK_SIZE)
class MockTransport:
def __init__(self) -> None:

View File

@ -7,6 +7,8 @@ import pytest
from tests.benchmarks.http import (
CONNECTION_CLOSE_REQUEST,
FINISH_POST_REQUEST,
FRAGMENTED_BODY_CHUNKS,
FRAGMENTED_POST_HEADERS,
HTTP10_GET_REQUEST,
LARGE_POST_REQUEST,
SIMPLE_GET_REQUEST,
@ -91,6 +93,14 @@ async def test_bench_connection_close(http_protocol_cls: type[HTTPProtocol]) ->
await protocol.loop.run_one()
async def test_bench_fragmented_body(http_protocol_cls: type[HTTPProtocol]) -> None:
protocol = get_connected_protocol(_plain_text_app, http_protocol_cls)
protocol.data_received(FRAGMENTED_POST_HEADERS)
for chunk in FRAGMENTED_BODY_CHUNKS:
protocol.data_received(chunk)
await protocol.loop.run_one()
async def test_bench_post_body_receive(http_protocol_cls: type[HTTPProtocol]) -> None:
protocol = get_connected_protocol(_body_echo_app, http_protocol_cls)
protocol.data_received(START_POST_REQUEST)