replayer: restore optional max_inflight_sessions for backwards compat
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,7 @@ class ReplayConfig:
|
|||||||
request_timeout_s: float = 600.0
|
request_timeout_s: float = 600.0
|
||||||
request_limit: int | None = None
|
request_limit: int | None = None
|
||||||
model_name: str = "default"
|
model_name: str = "default"
|
||||||
|
max_inflight_sessions: int | None = None # cap on concurrent sessions; None = unlimited
|
||||||
|
|
||||||
|
|
||||||
def _build_prompt_token_ids(req: TraceRequest) -> list[int]:
|
def _build_prompt_token_ids(req: TraceRequest) -> list[int]:
|
||||||
@@ -215,21 +216,28 @@ async def _run_session(
|
|||||||
earliest_ts: float,
|
earliest_ts: float,
|
||||||
sweep_start: float,
|
sweep_start: float,
|
||||||
sink: IncrementalMetricSink,
|
sink: IncrementalMetricSink,
|
||||||
|
session_sem: asyncio.Semaphore | None = None,
|
||||||
) -> list[RequestMetrics]:
|
) -> list[RequestMetrics]:
|
||||||
for req in state.turns:
|
if session_sem is not None:
|
||||||
# Wait until this request's trace timestamp
|
await session_sem.acquire()
|
||||||
target_wall = (req.timestamp_s - earliest_ts)
|
try:
|
||||||
elapsed = time.perf_counter() - sweep_start
|
for req in state.turns:
|
||||||
if elapsed < target_wall:
|
# Wait until this request's trace timestamp
|
||||||
await asyncio.sleep(target_wall - elapsed)
|
target_wall = (req.timestamp_s - earliest_ts)
|
||||||
|
elapsed = time.perf_counter() - sweep_start
|
||||||
|
if elapsed < target_wall:
|
||||||
|
await asyncio.sleep(target_wall - elapsed)
|
||||||
|
|
||||||
token_ids = _build_prompt_token_ids(req)
|
token_ids = _build_prompt_token_ids(req)
|
||||||
metric = await _dispatch_request(
|
metric = await _dispatch_request(
|
||||||
client=client, config=config, req=req,
|
client=client, config=config, req=req,
|
||||||
prompt_token_ids=token_ids, sem=request_sem,
|
prompt_token_ids=token_ids, sem=request_sem,
|
||||||
)
|
)
|
||||||
state.metrics.append(metric)
|
state.metrics.append(metric)
|
||||||
await sink.append(metric)
|
await sink.append(metric)
|
||||||
|
finally:
|
||||||
|
if session_sem is not None:
|
||||||
|
session_sem.release()
|
||||||
|
|
||||||
return state.metrics
|
return state.metrics
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user