Skip to content

routing: rank same-priority accounts by observed latency - #71

Merged
CMGS merged 3 commits into
mainfrom
feat/latency-routing-2
Sep 9, 2026
Merged

routing: rank same-priority accounts by observed latency#71
CMGS merged 3 commits into
mainfrom
feat/latency-routing-2

Conversation

@CMGS

@CMGS CMGS commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Re-cut of #70 on current main (that PR conflicted with #67 on the README pipeline bullet; pushed branches are never rewritten, so the commit was cherry-picked onto a fresh branch).

What

stability.latency_routing: true ranks the accounts of a priority tier by their observed call latency instead of round-robin. The ranker is an in-process EWMA (α = 0.2) of completed engine calls per account; an account never sampled or not sampled in the last 60 s ranks first, so new and idle accounts get probed and a slow one is re-checked once a minute; equal ranks fall back to round-robin through a rotating start. PTU preference, priority tiers, health cooldown and failover are unchanged; the realtime surface keeps round-robin. Each instance learns its own view (no fleet sharing).

Hot path

Off (default): nothing — the ranker is None and no sample is recorded. On: one DashMap write per successful call and one read per candidate at selection. A/B bench on cocoon-test1 in the PR comments.

Evidence

  • Unit: EWMA arithmetic, stale samples rank as unknown, a fast/slow pair always picks fast, round-robin without the ranker, a minute-old slow account is probed again, unknown accounts round-robin.
  • Live (from routing: rank same-priority accounts by observed latency #70's comment, same code): two direct accounts vs one through a +400 ms delay proxy, 30 requests — on: 26/3/1; off: 10/10/10.

CMGS added 3 commits September 9, 2026 11:41
stability.latency_routing ranks the accounts of a priority tier by an
in-process EWMA of their completed call latency instead of round-robin: the
fastest account takes the tier's traffic, an account never or not recently
(60 s) sampled ranks first so it gets probed, and equal ranks stay
round-robin. Samples are recorded on the engine's success path only while
the option is on, so the default pays nothing; the realtime surface keeps
round-robin. Each instance learns its own view.
@CMGS

CMGS commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

A/B bench (cocoon-test1, mock upstream, oha, c=256, 20 s per arm, arms interleaved with the order swapped each round)

main 2b8abd9 vs this branch, default config (latency_routing off), 5 rounds:

main     small256 209.7k / 209.5k / 209.5k / 209.5k / 215.5k rps   big256 158k / 182k / 157k / 201k / 174k   msgstream256 5.61k / 5.35k / 5.59k / 5.73k / 5.73k
latency  small256 216.1k / 218.0k / 220.4k / 216.2k / 216.7k rps   big256 150k / 191k / 194k / 197k / 158k   msgstream256 5.64k / 5.73k / 5.37k / 5.65k / 5.36k

This branch, latency_routing off vs on, 3 rounds:

off  small256 215.8k / 219.8k / 209.5k   big256 152k / 195k / 157k   msgstream256 5.64k / 5.41k / 5.56k
on   small256 218.2k / 212.5k / 209.5k   big256 166k / 163k / 172k   msgstream256 5.55k / 5.62k / 5.76k

big256 is bimodal on this host for every arm (150–200k, both main and branch, same as last night's runs), so it carries no signal; small256 and msgstream256 are flat within noise. No regression, on or off.

Linux gates (cocoon-test1): fmt clean, clippy 0, TOTAL passed 587 failed 0.

@CMGS
CMGS merged commit 12f712b into main Sep 9, 2026
2 checks passed
@CMGS
CMGS deleted the feat/latency-routing-2 branch September 9, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant