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:
@@ -23,6 +23,7 @@ type Subscriber struct {
|
||||
engine *engine.Engine
|
||||
logger *filelog.Logger
|
||||
onNewNode func(nodeID, sipGateway string) // вызывается при первой метрике от новой ноды
|
||||
onMetric func() // вызывается после каждой обработанной метрики
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
@@ -63,6 +64,11 @@ func (s *Subscriber) SetOnNewNode(fn func(nodeID, sipGateway string)) {
|
||||
s.onNewNode = fn
|
||||
}
|
||||
|
||||
// SetOnMetric устанавливает callback, вызываемый после каждой обработанной метрики.
|
||||
func (s *Subscriber) SetOnMetric(fn func()) {
|
||||
s.onMetric = fn
|
||||
}
|
||||
|
||||
// handleMetric — обработчик входящих сообщений NATS.
|
||||
func (s *Subscriber) handleMetric(msg *natsgo.Msg) {
|
||||
var metric models.NodeMetric
|
||||
@@ -86,6 +92,10 @@ func (s *Subscriber) handleMetric(msg *natsgo.Msg) {
|
||||
ns := s.engine.UpdateMetric(&metric)
|
||||
s.logger.Log(ns)
|
||||
|
||||
if s.onMetric != nil {
|
||||
s.onMetric()
|
||||
}
|
||||
|
||||
// Авто-создание balance-транка для новой ноды
|
||||
if isNew && metric.SIPGateway != "" && s.onNewNode != nil {
|
||||
s.onNewNode(metric.NodeID, metric.SIPGateway)
|
||||
|
||||
Reference in New Issue
Block a user