feat(routing): latency-aware target selection (least_latency strategy) - #682
Conversation
Add a `least_latency` routing strategy that ranks a routing model's targets fastest-first by an exponentially-weighted moving average (alpha 0.3) of recent observed upstream latency, and falls forward down the ranked order. Targets with no samples yet rank first so they get probed (explore, then exploit). The EWMA lives on the per-target RuntimeEntry in the runtime-status tracker, alongside the existing health/cooldown state, and is fed on each successful attempt from the routing dispatch loops of /v1/chat/completions (round-trip for non-streaming, time-to-first-response for streaming), /v1/messages, and /v1/responses. /v1/count_tokens is intentionally excluded — its latency is a token-count round-trip, not representative of inference latency, and would skew the signal; it still gets the ranking via the shared path. Reuses the metric-ordering framework from the least_cost strategy: the selection slots into resolve_attempt_models and inherits the existing retry / cooldown / health-filter / fallback machinery. Regenerated the committed resource schemas for the new enum variant.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 19 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Adds a
least_latencyrouting strategy: a routing model ranks its targets fastest-first by a moving average of recent observed upstream latency and falls forward down the ranked order. Targets with no samples yet rank first so they get probed (explore, then exploit).Why
No latency-aware selection existed — a gap vs LiteLLM (
lowest_latency) and Kong (lowest-latency). Second of the smart-routing strategies from the routing gap list (#873); aligns with #895 Phase 2 (the latency objective).How
Reuses the metric-ordering framework introduced by
least_cost(#681): the ranking runs in the sharedresolve_attempt_modelsand inherits the existing retry / cooldown / health-filter / fallback machinery.RuntimeEntryin the runtime-status tracker, next to the existing health/cooldown state. Fed on each successful attempt from the routing dispatch loops of/v1/chat/completions(round-trip for non-streaming, time-to-first-response for streaming),/v1/messages, and/v1/responses./v1/count_tokensis intentionally excluded from feeding the EWMA — its latency is a token-count round-trip, not representative of inference latency, and would skew the signal. It still gets the ranking via the shared path.Tests
is_metric_based, fastest-first ordering, unmeasured-targets-probed-first, EWMA math.latency-aware-routing-e2e.test.ts): a fast + a deliberately-slow (responseDelayMs) upstream declared slow-first; after warmup the strategy sends every request to the fast target.Notes
Regenerated the committed resource schemas (
schemas/resources/{routing,model}.schema.json). User-facing docs will ship as one consolidatedapi7/docsrouting-strategies page for the whole smart-routing family.Fixes api7/AISIX-Cloud#924
EOF