Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(e2e): event_loop_stalls charges a hold to the longest gc pass that fits it, not to the sum of every pass since the last hold (#47089)

Kerry Lu22e17b69faa8
diff --git a/tests/e2e/perf/cases/event_loop_stalls.py b/tests/e2e/perf/cases/event_loop_stalls.py
index 66c99686151..04424de2e8d 100644
--- a/tests/e2e/perf/cases/event_loop_stalls.py
+++ b/tests/e2e/perf/cases/event_loop_stalls.py
@@ -43,6 +43,7 @@ CASE: Final = replace(
KnownStall("RedisBatch.flush", max_count=2),
KnownStall("run_coroutine_job", max_count=2),
KnownStall("user_api_key_auth.py", max_count=2),
+ KnownStall("route_streaming_logging_to_handler", max_count=2),
),
),
)
diff --git a/tests/e2e/perf/setup/event_loop.py b/tests/e2e/perf/setup/event_loop.py
index 00d05c79f73..dee45c374d9 100644
--- a/tests/e2e/perf/setup/event_loop.py
+++ b/tests/e2e/perf/setup/event_loop.py
@@ -115,13 +115,11 @@ def _parse_event(line: str) -> Stall | GcPass | None:
def _with_passes(stall: Stall, passes: tuple[GcPass, ...]) -> Stall:
- if not passes:
+ fitting: Final = tuple(gc_pass for gc_pass in passes if gc_pass.seconds <= stall.seconds)
+ if not fitting:
return stall
- return replace(
- stall,
- gc_seconds=sum(gc_pass.seconds for gc_pass in passes),
- gc_generation=max(gc_pass.generation for gc_pass in passes),
- )
+ longest: Final = max(fitting, key=lambda gc_pass: gc_pass.seconds)
+ return replace(stall, gc_seconds=longest.seconds, gc_generation=longest.generation)
def parse_stalls(lines: Iterable[str]) -> tuple[Stall, ...]:
@@ -137,7 +135,7 @@ def parse_stalls(lines: Iterable[str]) -> tuple[Stall, ...]:
def _reported(spec: EventLoopStalls, stall: Stall) -> Stall:
"""A hold the collector accounts for, what is left under the threshold, is the collector's, not the task's."""
- if stall.gc_generation is None or stall.gc_seconds > stall.seconds:
+ if stall.gc_generation is None:
return stall
if stall.seconds - stall.gc_seconds >= spec.max_hold_seconds:
return stall
diff --git a/tests/e2e_harness/perf/setup/test_event_loop.py b/tests/e2e_harness/perf/setup/test_event_loop.py
index 4728003db7f..57868305716 100644
--- a/tests/e2e_harness/perf/setup/test_event_loop.py
+++ b/tests/e2e_harness/perf/setup/test_event_loop.py
@@ -78,6 +78,16 @@ def test_a_hold_well_past_its_collector_pass_stays_on_the_task() -> None:
assert [(row.coroutine, row.offending) for row in rows] == [("TaskHandle._run_coro()", True)]
+def test_a_hold_is_charged_to_the_longest_collector_pass_that_fits_it_not_to_their_sum() -> None:
+ thread_side_pass: Final = _GC_PASS.replace("0.711", "0.627")
+ rows: Final = summarize(
+ _SPEC, parse_stalls((thread_side_pass, _GC_PASS.replace("0.711", "0.605"), _STREAM.replace("0.412", "0.614")))
+ )
+ assert [(row.coroutine, row.where, row.max_seconds, row.offending) for row in rows] == [
+ ("garbage collection", "gen=2", 0.614, False)
+ ]
+
+
def test_a_collector_pass_explains_only_the_next_hold_and_only_one_at_least_as_long() -> None:
rows: Final = summarize(_SPEC, parse_stalls((_GC_PASS, _STARTUP, _HANDLER)))
assert sorted((row.coroutine, row.offending) for row in rows) == [