feat: production-grade routing cache + stale detection fixes

Three-tier routing cache (ESL global -> file -> HTTP) eliminates HTTP
from call path for 2500-5000 concurrent calls. Lua reads cached route
in ~0.1us instead of blocking on api:execute('curl', ...).

Engine fixes:
- recalcBestLocked now skips stale nodes (was 5 min bug -> now ~10-15s)
- PickNodeForCall action_type='node' checks staleness for consistency
- onMetric callback pushes cache on every metric (no ticker delay)

Config:
- stale_threshold_sec default 20 -> 10 (industry standard)
- contrib/ included in Makefile deploy target
- route.lua paths updated for /opt/pulse-lets-go
This commit is contained in:
Maksim Totmin
2026-06-25 22:23:16 +07:00
parent 54259e51b9
commit 110289a093
11 changed files with 266 additions and 86 deletions
+6
View File
@@ -139,8 +139,13 @@ func main() {
// 6. HTTP API
apiHandler = api.NewAPI(eng, cfgMgr, cfg.GetJWTSecret(), cfg.MonitoringAPIKey, sub.IsConnected, cfg)
apiHandler.SetRouteCachePath(filepath.Join(dataDir, "route_cache.json"))
apiHandler.RebuildTrunkCache() // первичное построение in-memory кэша gateway
sub.SetOnMetric(func() {
apiHandler.PushRouteCache()
})
// При эвикции stale-ноды — удаляем её balance-транк из trunks.json
eng.SetOnNodeEvicted(func(nodeID string) {
trunks, err := cfgMgr.ReadTrunks()
@@ -232,6 +237,7 @@ func main() {
go func() {
ticker := time.NewTicker(5 * time.Second)
for range ticker.C {
apiHandler.PushRouteCache()
if eslClient != nil && eslClient.IsConnected() {
if stats, err := eslClient.FetchFsStats(); err == nil {
apiHandler.UpdateFsStats(stats)