Prevent stats update if the deltas are empty (#619)

* Prevent stats update if the deltas are empty

* increase force interval

* static check

* Change max delay to 30 seconds
This commit is contained in:
Raja Subramanian
2022-04-18 22:51:34 +05:30
committed by GitHub
parent 2e9bccfeff
commit a19ca69f5f
3 changed files with 24 additions and 5 deletions
+3 -1
View File
@@ -26,7 +26,7 @@ const (
// expire participant mappings after a day // expire participant mappings after a day
participantMappingTTL = 24 * time.Hour participantMappingTTL = 24 * time.Hour
statsUpdateInterval = 2 * time.Second statsUpdateInterval = 2 * time.Second
statsMaxDelaySeconds = 10 statsMaxDelaySeconds = 30
) )
// RedisRouter uses Redis pub/sub to route signaling messages across different nodes // RedisRouter uses Redis pub/sub to route signaling messages across different nodes
@@ -483,8 +483,10 @@ func (r *RedisRouter) handleRTCMessage(rm *livekit.RTCNodeMessage) error {
if err != nil { if err != nil {
logger.Errorw("could not update node stats", err) logger.Errorw("could not update node stats", err)
} else { } else {
if updated != nil {
r.currentNode.Stats = updated r.currentNode.Stats = updated
} }
}
r.statsMu.Unlock() r.statsMu.Unlock()
// TODO: check stats against config.Limit values // TODO: check stats against config.Limit values
+5
View File
@@ -15,6 +15,11 @@ const AvailableSeconds = 5
// checks if a node has been updated recently to be considered for selection // checks if a node has been updated recently to be considered for selection
func IsAvailable(node *livekit.Node) bool { func IsAvailable(node *livekit.Node) bool {
if node.Stats == nil {
// available till stats are available
return true
}
delta := time.Now().Unix() - node.Stats.UpdatedAt delta := time.Now().Unix() - node.Stats.UpdatedAt
return int(delta) < AvailableSeconds return int(delta) < AvailableSeconds
} }
+13 -1
View File
@@ -10,7 +10,10 @@ import (
"github.com/livekit/protocol/utils" "github.com/livekit/protocol/utils"
) )
const livekitNamespace string = "livekit" const (
livekitNamespace string = "livekit"
forceUpdateInterval int64 = 15
)
var ( var (
MessageCounter *prometheus.CounterVec MessageCounter *prometheus.CounterVec
@@ -66,6 +69,15 @@ func GetUpdatedNodeStats(prev *livekit.NodeStats) (*livekit.NodeStats, error) {
packetsOutNow := packetsOut.Load() packetsOutNow := packetsOut.Load()
nackTotalNow := nackTotal.Load() nackTotalNow := nackTotal.Load()
if bytesInNow == prev.BytesIn &&
bytesOutNow == prev.BytesOut &&
packetsInNow == prev.PacketsIn &&
packetsOutNow == prev.PacketsOut &&
nackTotalNow == prev.NackTotal &&
elapsed < forceUpdateInterval {
return nil, nil
}
return &livekit.NodeStats{ return &livekit.NodeStats{
StartedAt: prev.StartedAt, StartedAt: prev.StartedAt,
UpdatedAt: updatedAt, UpdatedAt: updatedAt,