Skip to content

Commit 6a5f2e9

Browse files
Copilottoby-coleman
andcommitted
Benchmark only process.run(), add RayConnector/RayProcess parametrization
- test_benchmark_process_run now uses benchmark.pedantic with setup to only time process.run(), excluding init - Added RayConnector/RayProcess to both benchmark test parametrizations - Added Ray env vars to CI workflow for benchmark tests Co-authored-by: toby-coleman <13170610+toby-coleman@users.noreply.github.com> Agent-Logs-Url: https://github.com/plugboard-dev/plugboard/sessions/2d017dc2-a948-4b46-8c61-c42be32507a4
1 parent 429c9cc commit 6a5f2e9

2 files changed

Lines changed: 46 additions & 21 deletions

File tree

.github/workflows/benchmarks.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939

4040
- name: Run benchmarks
4141
uses: CodSpeedHQ/action@v4
42+
env:
43+
RAY_ENABLE_UV_RUN_RUNTIME_ENV: 0
44+
PLUGBOARD_IO_READ_TIMEOUT: 5.0
4245
with:
4346
mode: walltime
4447
run: uv run pytest tests/benchmark/ --codspeed

tests/benchmark/test_benchmarking.py

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
import asyncio
44

55
import pytest
6+
from pytest_codspeed import BenchmarkFixture
67

7-
from plugboard.connector import AsyncioConnector, Connector, ZMQConnector
8-
from plugboard.process import LocalProcess
8+
from plugboard.connector import AsyncioConnector, Connector, RayConnector, ZMQConnector
9+
from plugboard.process import LocalProcess, Process, RayProcess
910
from plugboard.schemas import ConnectorSpec
1011
from tests.integration.test_process_with_components_run import A, B
1112

1213

1314
ITERS = 1000
1415

16+
CONNECTOR_PROCESS_PARAMS = [
17+
(AsyncioConnector, LocalProcess),
18+
(ZMQConnector, LocalProcess),
19+
(RayConnector, RayProcess),
20+
]
21+
CONNECTOR_PROCESS_IDS = ["asyncio", "zmq", "ray"]
1522

16-
def _build_process(connector_cls: type[Connector]) -> LocalProcess:
17-
"""Build a process with the given connector class."""
23+
24+
def _build_process(connector_cls: type[Connector], process_cls: type[Process]) -> Process:
25+
"""Build a process with the given connector and process class."""
1826
comp_a = A(name="comp_a", iters=ITERS)
1927
comp_b1 = B(name="comp_b1", factor=1)
2028
comp_b2 = B(name="comp_b2", factor=2)
@@ -23,37 +31,51 @@ def _build_process(connector_cls: type[Connector]) -> LocalProcess:
2331
connector_cls(spec=ConnectorSpec(source="comp_a.out_1", target="comp_b1.in_1")),
2432
connector_cls(spec=ConnectorSpec(source="comp_b1.out_1", target="comp_b2.in_1")),
2533
]
26-
return LocalProcess(components=components, connectors=connectors)
34+
return process_cls(components=components, connectors=connectors)
2735

2836

29-
@pytest.mark.benchmark
3037
@pytest.mark.parametrize(
31-
"connector_cls",
32-
[AsyncioConnector, ZMQConnector],
33-
ids=["asyncio", "zmq"],
38+
"connector_cls, process_cls",
39+
CONNECTOR_PROCESS_PARAMS,
40+
ids=CONNECTOR_PROCESS_IDS,
3441
)
35-
def test_benchmark_process_run(connector_cls: type[Connector]) -> None:
36-
"""Benchmark the init and run of a Plugboard Process."""
42+
def test_benchmark_process_run(
43+
benchmark: BenchmarkFixture,
44+
connector_cls: type[Connector],
45+
process_cls: type[Process],
46+
ray_ctx: None,
47+
) -> None:
48+
"""Benchmark running of a Plugboard Process."""
3749

38-
async def _run() -> None:
39-
process = _build_process(connector_cls)
40-
await process.init()
41-
await process.run()
50+
def _setup() -> tuple[tuple[Process], dict]:
51+
async def _init() -> Process:
52+
process = _build_process(connector_cls, process_cls)
53+
await process.init()
54+
return process
55+
56+
return (asyncio.run(_init()),), {}
57+
58+
def _run(process: Process) -> None:
59+
asyncio.run(process.run())
4260

43-
asyncio.run(_run())
61+
benchmark.pedantic(_run, setup=_setup, rounds=5)
4462

4563

4664
@pytest.mark.benchmark
4765
@pytest.mark.parametrize(
48-
"connector_cls",
49-
[AsyncioConnector, ZMQConnector],
50-
ids=["asyncio", "zmq"],
66+
"connector_cls, process_cls",
67+
CONNECTOR_PROCESS_PARAMS,
68+
ids=CONNECTOR_PROCESS_IDS,
5169
)
52-
def test_benchmark_process_lifecycle(connector_cls: type[Connector]) -> None:
70+
def test_benchmark_process_lifecycle(
71+
connector_cls: type[Connector],
72+
process_cls: type[Process],
73+
ray_ctx: None,
74+
) -> None:
5375
"""Benchmark the full lifecycle (init, run, destroy) of a Plugboard Process."""
5476

5577
async def _lifecycle() -> None:
56-
process = _build_process(connector_cls)
78+
process = _build_process(connector_cls, process_cls)
5779
await process.init()
5880
await process.run()
5981
await process.destroy()

0 commit comments

Comments
 (0)