Files
cleveragents-core/benchmarks/a2a_facade_bench.py
T
freemo ec0b7631d0
CI / lint (push) Successful in 12s
CI / build (push) Successful in 15s
CI / quality (push) Successful in 23s
CI / typecheck (push) Successful in 36s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 46s
CI / unit_tests (push) Successful in 3m3s
CI / integration_tests (push) Successful in 3m31s
CI / docker (push) Successful in 40s
CI / coverage (push) Successful in 5m34s
CI / benchmark-publish (push) Successful in 19m15s
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 13s
CI / build (pull_request) Successful in 14s
CI / quality (pull_request) Successful in 17s
CI / security (pull_request) Successful in 34s
CI / typecheck (pull_request) Has been cancelled
CI / unit_tests (pull_request) Has been cancelled
CI / coverage (pull_request) Has been cancelled
CI / benchmark-regression (pull_request) Has been cancelled
CI / integration_tests (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
refactor(a2a): rename ACP module and symbols to A2A standard
Renamed src/cleveragents/acp/ to src/cleveragents/a2a/ and all 13
Acp* classes to A2a* per ADR-047 (A2A Standard Adoption). Updated
all imports, structlog event names (acp.* → a2a.*), field names
(acp_version → a2a_version), and test references across the entire
codebase. This is a cosmetic rename only — no behavioral changes.

ISSUES CLOSED: #688
2026-03-12 14:38:57 +00:00

125 lines
3.7 KiB
Python

"""ASV benchmarks for A2A facade dispatch, version negotiation, and event queue.
Measures the performance of:
- A2aLocalFacade dispatch overhead per operation
- A2aVersionNegotiator negotiation throughput
- A2aEventQueue publish and get_events throughput
"""
from __future__ import annotations
import importlib
import sys
from pathlib import Path
# Ensure the local *source* tree is importable even when ASV has an
# older build of the package installed.
_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
sys.path.insert(0, _SRC)
# Force-reload so ASV picks up the source tree version.
import cleveragents # noqa: E402
importlib.reload(cleveragents)
from cleveragents.a2a.events import A2aEventQueue # noqa: E402
from cleveragents.a2a.facade import A2aLocalFacade # noqa: E402
from cleveragents.a2a.models import A2aEvent, A2aRequest # noqa: E402
from cleveragents.a2a.versioning import A2aVersionNegotiator # noqa: E402
# ---------------------------------------------------------------------------
# Facade dispatch benchmarks
# ---------------------------------------------------------------------------
class FacadeDispatchSuite:
"""Benchmark A2aLocalFacade.dispatch() overhead."""
timeout = 60
def setup(self) -> None:
self.facade = A2aLocalFacade()
self.session_req = A2aRequest(operation="session.create")
self.plan_req = A2aRequest(
operation="plan.execute", params={"plan_id": "BENCH001"}
)
self.context_req = A2aRequest(operation="context.get")
def time_dispatch_session_create(self) -> None:
self.facade.dispatch(self.session_req)
def time_dispatch_plan_execute(self) -> None:
self.facade.dispatch(self.plan_req)
def time_dispatch_context_get(self) -> None:
self.facade.dispatch(self.context_req)
def time_dispatch_all_operations(self) -> None:
for op in self.facade.list_operations():
req = A2aRequest(operation=op)
self.facade.dispatch(req)
def time_list_operations(self) -> None:
self.facade.list_operations()
# ---------------------------------------------------------------------------
# Version negotiation benchmarks
# ---------------------------------------------------------------------------
class VersionNegotiationSuite:
"""Benchmark A2aVersionNegotiator throughput."""
timeout = 60
def setup(self) -> None:
self.negotiator = A2aVersionNegotiator()
def time_negotiate_supported(self) -> None:
self.negotiator.negotiate("1.0")
def time_is_supported_true(self) -> None:
self.negotiator.is_supported("1.0")
def time_is_supported_false(self) -> None:
self.negotiator.is_supported("99.0")
def time_get_current(self) -> None:
self.negotiator.get_current()
# ---------------------------------------------------------------------------
# Event queue benchmarks
# ---------------------------------------------------------------------------
class EventQueueSuite:
"""Benchmark A2aEventQueue throughput."""
timeout = 60
def setup(self) -> None:
self.queue = A2aEventQueue()
self.event = A2aEvent(event_type="bench.event")
def time_publish_single(self) -> None:
self.queue.publish(self.event)
def time_publish_100(self) -> None:
for _ in range(100):
self.queue.publish(self.event)
def time_get_events_default(self) -> None:
self.queue.get_events()
def time_subscribe_local(self) -> None:
self.queue.subscribe_local(lambda e: None)
def time_publish_with_subscriber(self) -> None:
q = A2aEventQueue()
q.subscribe_local(lambda e: None)
for _ in range(100):
q.publish(self.event)