From e75b73af52c9c89d7be98a5fc4a2dda35ae36534 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sat, 15 Apr 2023 13:07:47 +0530 Subject: [PATCH] Use last received if lower. (#1616) When detecting congestion based on loss, it is possible that the loss based signal triggers earlier and the estimate based signal is lagging. In those cases, check against last received estimate and if that is lower than loss based throttling, use that. Without this, it was possible that the current usage high. Loss based throttling may not dial things back far enough to pause the stream. Ideally, congestion should hit again and it should be dialled down further and eventually pause, but there are situations it never dials back far enough to pause. --- pkg/sfu/streamallocator/channelobserver.go | 27 ++++++++-------------- pkg/sfu/streamallocator/streamallocator.go | 8 +++++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pkg/sfu/streamallocator/channelobserver.go b/pkg/sfu/streamallocator/channelobserver.go index f19bbb69..dcef36f3 100644 --- a/pkg/sfu/streamallocator/channelobserver.go +++ b/pkg/sfu/streamallocator/channelobserver.go @@ -148,29 +148,17 @@ func (c *ChannelObserver) GetNackRatio() (uint32, uint32, float64) { func (c *ChannelObserver) GetTrend() (ChannelTrend, ChannelCongestionReason) { estimateDirection := c.estimateTrend.GetDirection() - packets, repeatedNacks, nackRatio := c.GetNackRatio() + _, _, nackRatio := c.GetNackRatio() switch { case estimateDirection == TrendDirectionDownward: - c.logger.Debugw( - "stream allocator: channel observer: estimate is trending downward", - "name", c.params.Name, - "estimate", c.estimateTrend.ToString(), - "packets", packets, - "repeatedNacks", repeatedNacks, - "ratio", nackRatio, - ) + c.logger.Debugw( "stream allocator: channel observer: estimate is trending downward", "channel", c.ToString()) return ChannelTrendCongesting, ChannelCongestionReasonEstimate + case c.params.NackWindowMinDuration != 0 && !c.nackWindowStartTime.IsZero() && time.Since(c.nackWindowStartTime) > c.params.NackWindowMinDuration && nackRatio > c.params.NackRatioThreshold: - c.logger.Debugw( - "stream allocator: channel observer: high rate of repeated NACKs", - "name", c.params.Name, - "estimate", c.estimateTrend.ToString(), - "packets", packets, - "repeatedNacks", repeatedNacks, - "ratio", nackRatio, - ) + c.logger.Debugw( "stream allocator: channel observer: high rate of repeated NACKs", "channel", c.ToString()) return ChannelTrendCongesting, ChannelCongestionReasonLoss + case estimateDirection == TrendDirectionUpward: return ChannelTrendClearing, ChannelCongestionReasonNone } @@ -178,4 +166,9 @@ func (c *ChannelObserver) GetTrend() (ChannelTrend, ChannelCongestionReason) { return ChannelTrendNeutral, ChannelCongestionReasonNone } +func (c *ChannelObserver) ToString() string { + packets, repeatedNacks, nackRatio := c.GetNackRatio() + return fmt.Sprintf("name: %s, estimate: %s, packets: %d, repeatedNacks: %d, nackRatio: %f", c.params.Name, c.estimateTrend.ToString(), packets, repeatedNacks, nackRatio) +} + // ------------------------------------------------ diff --git a/pkg/sfu/streamallocator/streamallocator.go b/pkg/sfu/streamallocator/streamallocator.go index a65834ed..fdf6c335 100644 --- a/pkg/sfu/streamallocator/streamallocator.go +++ b/pkg/sfu/streamallocator/streamallocator.go @@ -785,6 +785,9 @@ func (s *StreamAllocator) handleNewEstimateInNonProbe() { switch reason { case ChannelCongestionReasonLoss: estimateToCommit = int64(float64(expectedBandwidthUsage) * (1.0 - NackRatioAttenuator*nackRatio)) + if estimateToCommit > s.lastReceivedEstimate { + estimateToCommit = s.lastReceivedEstimate + } default: estimateToCommit = s.lastReceivedEstimate } @@ -1156,6 +1159,10 @@ func (s *StreamAllocator) initProbe(probeRateBps int64) { s.probeEndTime = time.Time{} + channelState := "" + if s.channelObserver != nil { + channelState = s.channelObserver.ToString() + } s.channelObserver = s.newChannelObserverProbe() s.channelObserver.SeedEstimate(s.lastReceivedEstimate) @@ -1172,6 +1179,7 @@ func (s *StreamAllocator) initProbe(probeRateBps int64) { "current usage", expectedBandwidthUsage, "committed", s.committedChannelCapacity, "lastReceived", s.lastReceivedEstimate, + "channel", channelState, "probeRateBps", probeRateBps, "goalBps", s.probeGoalBps, )