Fixes from probe controller refactor (#3222)
* Fixes from probe controller refactor * fmt * static check
This commit is contained in:
@@ -18,6 +18,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/ccutils"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
@@ -175,11 +177,9 @@ func (c *channelObserver) GetTrend() (channelTrend, channelCongestionReason) {
|
||||
|
||||
switch {
|
||||
case estimateDirection == ccutils.TrendDirectionDownward:
|
||||
c.logger.Debugw("remote bwe: channel observer: estimate is trending downward", "channel", c)
|
||||
return channelTrendCongesting, channelCongestionReasonEstimate
|
||||
|
||||
case c.nackTracker.IsTriggered():
|
||||
c.logger.Debugw("remote bwe: channel observer: high rate of repeated NACKs", "channel", c)
|
||||
return channelTrendCongesting, channelCongestionReasonLoss
|
||||
|
||||
case estimateDirection == ccutils.TrendDirectionUpward:
|
||||
@@ -189,8 +189,19 @@ func (c *channelObserver) GetTrend() (channelTrend, channelCongestionReason) {
|
||||
return channelTrendNeutral, channelCongestionReasonNone
|
||||
}
|
||||
|
||||
func (c *channelObserver) String() string {
|
||||
return fmt.Sprintf("name: %s, estimate: {%v}, nack {%v}", c.params.Name, c.estimateTrend, c.nackTracker)
|
||||
func (c *channelObserver) MarshalLogObject(e zapcore.ObjectEncoder) error {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
e.AddString("name", c.params.Name)
|
||||
e.AddString("estimate", c.estimateTrend.String())
|
||||
e.AddObject("nack", c.nackTracker)
|
||||
|
||||
channelTrend, channelCongestionReason := c.GetTrend()
|
||||
e.AddString("channelTrend", channelTrend.String())
|
||||
e.AddString("channelCongestionReason", channelCongestionReason.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
package remotebwe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
|
||||
@@ -116,14 +117,22 @@ func (n *nackTracker) IsTriggered() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (n *nackTracker) String() string {
|
||||
window := ""
|
||||
if !n.windowStartTime.IsZero() {
|
||||
now := time.Now()
|
||||
elapsed := now.Sub(n.windowStartTime).Seconds()
|
||||
window = fmt.Sprintf("t: %+v|%+v|%.2fs", n.windowStartTime.Format(time.UnixDate), now.Format(time.UnixDate), elapsed)
|
||||
func (n *nackTracker) MarshalLogObject(e zapcore.ObjectEncoder) error {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Sprintf("n: %s, %s, p: %d, rn: %d, rn/p: %.2f", n.params.Name, window, n.packets, n.repeatedNacks, n.GetRatio())
|
||||
|
||||
e.AddString("name", n.params.Name)
|
||||
if n.windowStartTime.IsZero() {
|
||||
e.AddString("window", "inactive")
|
||||
} else {
|
||||
e.AddTime("windowStartTime", n.windowStartTime)
|
||||
e.AddDuration("windowDuration", time.Since(n.windowStartTime))
|
||||
e.AddUint32("packets", n.packets)
|
||||
e.AddUint32("repeatedNacks", n.repeatedNacks)
|
||||
e.AddFloat64("nackRatio", n.GetRatio())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/* REMOTE-BWE-DATA
|
||||
|
||||
@@ -140,6 +140,10 @@ func (r *RemoteBWE) congestionDetectionStateMachine() (bool, bwe.CongestionState
|
||||
newState := r.congestionState
|
||||
update := false
|
||||
trend, reason := r.channelObserver.GetTrend()
|
||||
if trend == channelTrendCongesting {
|
||||
r.params.Logger.Debugw("remote bwe, channel congesting", "channel", r.channelObserver)
|
||||
}
|
||||
|
||||
switch r.congestionState {
|
||||
case bwe.CongestionStateNone:
|
||||
if trend == channelTrendCongesting {
|
||||
@@ -151,7 +155,7 @@ func (r *RemoteBWE) congestionDetectionStateMachine() (bool, bwe.CongestionState
|
||||
case bwe.CongestionStateCongested:
|
||||
if trend == channelTrendCongesting {
|
||||
if r.estimateAvailableChannelCapacity(reason) {
|
||||
// update state sa this needs to reset switch time to wait for congestion min duration again
|
||||
// update state as this needs to reset switch time to wait for congestion min duration again
|
||||
update = true
|
||||
}
|
||||
} else if time.Since(r.congestionStateSwitchedAt) >= r.params.Config.CongestedMinDuration {
|
||||
@@ -273,13 +277,24 @@ func (r *RemoteBWE) ProbeClusterDone(_pci ccutils.ProbeClusterInfo) (bool, int64
|
||||
pco := r.channelObserver
|
||||
r.channelObserver = r.newChannelObserverNonProbe()
|
||||
|
||||
r.params.Logger.Debugw(
|
||||
"remote bwe: probe done",
|
||||
"lastReceived", r.lastReceivedEstimate,
|
||||
"expectedBandwidthUsage", r.lastExpectedBandwidthUsage,
|
||||
"channel", pco,
|
||||
)
|
||||
|
||||
if !pco.HasEnoughEstimateSamples() {
|
||||
// cannot decide success/failure without enough data
|
||||
return false, pco.GetHighestEstimate()
|
||||
return false, r.committedChannelCapacity
|
||||
}
|
||||
|
||||
trend, _ := pco.GetTrend()
|
||||
return trend == channelTrendClearing, pco.GetHighestEstimate()
|
||||
highestEstimate := pco.GetHighestEstimate()
|
||||
if trend == channelTrendClearing && highestEstimate > r.committedChannelCapacity {
|
||||
r.committedChannelCapacity = highestEstimate
|
||||
}
|
||||
return trend == channelTrendClearing, r.committedChannelCapacity
|
||||
}
|
||||
|
||||
func (r *RemoteBWE) worker() {
|
||||
|
||||
Reference in New Issue
Block a user