From b90ade81da4a797cff5fb912e9c75d99eddea4c1 Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Mon, 3 Jun 2024 15:12:53 +0800 Subject: [PATCH] add log for unexpected jitter (#2752) --- pkg/sfu/forwardstats.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/sfu/forwardstats.go b/pkg/sfu/forwardstats.go index 47c83f0d5..0924e199a 100644 --- a/pkg/sfu/forwardstats.go +++ b/pkg/sfu/forwardstats.go @@ -1,11 +1,13 @@ package sfu import ( + "fmt" "sync" "sync/atomic" "time" "github.com/livekit/livekit-server/pkg/telemetry/prometheus" + "github.com/livekit/protocol/logger" "github.com/livekit/protocol/utils" ) @@ -46,9 +48,17 @@ func (s *ForwardStats) Update(arrival, left time.Time) { func (s *ForwardStats) GetStats() (latency, jitter time.Duration) { s.lock.Lock() - defer s.lock.Unlock() w := s.latency.Summarize() - return time.Duration(w.Mean()), time.Duration(w.StdDev()) + s.lock.Unlock() + latency, jitter = time.Duration(w.Mean()), time.Duration(w.StdDev()) + // TODO: remove this check after debugging unexpected jitter issue + if jitter > 10*time.Second { + logger.Infow("unexpected forward jitter", + "jitter", jitter, + "stats", fmt.Sprintf("count %.2f, mean %.2f, stdDev %.2f", w.Count(), w.Mean(), w.StdDev()), + ) + } + return } func (s *ForwardStats) GetLastStats(duration time.Duration) (latency, jitter time.Duration) {