chore: initialize project repository
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
"""Repeatable local baseline for the in-process governance path."""
|
||||
import asyncio
|
||||
import statistics
|
||||
import time
|
||||
from dataclasses import dataclass, asdict
|
||||
|
||||
from app.core.contracts import AgentDefinition, AgentRequest, CoreResult, RequestContext
|
||||
from app.service.agent.base import BaseAgent
|
||||
|
||||
|
||||
class BenchmarkAgent(BaseAgent):
|
||||
async def handle(self, request: AgentRequest, context: RequestContext) -> CoreResult:
|
||||
del context
|
||||
return CoreResult(text=request.message)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Baseline:
|
||||
iterations: int
|
||||
p50_ms: float
|
||||
p95_ms: float
|
||||
max_ms: float
|
||||
|
||||
|
||||
async def run(iterations: int = 200) -> Baseline:
|
||||
agent = BenchmarkAgent(AgentDefinition(agent_type="benchmark", version="1"))
|
||||
request = AgentRequest(
|
||||
agent_type="benchmark", message="ping", session_id="benchmark",
|
||||
idempotency_key="benchmark-key-0001",
|
||||
)
|
||||
context = RequestContext(user_id="1", trace_id="benchmark")
|
||||
samples: list[float] = []
|
||||
for index in range(iterations):
|
||||
started = time.perf_counter()
|
||||
async for _ in agent.execute(request, context, f"run-{index}"):
|
||||
pass
|
||||
samples.append((time.perf_counter() - started) * 1000)
|
||||
ordered = sorted(samples)
|
||||
return Baseline(
|
||||
iterations=iterations,
|
||||
p50_ms=statistics.median(ordered),
|
||||
p95_ms=ordered[min(len(ordered) - 1, int(len(ordered) * 0.95))],
|
||||
max_ms=max(ordered),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(asdict(asyncio.run(run())))
|
||||
Reference in New Issue
Block a user