Better naming/logging for send side bwe (#3264)

* Better naming/logging for send side bwe

* Check BWE congestion state before doing optimal allocation.

It is possible that BWE declares congestion, but the estimated bandwidth
may still be enough to accommodate all tracks. So, stream allocator
would still not in DEFICIENT state. On a new track allocation, it will
get optimal allocation although BWE is in congested state.

Take BWE congestion state into consideration before doing any track
allocation.

* get congestion state from BWE rather than caching it in stream allocator

* get states from update

* log contributing groups only when they are small in number

* get oldest group always

* notify only when estimate is dropping

* require stronger CTR down trend

* maintain min/max group

* relax thresholds to declare congestion a bit
This commit is contained in:
Raja Subramanian
2024-12-18 21:38:13 +05:30
committed by GitHub
parent 90804c553e
commit b6e99e249b
8 changed files with 177 additions and 132 deletions
+3 -1
View File
@@ -85,6 +85,8 @@ type BWE interface {
UpdateRTT(rtt float64) UpdateRTT(rtt float64)
CongestionState() CongestionState
CanProbe() bool CanProbe() bool
ProbeDuration() time.Duration ProbeDuration() time.Duration
ProbeClusterStarting(pci ccutils.ProbeClusterInfo) ProbeClusterStarting(pci ccutils.ProbeClusterInfo)
@@ -96,7 +98,7 @@ type BWE interface {
// ------------------------------------------------ // ------------------------------------------------
type BWEListener interface { type BWEListener interface {
OnCongestionStateChange(congestionState CongestionState, estimatedAvailableChannelCapacity int64) OnCongestionStateChange(fromState CongestionState, toState CongestionState, estimatedAvailableChannelCapacity int64)
} }
// ------------------------------------------------ // ------------------------------------------------
+4
View File
@@ -50,6 +50,10 @@ func (n *NullBWE) HandleTWCCFeedback(_report *rtcp.TransportLayerCC) {}
func (n *NullBWE) UpdateRTT(rtt float64) {} func (n *NullBWE) UpdateRTT(rtt float64) {}
func (n *NullBWE) CongestionState() CongestionState {
return CongestionStateNone
}
func (n *NullBWE) CanProbe() bool { func (n *NullBWE) CanProbe() bool {
return false return false
} }
+23 -13
View File
@@ -137,12 +137,12 @@ func (r *RemoteBWE) HandleREMB(
r.channelObserver.AddEstimate(r.lastReceivedEstimate) r.channelObserver.AddEstimate(r.lastReceivedEstimate)
r.channelObserver.AddNack(sentPackets, repeatedNacks) r.channelObserver.AddNack(sentPackets, repeatedNacks)
shouldNotify, state, committedChannelCapacity := r.congestionDetectionStateMachine() shouldNotify, fromState, toState, committedChannelCapacity := r.congestionDetectionStateMachine()
r.lock.Unlock() r.lock.Unlock()
if shouldNotify { if shouldNotify {
if bweListener := r.getBWEListener(); bweListener != nil { if bweListener := r.getBWEListener(); bweListener != nil {
bweListener.OnCongestionStateChange(state, committedChannelCapacity) bweListener.OnCongestionStateChange(fromState, toState, committedChannelCapacity)
} }
} }
} }
@@ -154,18 +154,19 @@ func (r *RemoteBWE) UpdateRTT(rtt float64) {
r.probeController.UpdateRTT(rtt) r.probeController.UpdateRTT(rtt)
} }
func (r *RemoteBWE) congestionDetectionStateMachine() (bool, bwe.CongestionState, int64) { func (r *RemoteBWE) congestionDetectionStateMachine() (bool, bwe.CongestionState, bwe.CongestionState, int64) {
newState := r.congestionState fromState := r.congestionState
toState := r.congestionState
update := false update := false
trend, reason := r.channelObserver.GetTrend() trend, reason := r.channelObserver.GetTrend()
switch r.congestionState { switch fromState {
case bwe.CongestionStateNone: case bwe.CongestionStateNone:
if trend == channelTrendCongesting { if trend == channelTrendCongesting {
if r.probeController.IsInProbe() || r.estimateAvailableChannelCapacity(reason) { if r.probeController.IsInProbe() || r.estimateAvailableChannelCapacity(reason) {
// when in probe, if congested, stays there till probe is done, // when in probe, if congested, stays there till probe is done,
// the estimate stays at pre-probe level // the estimate stays at pre-probe level
newState = bwe.CongestionStateCongested toState = bwe.CongestionStateCongested
} }
} }
@@ -176,26 +177,26 @@ func (r *RemoteBWE) congestionDetectionStateMachine() (bool, bwe.CongestionState
update = true update = true
} }
} else { } else {
newState = bwe.CongestionStateCongestedHangover toState = bwe.CongestionStateCongestedHangover
} }
case bwe.CongestionStateCongestedHangover: case bwe.CongestionStateCongestedHangover:
if trend == channelTrendCongesting { if trend == channelTrendCongesting {
if r.estimateAvailableChannelCapacity(reason) { if r.estimateAvailableChannelCapacity(reason) {
newState = bwe.CongestionStateCongested toState = bwe.CongestionStateCongested
} }
} else if time.Since(r.congestionStateSwitchedAt) >= r.params.Config.CongestedHangoverDuration { } else if time.Since(r.congestionStateSwitchedAt) >= r.params.Config.CongestedHangoverDuration {
newState = bwe.CongestionStateNone toState = bwe.CongestionStateNone
} }
} }
shouldNotify := false shouldNotify := false
if newState != r.congestionState || update { if toState != fromState || update {
r.updateCongestionState(newState, reason) fromState, toState = r.updateCongestionState(toState, reason)
shouldNotify = true shouldNotify = true
} }
return shouldNotify, r.congestionState, r.committedChannelCapacity return shouldNotify, fromState, toState, r.committedChannelCapacity
} }
func (r *RemoteBWE) estimateAvailableChannelCapacity(reason channelCongestionReason) bool { func (r *RemoteBWE) estimateAvailableChannelCapacity(reason channelCongestionReason) bool {
@@ -229,7 +230,7 @@ func (r *RemoteBWE) estimateAvailableChannelCapacity(reason channelCongestionRea
return true return true
} }
func (r *RemoteBWE) updateCongestionState(state bwe.CongestionState, reason channelCongestionReason) { func (r *RemoteBWE) updateCongestionState(state bwe.CongestionState, reason channelCongestionReason) (bwe.CongestionState, bwe.CongestionState) {
r.params.Logger.Infow( r.params.Logger.Infow(
"remote bwe: congestion state change", "remote bwe: congestion state change",
"from", r.congestionState, "from", r.congestionState,
@@ -238,8 +239,17 @@ func (r *RemoteBWE) updateCongestionState(state bwe.CongestionState, reason chan
"committedChannelCapacity", r.committedChannelCapacity, "committedChannelCapacity", r.committedChannelCapacity,
) )
fromState := r.congestionState
r.congestionState = state r.congestionState = state
r.congestionStateSwitchedAt = mono.Now() r.congestionStateSwitchedAt = mono.Now()
return fromState, r.congestionState
}
func (r *RemoteBWE) CongestionState() bwe.CongestionState {
r.lock.Lock()
defer r.lock.Unlock()
return r.congestionState
} }
func (r *RemoteBWE) CanProbe() bool { func (r *RemoteBWE) CanProbe() bool {
+91 -67
View File
@@ -40,23 +40,23 @@ func (c CongestionSignalConfig) IsTriggered(numGroups int, duration int64) bool
var ( var (
defaultQueuingDelayEarlyWarningCongestionSignalConfig = CongestionSignalConfig{ defaultQueuingDelayEarlyWarningCongestionSignalConfig = CongestionSignalConfig{
MinNumberOfGroups: 1, MinNumberOfGroups: 2,
MinDuration: 100 * time.Millisecond, MinDuration: 200 * time.Millisecond,
} }
defaultLossEarlyWarningCongestionSignalConfig = CongestionSignalConfig{ defaultLossEarlyWarningCongestionSignalConfig = CongestionSignalConfig{
MinNumberOfGroups: 2,
MinDuration: 300 * time.Millisecond,
}
defaultQueuingDelayCongestedCongestionSignalConfig = CongestionSignalConfig{
MinNumberOfGroups: 3, MinNumberOfGroups: 3,
MinDuration: 300 * time.Millisecond, MinDuration: 300 * time.Millisecond,
} }
defaultQueuingDelayCongestedCongestionSignalConfig = CongestionSignalConfig{
MinNumberOfGroups: 4,
MinDuration: 400 * time.Millisecond,
}
defaultLossCongestedCongestionSignalConfig = CongestionSignalConfig{ defaultLossCongestedCongestionSignalConfig = CongestionSignalConfig{
MinNumberOfGroups: 6, MinNumberOfGroups: 6,
MinDuration: 900 * time.Millisecond, MinDuration: 600 * time.Millisecond,
} }
) )
@@ -141,11 +141,13 @@ type qdMeasurement struct {
dqrMax int64 dqrMax int64
numGroups int numGroups int
numJQRGroups int
minSendTime int64 minSendTime int64
maxSendTime int64 maxSendTime int64
isSealed bool isSealed bool
sealedGroupIdx int minGroupIdx int
maxGroupIdx int
queuingRegion queuingRegion queuingRegion queuingRegion
} }
@@ -169,16 +171,21 @@ func (q *qdMeasurement) ProcessPacketGroup(pg *packetGroup, groupIdx int) {
return return
} }
q.numGroups++
if q.minGroupIdx == 0 || q.minGroupIdx > groupIdx {
groupIdx = q.minGroupIdx
}
q.maxGroupIdx = max(q.maxGroupIdx, groupIdx)
if pqd < q.dqrMax { if pqd < q.dqrMax {
// a DQR breaks continuity // a DQR breaks continuity
q.isSealed = true q.isSealed = true
q.sealedGroupIdx = groupIdx
q.queuingRegion = queuingRegionDQR q.queuingRegion = queuingRegionDQR
return return
} }
if pqd > q.jqrMin { if pqd > q.jqrMin {
q.numGroups++ q.numJQRGroups++
minSendTime, maxSendTime := pg.SendWindow() minSendTime, maxSendTime := pg.SendWindow()
if q.minSendTime == 0 || minSendTime < q.minSendTime { if q.minSendTime == 0 || minSendTime < q.minSendTime {
q.minSendTime = minSendTime q.minSendTime = minSendTime
@@ -186,9 +193,8 @@ func (q *qdMeasurement) ProcessPacketGroup(pg *packetGroup, groupIdx int) {
q.maxSendTime = max(q.maxSendTime, maxSendTime) q.maxSendTime = max(q.maxSendTime, maxSendTime)
} }
if q.config.IsTriggered(q.numGroups, q.maxSendTime-q.minSendTime) { if q.config.IsTriggered(q.numJQRGroups, q.maxSendTime-q.minSendTime) {
q.isSealed = true q.isSealed = true
q.sealedGroupIdx = groupIdx
q.queuingRegion = queuingRegionJQR q.queuingRegion = queuingRegionJQR
} }
} }
@@ -197,8 +203,8 @@ func (q *qdMeasurement) IsSealed() bool {
return q.isSealed return q.isSealed
} }
func (q *qdMeasurement) Result() (queuingRegion, int) { func (q *qdMeasurement) Result() (queuingRegion, int, int) {
return q.queuingRegion, q.sealedGroupIdx return q.queuingRegion, q.minGroupIdx, q.maxGroupIdx
} }
func (q *qdMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error { func (q *qdMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
@@ -207,11 +213,13 @@ func (q *qdMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
} }
e.AddInt("numGroups", q.numGroups) e.AddInt("numGroups", q.numGroups)
e.AddInt("numJQRGroups", q.numJQRGroups)
e.AddInt64("minSendTime", q.minSendTime) e.AddInt64("minSendTime", q.minSendTime)
e.AddInt64("maxSendTime", q.maxSendTime) e.AddInt64("maxSendTime", q.maxSendTime)
e.AddDuration("duration", time.Duration((q.maxSendTime-q.minSendTime)*1000)) e.AddDuration("duration", time.Duration((q.maxSendTime-q.minSendTime)*1000))
e.AddBool("isSealed", q.isSealed) e.AddBool("isSealed", q.isSealed)
e.AddInt("sealedGroupIdx", q.sealedGroupIdx) e.AddInt("minGroupIdx", q.minGroupIdx)
e.AddInt("maxGroupIdx", q.maxGroupIdx)
e.AddString("queuingRegion", q.queuingRegion.String()) e.AddString("queuingRegion", q.queuingRegion.String())
return nil return nil
} }
@@ -227,7 +235,8 @@ type lossMeasurement struct {
ts *trafficStats ts *trafficStats
isSealed bool isSealed bool
sealedGroupIdx int minGroupIdx int
maxGroupIdx int
weightedLoss float64 weightedLoss float64
@@ -259,12 +268,16 @@ func (l *lossMeasurement) ProcessPacketGroup(pg *packetGroup, groupIdx int) {
} }
l.numGroups++ l.numGroups++
if l.minGroupIdx == 0 || l.minGroupIdx > groupIdx {
groupIdx = l.minGroupIdx
}
l.maxGroupIdx = max(l.maxGroupIdx, groupIdx)
l.ts.Merge(pg.Traffic()) l.ts.Merge(pg.Traffic())
duration := l.ts.Duration() duration := l.ts.Duration()
if l.config.IsTriggered(l.numGroups, duration) { if l.config.IsTriggered(l.numGroups, duration) {
l.isSealed = true l.isSealed = true
l.sealedGroupIdx = groupIdx
l.weightedLoss = l.ts.WeightedLoss() l.weightedLoss = l.ts.WeightedLoss()
if l.weightedLoss < l.dqrMaxLoss { if l.weightedLoss < l.dqrMaxLoss {
@@ -279,8 +292,8 @@ func (l *lossMeasurement) IsSealed() bool {
return l.isSealed return l.isSealed
} }
func (l *lossMeasurement) Result() (queuingRegion, int) { func (l *lossMeasurement) Result() (queuingRegion, int, int) {
return l.queuingRegion, l.sealedGroupIdx return l.queuingRegion, l.minGroupIdx, l.maxGroupIdx
} }
func (l *lossMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error { func (l *lossMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
@@ -291,7 +304,8 @@ func (l *lossMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
e.AddInt("numGroups", l.numGroups) e.AddInt("numGroups", l.numGroups)
e.AddObject("ts", l.ts) e.AddObject("ts", l.ts)
e.AddBool("isSealed", l.isSealed) e.AddBool("isSealed", l.isSealed)
e.AddInt("sealedGroupIdx", l.sealedGroupIdx) e.AddInt("minGroupIdx", l.minGroupIdx)
e.AddInt("maxGroupIdx", l.maxGroupIdx)
e.AddFloat64("weightedLoss", l.weightedLoss) e.AddFloat64("weightedLoss", l.weightedLoss)
e.AddString("queuingRegion", l.queuingRegion.String()) e.AddString("queuingRegion", l.queuingRegion.String())
return nil return nil
@@ -331,7 +345,7 @@ var (
defaultTrendDetectorConfigCongestedCTR = ccutils.TrendDetectorConfig{ defaultTrendDetectorConfigCongestedCTR = ccutils.TrendDetectorConfig{
RequiredSamples: 4, RequiredSamples: 4,
RequiredSamplesMin: 2, RequiredSamplesMin: 2,
DownwardTrendThreshold: -0.5, DownwardTrendThreshold: -0.7,
DownwardTrendMaxWait: 2 * time.Second, DownwardTrendMaxWait: 2 * time.Second,
CollapseThreshold: 500 * time.Millisecond, CollapseThreshold: 500 * time.Millisecond,
ValidityWindow: 10 * time.Second, ValidityWindow: 10 * time.Second,
@@ -583,12 +597,12 @@ func (c *congestionDetector) HandleTWCCFeedback(report *rtcp.TransportLayerCC) {
} }
c.prunePacketGroups() c.prunePacketGroups()
shouldNotify, state, committedChannelCapacity := c.congestionDetectionStateMachine() shouldNotify, fromState, toState, committedChannelCapacity := c.congestionDetectionStateMachine()
c.lock.Unlock() c.lock.Unlock()
if shouldNotify { if shouldNotify {
if bweListener := c.getBWEListener(); bweListener != nil { if bweListener := c.getBWEListener(); bweListener != nil {
bweListener.OnCongestionStateChange(state, committedChannelCapacity) bweListener.OnCongestionStateChange(fromState, toState, committedChannelCapacity)
} }
} }
} }
@@ -608,6 +622,13 @@ func (c *congestionDetector) UpdateRTT(rtt float64) {
} }
} }
func (c *congestionDetector) CongestionState() bwe.CongestionState {
c.lock.Lock()
defer c.lock.Unlock()
return c.congestionState
}
func (c *congestionDetector) CanProbe() bool { func (c *congestionDetector) CanProbe() bool {
c.lock.Lock() c.lock.Lock()
defer c.lock.Unlock() defer c.lock.Unlock()
@@ -718,7 +739,7 @@ func (c *congestionDetector) getCongestionSignal(
stage string, stage string,
qdConfig CongestionSignalConfig, qdConfig CongestionSignalConfig,
lossConfig CongestionSignalConfig, lossConfig CongestionSignalConfig,
) (queuingRegion, string, int) { ) (queuingRegion, string, int, int) {
qdMeasurement := newQdMeasurement( qdMeasurement := newQdMeasurement(
qdConfig, qdConfig,
c.params.Config.JQRMinDelay.Microseconds(), c.params.Config.JQRMinDelay.Microseconds(),
@@ -744,24 +765,21 @@ func (c *congestionDetector) getCongestionSignal(
} }
} }
oldestContributingGroup := max(0, idx)
reason := "" reason := ""
qr, groupIdx := qdMeasurement.Result() qr, minGroupIdx, maxGroupIdx := qdMeasurement.Result()
if qr == queuingRegionJQR { if qr == queuingRegionJQR {
reason = "queuing-delay" reason = "queuing-delay"
oldestContributingGroup = groupIdx
} else { } else {
qr, groupIdx = lossMeasurement.Result() qr, minGroupIdx, maxGroupIdx = lossMeasurement.Result()
if qr == queuingRegionJQR { if qr == queuingRegionJQR {
reason = "loss" reason = "loss"
oldestContributingGroup = groupIdx
} }
} }
return qr, reason, oldestContributingGroup return qr, reason, max(0, minGroupIdx), max(0, maxGroupIdx)
} }
func (c *congestionDetector) getEarlyWarningSignal() (queuingRegion, string, int) { func (c *congestionDetector) getEarlyWarningSignal() (queuingRegion, string, int, int) {
return c.getCongestionSignal( return c.getCongestionSignal(
"early-warning", "early-warning",
c.params.Config.QueuingDelayEarlyWarning, c.params.Config.QueuingDelayEarlyWarning,
@@ -769,7 +787,7 @@ func (c *congestionDetector) getEarlyWarningSignal() (queuingRegion, string, int
) )
} }
func (c *congestionDetector) getCongestedSignal() (queuingRegion, string, int) { func (c *congestionDetector) getCongestedSignal() (queuingRegion, string, int, int) {
return c.getCongestionSignal( return c.getCongestionSignal(
"congested", "congested",
c.params.Config.QueuingDelayCongested, c.params.Config.QueuingDelayCongested,
@@ -777,72 +795,70 @@ func (c *congestionDetector) getCongestedSignal() (queuingRegion, string, int) {
) )
} }
func (c *congestionDetector) congestionDetectionStateMachine() (bool, bwe.CongestionState, int64) { func (c *congestionDetector) congestionDetectionStateMachine() (bool, bwe.CongestionState, bwe.CongestionState, int64) {
state := c.congestionState fromState := c.congestionState
newState := c.congestionState toState := c.congestionState
var ( var (
qr queuingRegion qr queuingRegion
reason string reason string
oldestContributingGroup int minGroupIdx, maxGroupIdx int
) )
switch state { switch fromState {
case bwe.CongestionStateNone: case bwe.CongestionStateNone:
qr, reason, oldestContributingGroup = c.getEarlyWarningSignal() qr, reason, minGroupIdx, maxGroupIdx = c.getEarlyWarningSignal()
if qr == queuingRegionJQR { if qr == queuingRegionJQR {
newState = bwe.CongestionStateEarlyWarning toState = bwe.CongestionStateEarlyWarning
} }
case bwe.CongestionStateEarlyWarning: case bwe.CongestionStateEarlyWarning:
qr, reason, oldestContributingGroup = c.getCongestedSignal() qr, reason, minGroupIdx, maxGroupIdx = c.getCongestedSignal()
if qr == queuingRegionJQR { if qr == queuingRegionJQR {
newState = bwe.CongestionStateCongested toState = bwe.CongestionStateCongested
} else { } else {
qr, _, _ := c.getEarlyWarningSignal() qr, reason, minGroupIdx, maxGroupIdx = c.getEarlyWarningSignal()
if qr == queuingRegionDQR { if qr == queuingRegionDQR {
newState = bwe.CongestionStateEarlyWarningHangover toState = bwe.CongestionStateEarlyWarningHangover
} }
} }
case bwe.CongestionStateEarlyWarningHangover: case bwe.CongestionStateEarlyWarningHangover:
qr, reason, oldestContributingGroup = c.getEarlyWarningSignal() qr, reason, minGroupIdx, maxGroupIdx = c.getEarlyWarningSignal()
if qr == queuingRegionJQR { if qr == queuingRegionJQR {
newState = bwe.CongestionStateEarlyWarning toState = bwe.CongestionStateEarlyWarning
} else if time.Since(c.congestionStateSwitchedAt) >= c.params.Config.EarlyWarningHangover { } else if time.Since(c.congestionStateSwitchedAt) >= c.params.Config.EarlyWarningHangover {
newState = bwe.CongestionStateNone toState = bwe.CongestionStateNone
} }
case bwe.CongestionStateCongested: case bwe.CongestionStateCongested:
qr, _, _ = c.getCongestedSignal() qr, reason, minGroupIdx, maxGroupIdx = c.getCongestedSignal()
if qr == queuingRegionDQR { if qr == queuingRegionDQR {
newState = bwe.CongestionStateCongestedHangover toState = bwe.CongestionStateCongestedHangover
} }
case bwe.CongestionStateCongestedHangover: case bwe.CongestionStateCongestedHangover:
qr, reason, oldestContributingGroup = c.getEarlyWarningSignal() qr, reason, minGroupIdx, maxGroupIdx = c.getEarlyWarningSignal()
if qr == queuingRegionJQR { if qr == queuingRegionJQR {
newState = bwe.CongestionStateEarlyWarning toState = bwe.CongestionStateEarlyWarning
} else if time.Since(c.congestionStateSwitchedAt) >= c.params.Config.CongestedHangover { } else if time.Since(c.congestionStateSwitchedAt) >= c.params.Config.CongestedHangover {
newState = bwe.CongestionStateNone toState = bwe.CongestionStateNone
} }
} }
c.estimateAvailableChannelCapacity(oldestContributingGroup) c.estimateAvailableChannelCapacity(minGroupIdx)
// update after running the above estimate as state change callback includes the estimated available channel capacity // update after running the above estimate as state change callback includes the estimated available channel capacity
shouldNotify := false shouldNotify := false
if newState != state { if toState != fromState {
c.updateCongestionState(newState, reason, oldestContributingGroup) fromState, toState = c.updateCongestionState(toState, reason, minGroupIdx, maxGroupIdx)
shouldNotify = true shouldNotify = true
} }
if c.congestedCTRTrend != nil && c.congestedCTRTrend.GetDirection() == ccutils.TrendDirectionDownward { if c.congestedCTRTrend != nil && c.congestedCTRTrend.GetDirection() == ccutils.TrendDirectionDownward {
shouldNotify = true
congestedAckedBitrate := c.congestedTrafficStats.AcknowledgedBitrate() congestedAckedBitrate := c.congestedTrafficStats.AcknowledgedBitrate()
if congestedAckedBitrate < c.estimatedAvailableChannelCapacity { if congestedAckedBitrate < c.estimatedAvailableChannelCapacity {
c.estimatedAvailableChannelCapacity = congestedAckedBitrate c.estimatedAvailableChannelCapacity = congestedAckedBitrate
}
c.params.Logger.Infow( c.params.Logger.Infow(
"send side bwe: captured traffic ratio is trending downward", "send side bwe: captured traffic ratio is trending downward",
"channel", c.congestedCTRTrend, "channel", c.congestedCTRTrend,
@@ -850,11 +866,14 @@ func (c *congestionDetector) congestionDetectionStateMachine() (bool, bwe.Conges
"estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity, "estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity,
) )
shouldNotify = true
}
// reset to get new set of samples for next trend // reset to get new set of samples for next trend
c.resetCTRTrend() c.resetCTRTrend()
} }
return shouldNotify, c.congestionState, c.estimatedAvailableChannelCapacity return shouldNotify, fromState, toState, c.estimatedAvailableChannelCapacity
} }
func (c *congestionDetector) createCTRTrend() { func (c *congestionDetector) createCTRTrend() {
@@ -943,23 +962,26 @@ func (c *congestionDetector) estimateAvailableChannelCapacity(oldestContributing
c.estimatedAvailableChannelCapacity = agg.AcknowledgedBitrate() c.estimatedAvailableChannelCapacity = agg.AcknowledgedBitrate()
} }
func (c *congestionDetector) updateCongestionState(state bwe.CongestionState, reason string, oldestContributingGroup int) { func (c *congestionDetector) updateCongestionState(state bwe.CongestionState, reason string, minGroupIdx int, maxGroupIdx int) (bwe.CongestionState, bwe.CongestionState) {
c.params.Logger.Infow( loggingFields := []any{
"send side bwe: congestion state change",
"from", c.congestionState, "from", c.congestionState,
"to", state, "to", state,
"reason", reason, "reason", reason,
"numPacketGroups", len(c.packetGroups), "numPacketGroups", len(c.packetGroups),
"numContributingGroups", len(c.packetGroups[oldestContributingGroup:]), "minGroupIdx", minGroupIdx,
"contributingGroups", logger.ObjectSlice(c.packetGroups[oldestContributingGroup:]), "maxGroupIdx", maxGroupIdx,
"estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity, "estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity,
) }
if state == bwe.CongestionStateEarlyWarning || state == bwe.CongestionStateCongested {
loggingFields = append(loggingFields, "contributingGroups", logger.ObjectSlice(c.packetGroups[minGroupIdx:maxGroupIdx+1]))
}
c.params.Logger.Infow("send side bwe: congestion state change", loggingFields...)
if state != c.congestionState { if state != c.congestionState {
c.congestionStateSwitchedAt = mono.Now() c.congestionStateSwitchedAt = mono.Now()
} }
prevState := c.congestionState fromState := c.congestionState
c.congestionState = state c.congestionState = state
// when in congested state, monitor changes in captured traffic ratio (CTR) // when in congested state, monitor changes in captured traffic ratio (CTR)
@@ -968,9 +990,11 @@ func (c *congestionDetector) updateCongestionState(state bwe.CongestionState, re
// sub-optimal and not enough to reduce/relieve congestion, by monitoing CTR // sub-optimal and not enough to reduce/relieve congestion, by monitoing CTR
// on a continuous basis allocations can be adjusted in the direction of // on a continuous basis allocations can be adjusted in the direction of
// reducing/relieving congestion // reducing/relieving congestion
if state == bwe.CongestionStateCongested && prevState != bwe.CongestionStateCongested { if state == bwe.CongestionStateCongested && fromState != bwe.CongestionStateCongested {
c.createCTRTrend() c.createCTRTrend()
} else if state != bwe.CongestionStateCongested { } else if state != bwe.CongestionStateCongested {
c.clearCTRTrend() c.clearCTRTrend()
} }
return fromState, c.congestionState
} }
+7 -7
View File
@@ -39,7 +39,7 @@ type PacketGroupConfig struct {
var ( var (
defaultPacketGroupConfig = PacketGroupConfig{ defaultPacketGroupConfig = PacketGroupConfig{
MinPackets: 20, MinPackets: 30,
MaxWindowDuration: 500 * time.Millisecond, MaxWindowDuration: 500 * time.Millisecond,
} }
) )
@@ -144,15 +144,15 @@ type packetGroup struct {
aggregateSendDelta int64 aggregateSendDelta int64
aggregateRecvDelta int64 aggregateRecvDelta int64
queuingDelay int64 inheritedQueuingDelay int64
isFinalized bool isFinalized bool
} }
func newPacketGroup(params packetGroupParams, queuingDelay int64) *packetGroup { func newPacketGroup(params packetGroupParams, inheritedQueuingDelay int64) *packetGroup {
return &packetGroup{ return &packetGroup{
params: params, params: params,
queuingDelay: queuingDelay, inheritedQueuingDelay: inheritedQueuingDelay,
snBitmap: utils.NewBitmap[uint64](params.Config.MinPackets), snBitmap: utils.NewBitmap[uint64](params.Config.MinPackets),
} }
} }
@@ -231,8 +231,8 @@ func (p *packetGroup) SendWindow() (int64, int64) {
} }
func (p *packetGroup) PropagatedQueuingDelay() int64 { func (p *packetGroup) PropagatedQueuingDelay() int64 {
if p.queuingDelay+p.aggregateRecvDelta-p.aggregateSendDelta > 0 { if p.inheritedQueuingDelay+p.aggregateRecvDelta-p.aggregateSendDelta > 0 {
return p.queuingDelay + p.aggregateRecvDelta - p.aggregateSendDelta return p.inheritedQueuingDelay + p.aggregateRecvDelta - p.aggregateSendDelta
} }
return max(0, p.aggregateRecvDelta-p.aggregateSendDelta) return max(0, p.aggregateRecvDelta-p.aggregateSendDelta)
@@ -290,7 +290,7 @@ func (p *packetGroup) MarshalLogObject(e zapcore.ObjectEncoder) error {
}) })
ts.Merge(p.Traffic()) ts.Merge(p.Traffic())
e.AddObject("trafficStats", ts) e.AddObject("trafficStats", ts)
e.AddInt64("queuingDelay", p.queuingDelay) e.AddInt64("inheritedQueuingDelay", p.inheritedQueuingDelay)
e.AddInt64("propagatedQueuingDelay", p.PropagatedQueuingDelay()) e.AddInt64("propagatedQueuingDelay", p.PropagatedQueuingDelay())
e.AddBool("isFinalized", p.isFinalized) e.AddBool("isFinalized", p.isFinalized)
+4
View File
@@ -114,6 +114,10 @@ func (s *SendSideBWE) UpdateRTT(rtt float64) {
s.congestionDetector.UpdateRTT(rtt) s.congestionDetector.UpdateRTT(rtt)
} }
func (s *SendSideBWE) CongestionState() bwe.CongestionState {
return s.congestionDetector.CongestionState()
}
func (s *SendSideBWE) CanProbe() bool { func (s *SendSideBWE) CanProbe() bool {
return s.congestionDetector.CanProbe() return s.congestionDetector.CanProbe()
} }
+2 -2
View File
@@ -32,8 +32,8 @@ type WeightedLossConfig struct {
var ( var (
defaultWeightedLossConfig = WeightedLossConfig{ defaultWeightedLossConfig = WeightedLossConfig{
MinDurationForLossValidity: 200 * time.Millisecond, MinDurationForLossValidity: 250 * time.Millisecond,
MinPPSForLossValidity: 20, MinPPSForLossValidity: 30,
LossPenaltyFactor: 0.25, LossPenaltyFactor: 0.25,
} }
) )
+20 -19
View File
@@ -206,7 +206,7 @@ type StreamAllocator struct {
rembTrackingSSRC uint32 rembTrackingSSRC uint32
state streamAllocatorState state streamAllocatorState
isHolding bool
activeProbeClusterId ccutils.ProbeClusterId activeProbeClusterId ccutils.ProbeClusterId
activeProbeGoalReached bool activeProbeGoalReached bool
activeProbeCongesting bool activeProbeCongesting bool
@@ -454,15 +454,16 @@ func (s *StreamAllocator) onTargetBitrateChange(bitrate int) {
// called when congestion state changes (send side bandwidth estimation) // called when congestion state changes (send side bandwidth estimation)
type congestionStateChangeData struct { type congestionStateChangeData struct {
congestionState bwe.CongestionState fromState bwe.CongestionState
toState bwe.CongestionState
estimatedAvailableChannelCapacity int64 estimatedAvailableChannelCapacity int64
} }
// BWEListener implementation // BWEListener implementation
func (s *StreamAllocator) OnCongestionStateChange(congestionState bwe.CongestionState, estimatedAvailableChannelCapacity int64) { func (s *StreamAllocator) OnCongestionStateChange(fromState bwe.CongestionState, toState bwe.CongestionState, estimatedAvailableChannelCapacity int64) {
s.postEvent(Event{ s.postEvent(Event{
Signal: streamAllocatorSignalCongestionStateChange, Signal: streamAllocatorSignalCongestionStateChange,
Data: congestionStateChangeData{congestionState, estimatedAvailableChannelCapacity}, Data: congestionStateChangeData{fromState, toState, estimatedAvailableChannelCapacity},
}) })
} }
@@ -828,20 +829,14 @@ func (s *StreamAllocator) handleSignalSetChannelCapacity(event Event) {
func (s *StreamAllocator) handleSignalCongestionStateChange(event Event) { func (s *StreamAllocator) handleSignalCongestionStateChange(event Event) {
cscd := event.Data.(congestionStateChangeData) cscd := event.Data.(congestionStateChangeData)
if cscd.congestionState != bwe.CongestionStateNone { if cscd.toState != bwe.CongestionStateNone {
// end/abort any running probe if channel is not clear // end/abort any running probe if channel is not clear
s.maybeStopProbe() s.maybeStopProbe()
} }
if cscd.congestionState == bwe.CongestionStateEarlyWarning ||
cscd.congestionState == bwe.CongestionStateEarlyWarningHangover {
s.isHolding = true
} else {
// early warning is done and hold has been released,
// if there is no congestion, allocate all tracks optimally as
// some tracks may have been held at sub-optimal allocation // some tracks may have been held at sub-optimal allocation
// during early warning hold // during early warning hold (if there was one)
if s.isHolding && cscd.congestionState == bwe.CongestionStateNone && s.state == streamAllocatorStateStable { if isHoldableCongestionState(cscd.fromState) && cscd.toState == bwe.CongestionStateNone && s.state == streamAllocatorStateStable {
update := NewStreamStateUpdate() update := NewStreamStateUpdate()
for _, track := range s.getTracks() { for _, track := range s.getTracks() {
allocation := track.AllocateOptimal(FlagAllowOvershootWhileOptimal, false) allocation := track.AllocateOptimal(FlagAllowOvershootWhileOptimal, false)
@@ -850,10 +845,7 @@ func (s *StreamAllocator) handleSignalCongestionStateChange(event Event) {
s.maybeSendUpdate(update) s.maybeSendUpdate(update)
} }
s.isHolding = false if cscd.toState == bwe.CongestionStateCongested {
}
if cscd.congestionState == bwe.CongestionStateCongested {
if s.activeProbeClusterId != ccutils.ProbeClusterIdInvalid { if s.activeProbeClusterId != ccutils.ProbeClusterIdInvalid {
if !s.activeProbeCongesting { if !s.activeProbeCongesting {
s.activeProbeCongesting = true s.activeProbeCongesting = true
@@ -910,9 +902,10 @@ func (s *StreamAllocator) allocateTrack(track *Track) {
s.maybeStopProbe() s.maybeStopProbe()
// if not deficient, free pass allocate track // if not deficient, free pass allocate track
if !s.enabled || s.state == streamAllocatorStateStable || !track.IsManaged() { bweCongestionState := s.params.BWE.CongestionState()
if !s.enabled || (s.state == streamAllocatorStateStable && !isDeficientCongestionState(bweCongestionState)) || !track.IsManaged() {
update := NewStreamStateUpdate() update := NewStreamStateUpdate()
allocation := track.AllocateOptimal(FlagAllowOvershootWhileOptimal, s.isHolding) allocation := track.AllocateOptimal(FlagAllowOvershootWhileOptimal, isHoldableCongestionState(bweCongestionState))
updateStreamStateChange(track, allocation, update) updateStreamStateChange(track, allocation, update)
s.maybeSendUpdate(update) s.maybeSendUpdate(update)
return return
@@ -1445,4 +1438,12 @@ func updateStreamStateChange(track *Track, allocation sfu.VideoAllocation, updat
} }
} }
func isHoldableCongestionState(bweCongestionState bwe.CongestionState) bool {
return bweCongestionState == bwe.CongestionStateEarlyWarning || bweCongestionState == bwe.CongestionStateEarlyWarningHangover
}
func isDeficientCongestionState(bweCongestionState bwe.CongestionState) bool {
return bweCongestionState == bwe.CongestionStateCongested || bweCongestionState == bwe.CongestionStateCongestedHangover
}
// ------------------------------------------------ // ------------------------------------------------