From 2a3035ca9babe5a0dd1aa385ce7f32526a163053 Mon Sep 17 00:00:00 2001 From: CMGS Date: Tue, 27 Oct 2026 10:06:51 +0800 Subject: [PATCH] perf: check an account's models concurrently in /internal/accounts Per-model health turned the view's one lookup per account into one per served model, awaited in sequence: 25 accounts and 102 models took 17.7 ms against a local Redis, 7.3 ms with each account's lookups joined. Also rewraps the HealthStore paragraph in architecture.md. --- crates/views/src/lib.rs | 32 ++++++++++++++++++++------------ docs/architecture.md | 6 +++--- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/crates/views/src/lib.rs b/crates/views/src/lib.rs index 31f030a..8ab4b9e 100644 --- a/crates/views/src/lib.rs +++ b/crates/views/src/lib.rs @@ -1321,18 +1321,26 @@ async fn accounts(State(s): State, _: GlobalAdmin) -> Response { let health = &s.handler.state().health; let mut data: Vec = Vec::with_capacity(cfg.accounts.len()); for a in &cfg.accounts { - let mut cooling = Vec::new(); - for m in cfg.models.iter().filter(|m| { - a.protocols.contains(&m.protocol) - && m.provider.as_deref().is_none_or(|p| p == a.provider) - }) { - if !health - .available(&gw_state::health_key(&a.name, &m.name)) - .await - { - cooling.push(m.name.as_str()); - } - } + let served: Vec<&str> = cfg + .models + .iter() + .filter(|m| { + a.protocols.contains(&m.protocol) + && m.provider.as_deref().is_none_or(|p| p == a.provider) + }) + .map(|m| m.name.as_str()) + .collect(); + let checks = futures::future::join_all( + served + .iter() + .map(|m| async move { health.available(&gw_state::health_key(&a.name, m)).await }), + ) + .await; + let cooling: Vec<&str> = served + .into_iter() + .zip(checks) + .filter_map(|(m, ok)| (!ok).then_some(m)) + .collect(); data.push(json!({ "name": a.name, "provider": a.provider, diff --git a/docs/architecture.md b/docs/architecture.md index ab4ec71..ce85d35 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -78,9 +78,9 @@ default, so the whole pipeline is testable offline: - **`HealthStore`** — account cooldown/recovery, per account and served model, so one model's refusals never bench the account for the others. In-process breaker by default; `RedisHealth` with `storage.redis_url` — a - tripped account is skipped for that model by every instance. Only upstream faults count (5xx, timeouts, - broken streams, a 401/402/403 credential or billing refusal), never a - client-caused or rate-limit error. + tripped account is skipped for that model by every instance. Only upstream + faults count (5xx, timeouts, broken streams, a 401/402/403 credential or + billing refusal), never a client-caused or rate-limit error. - **`Governance`** — rate/quota/TPM counters. In-process by default; `RedisGovernance` shares them (including pooled tenant QPS) fleet-wide. - **`Moderator`** — the external content review behind `security.moderate`;