routing-architecture
БесплатноБез исполняемых скриптовНе проверенLiteLLM-RS Routing Architecture. Covers 7 routing strategies over immutable routing snapshots (ArcSwap) with atomic/DashMap state, health-aware deployment…
от majiayu000★ 124 звезды на GitHubОб этом скилле
Routing Architecture Guide
Overview
The router (src/core/router/) selects among deployments — concrete provider+model
pairs registered via Router::add_deployment / Router::set_model_list — using one of
7 strategies. There is no per-strategy router struct, no Router trait, and no
create_router factory: strategy dispatch is a match on the RoutingStrategy enum
calling free functions in src/core/router/strategy_impl.rs.
Key Design Principles
- Snapshot isolation: deployments, the model index, and aliases live in an immutable
RoutingSnapshot, published throughArcSwap(src/core/router/unified.rs:61,308). Readers load one generation lock-free; writers clone-modify-store under aparking_lot::Mutexthat only serializes writers (unified.rs:312,379-398). - Atomic deployment state: per-deployment runtime state (
DeploymentState) is plain atomics withRelaxedordering (deployment.rs:210-252); RoundRobin uses aDashMap<String, AtomicUsize>of per-model counters (unified.rs:321). - Health-aware: candidates are filtered by cooldown, health status, parallel limits, and RPM/TPM limits before a strategy picks among them.
- Fallback chains: the built-in execution path tries the model-keyed
Generalfallback list after retries are exhausted. Typed context-window, content-policy, and rate-limit lists require explicit caller lookup/wiring today.
Selection Flow
Entry point Router::select_deployment_lease (selection.rs:95) delegates to
select_deployment_matching (selection.rs:226). The real flow:
- Load the current snapshot; resolve model aliases via
resolve_model_name(maxMAX_ALIAS_HOPS = 16hops,unified.rs:26). - Look up the resolved model in
snapshot.model_indexto get candidateDeploymentIds. - One filter pass builds
Vec<RoutingContext>(strategy_impl.rs:17), skipping deployments that are in cooldown (is_in_cooldown), unhealthy (is_healthy), at theirmax_parallel_requestslimit, or at theirrpm_limit/tpm_limit(selection.rs:287-344). Each context copiesweight,priority,active_requests,tpm_current/tpm_limit,rpm_current/rpm_limit,avg_latency_us. Router::select_from_routing_contextsdispatches on the configured strategy (selection.rs:195-224):
match strategy {
RoutingStrategy::SimpleShuffle => strategy_impl::weighted_random_from_context(routing_contexts),
RoutingStrategy::LeastBusy => strategy_impl::least_busy_from_context(routing_contexts),
RoutingStrategy::UsageBased => strategy_impl::lowest_usage_from_context(routing_contexts),
RoutingStrategy::LatencyBased => strategy_impl::lowest_latency_from_context(routing_contexts),
RoutingStrategy::PriorityBased => strategy_impl::lowest_priority_from_context(routing_contexts),
RoutingStrategy::RateLimitAware => strategy_impl::rate_limit_aware_from_context(routing_contexts),
RoutingStrategy::RoundRobin => strategy_impl::round_robin_from_context(
model_name, routing_contexts, round_robin_counters),
}
- The winner is reserved by
try_reserve_deployment— an atomic increment ofactive_requests(CAS loop whenmax_parallel_requestsis set). If another caller wins the last slot, that candidate is removed from the contexts and selection retries (selection.rs:378-415). - Returns a
DeploymentLease; dropping it decrementsactive_requests(RAII release,selection.rs:64-70). The deprecated ID-returningselect_deploymentstill exists but converts the lease to an ID without release-on-drop.
Routing Strategies
Enum RoutingStrategy (src/core/router/config.rs:22-39) serializes as snake_case
(simple_shuffle, round_robin, least_busy, latency_based, priority_based,
usage_based, rate_limit_aware); PriorityBased also accepts the serde alias
"cost_based".
1. SimpleShuffle (runtime default)
Weighted random selection: draws a point in 0..total_weight and walks candidates until
the cumulative weight covers it; uniform random when total weight is 0
(weighted_random_from_context, strategy_impl.rs:56-85). Weights come from
DeploymentConfig.weight (default 1).
Use when: general traffic where deployments have different capacity.
2. RoundRobin (gateway YAML default)
Per-model counter in round_robin_counters: DashMap<String, AtomicUsize> cycles through
candidate order (round_robin_from_context, strategy_impl.rs:247-274). Note the
defaults diverge: GatewayRouterConfig defaults to round_robin
(src/config/models/router.rs:48-50) while runtime RouterConfig defaults to SimpleShuffle.
Use when: predictable distribution needed, debugging provider issues.
3. LeastBusy
Single pass for the fewest active_requests; ties are broken randomly with reservoir
sampling so equal-load deployments share traffic (least_busy_from_context,
strategy_impl.rs:88-116).
Use when: high concurr
Установить routing-architecture в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл routing-architecture?
LiteLLM-RS Routing Architecture. Covers 7 routing strategies over immutable routing snapshots (ArcSwap) with atomic/DashMap state, health-aware deployment selection with cooldown circuit breaker, model-keyed fallback chains, and load balancing. Use when selecting or tuning a routing strategy, or configuring failover, health checks, and load balancing.
Как установить скилл routing-architecture?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл routing-architecture запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic