feat: weighted random routing + mode switching + EWMA smoothing + stale eviction

- Weighted random routing (math/rand/v2 per-goroutine ChaCha8)
- PUT /api/route/mode for runtime mode switch (best / weighted_random)
- EWMA score smoothing (configurable smoothing_factor, default 0.3)
- Periodic stale node eviction (5 min threshold, 60s interval)
- Non-blocking WS broadcast (per-client buffered channel + writePump)
- Background rate limiter cleanup goroutine
- In-memory trunk gateway cache (zero disk I/O in hot path)
- Configurable load_avg multiplier (default 50.0, backward compat)
- UI mode indicator + admin Switch button in dashboard
- 42 tests: weighted random, mode switching, EWMA, eviction, API integration
This commit is contained in:
Maksim Totmin
2026-06-25 20:42:46 +07:00
parent ff037f9c1e
commit 938c9e9362
15 changed files with 1026 additions and 65 deletions
+1
View File
@@ -226,6 +226,7 @@ type BalancerInfo struct {
RouteTotal int64 `json:"route_total"`
RouteFallbacks int64 `json:"route_fallbacks"`
UptimeSec int64 `json:"uptime_sec"`
BalanceMode string `json:"balance_mode"`
}
// --- WebSocket ---