Move Prober to ccutils. (#3175)

* keep track of RTX bytes separately

* packet group

* Packet group of 50ms

* Minor refactoring

* rate calculator

* send bit rate

* WIP

* comment

* reduce packet infos size

* extended twcc seq num

* fix packet info

* WIP

* queuing delay

* refactor

* config

* callbacks

* fixes

* clean up

* remove debug file, fix rate calculation

* fmt

* fix probes

* format

* notes

* check loss

* tweak detection settings

* 24-bit wrap

* clean up a bit

* limit symbol list to number of packets

* fmt

* clean up

* lost

* fixes

* fmt

* rename

* fixes

* fmt

* use min/max

* hold on early warning of congestion

* make note about need for all optimal allocation on hold release

* estimate trend in congested state

* tweaks

* quantized

* fmt

* TrendDetector generics

* CTR trend

* tweaks

* config

* config

* comments

* clean up

* consistent naming

* pariticpant level setting

* log usage mode

* probing hacks

* WIP

* no lock

* packet group config

* ctr trend refactor

* cleanup and fixes

* format

* debug

* format

* move prober to ccutils

* clean up

* clean up
This commit is contained in:
Raja Subramanian
2024-11-15 00:05:59 +05:30
committed by GitHub
parent 9e4dae7107
commit adaf56a30d
7 changed files with 166 additions and 112 deletions
@@ -117,7 +117,7 @@
// window being long(ish). But, RTT should be much shorter especially if // window being long(ish). But, RTT should be much shorter especially if
// the subscriber peer connection of the client is able to connect to // the subscriber peer connection of the client is able to connect to
// the nearest data center. // the nearest data center.
package streamallocator package ccutils
import ( import (
"fmt" "fmt"
+105 -59
View File
@@ -24,6 +24,7 @@ import (
"github.com/livekit/protocol/logger" "github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils/mono" "github.com/livekit/protocol/utils/mono"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"go.uber.org/zap/zapcore"
) )
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
@@ -33,6 +34,10 @@ type CongestionSignalConfig struct {
MinDuration time.Duration `yaml:"min_duration,omitempty"` MinDuration time.Duration `yaml:"min_duration,omitempty"`
} }
func (c CongestionSignalConfig) IsTriggered(numGroups int, duration int64) bool {
return numGroups >= c.MinNumberOfGroups && duration >= c.MinDuration.Microseconds()
}
var ( var (
DefaultQueuingDelayEarlyWarningCongestionSignalConfig = CongestionSignalConfig{ DefaultQueuingDelayEarlyWarningCongestionSignalConfig = CongestionSignalConfig{
MinNumberOfGroups: 1, MinNumberOfGroups: 1,
@@ -111,7 +116,7 @@ func (q *qdMeasurement) ProcessPacketGroup(pg *packetGroup) {
} }
// can seal if congested config thresholds are met as they are longer // can seal if congested config thresholds are met as they are longer
if q.numGroups >= q.congestedConfig.MinNumberOfGroups && (q.maxSendTime-q.minSendTime) >= q.congestedConfig.MinDuration.Microseconds() { if q.congestedConfig.IsTriggered(q.numGroups, q.maxSendTime-q.minSendTime) {
q.isSealed = true q.isSealed = true
} }
} }
@@ -121,11 +126,26 @@ func (q *qdMeasurement) IsSealed() bool {
} }
func (q *qdMeasurement) IsEarlyWarningTriggered() bool { func (q *qdMeasurement) IsEarlyWarningTriggered() bool {
return q.numGroups >= q.earlyWarningConfig.MinNumberOfGroups && (q.maxSendTime-q.minSendTime) >= q.earlyWarningConfig.MinDuration.Microseconds() return q.earlyWarningConfig.IsTriggered(q.numGroups, q.maxSendTime-q.minSendTime)
} }
func (q *qdMeasurement) IsCongestedTriggered() bool { func (q *qdMeasurement) IsCongestedTriggered() bool {
return q.numGroups >= q.congestedConfig.MinNumberOfGroups && (q.maxSendTime-q.minSendTime) >= q.congestedConfig.MinDuration.Microseconds() return q.congestedConfig.IsTriggered(q.numGroups, q.maxSendTime-q.minSendTime)
}
func (q *qdMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
if q == nil {
return nil
}
e.AddInt("numGroups", q.numGroups)
e.AddInt64("minSendTime", q.minSendTime)
e.AddInt64("maxSendTime", q.maxSendTime)
e.AddDuration("duration", time.Duration((q.maxSendTime-q.minSendTime)*1000))
e.AddBool("isSealed", q.isSealed)
e.AddBool("isEarlyWarningTriggered", q.IsEarlyWarningTriggered())
e.AddBool("isCongestedTriggered", q.IsCongestedTriggered())
return nil
} }
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
@@ -167,13 +187,14 @@ func (l *lossMeasurement) ProcessPacketGroup(pg *packetGroup) {
return return
} }
l.numGroups++
l.ts.Merge(pg.Traffic()) l.ts.Merge(pg.Traffic())
duration := l.ts.Duration() duration := l.ts.Duration()
if l.numGroups >= l.earlyWarningConfig.MinNumberOfGroups && duration >= l.earlyWarningConfig.MinDuration.Microseconds() { if l.earlyWarningConfig.IsTriggered(l.numGroups, duration) {
l.earlyWarningWeightedLoss = l.ts.WeightedLoss() l.earlyWarningWeightedLoss = l.ts.WeightedLoss()
} }
if l.numGroups >= l.congestedConfig.MinNumberOfGroups && duration >= l.congestedConfig.MinDuration.Microseconds() { if l.congestedConfig.IsTriggered(l.numGroups, duration) {
l.congestedWeightedLoss = l.ts.WeightedLoss() l.congestedWeightedLoss = l.ts.WeightedLoss()
l.isSealed = true // can seal if congested thresholds are satisfied as those should be higher l.isSealed = true // can seal if congested thresholds are satisfied as those should be higher
} }
@@ -191,6 +212,21 @@ func (l *lossMeasurement) IsCongestedTriggered() bool {
return l.congestedWeightedLoss > l.congestionMinLoss return l.congestedWeightedLoss > l.congestionMinLoss
} }
func (l *lossMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
if l == nil {
return nil
}
e.AddInt("numGroups", l.numGroups)
e.AddObject("ts", l.ts)
e.AddFloat64("earlyWarningWeightedLoss", l.earlyWarningWeightedLoss)
e.AddFloat64("congestedWeightedLoss", l.congestedWeightedLoss)
e.AddBool("isSealed", l.isSealed)
e.AddBool("isEarlyWarningTriggered", l.IsEarlyWarningTriggered())
e.AddBool("isCongestedTriggered", l.IsCongestedTriggered())
return nil
}
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
type CongestionDetectorConfig struct { type CongestionDetectorConfig struct {
@@ -232,7 +268,7 @@ var (
DefaultCongestionDetectorConfig = CongestionDetectorConfig{ DefaultCongestionDetectorConfig = CongestionDetectorConfig{
PacketGroup: DefaultPacketGroupConfig, PacketGroup: DefaultPacketGroupConfig,
PacketGroupMaxAge: 30 * time.Second, PacketGroupMaxAge: 15 * time.Second,
JQRMinDelay: 15 * time.Millisecond, JQRMinDelay: 15 * time.Millisecond,
DQRMaxDelay: 5 * time.Millisecond, DQRMaxDelay: 5 * time.Millisecond,
WeightedLoss: defaultWeightedLossConfig, WeightedLoss: defaultWeightedLossConfig,
@@ -327,6 +363,8 @@ func (c *congestionDetector) updateCongestionState(state CongestionState, reason
"from", c.congestionState, "from", c.congestionState,
"to", state, "to", state,
"reason", reason, "reason", reason,
"numPacketGroups", len(c.packetGroups),
"numContributingGroups", len(c.packetGroups[oldestContributingGroup:]),
"contributingGroups", logger.ObjectSlice(c.packetGroups[oldestContributingGroup:]), "contributingGroups", logger.ObjectSlice(c.packetGroups[oldestContributingGroup:]),
"estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity, "estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity,
) )
@@ -349,18 +387,9 @@ func (c *congestionDetector) updateCongestionState(state CongestionState, reason
// 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 == CongestionStateCongested && prevState != CongestionStateCongested { if state == CongestionStateCongested && prevState != CongestionStateCongested {
c.congestedCTRTrend = ccutils.NewTrendDetector[float64](ccutils.TrendDetectorParams{ c.resetCTRTrend()
Name: "ssbwe-ctr",
Logger: c.params.Logger,
Config: c.params.Config.CongestedCTRTrend,
})
c.congestedTrafficStats = newTrafficStats(trafficStatsParams{
Config: c.params.Config.WeightedLoss,
Logger: c.params.Logger,
})
} else if state != CongestionStateCongested { } else if state != CongestionStateCongested {
c.congestedCTRTrend = nil c.clearCTRTrend()
c.congestedTrafficStats = nil
} }
} }
@@ -388,11 +417,10 @@ func (c *congestionDetector) prunePacketGroups() {
return return
} }
bst := c.packetTracker.BaseSendTime() threshold, ok := c.packetTracker.BaseSendTimeThreshold(c.params.Config.PacketGroupMaxAge.Microseconds())
if bst == 0 { if !ok {
return return
} }
threshold := mono.UnixMicro() - bst - c.params.Config.PacketGroupMaxAge.Microseconds()
for idx, pg := range c.packetGroups { for idx, pg := range c.packetGroups {
if mst := pg.MinSendTime(); mst > threshold { if mst := pg.MinSendTime(); mst > threshold {
@@ -451,7 +479,7 @@ func (c *congestionDetector) isCongestionSignalTriggered() (bool, string, bool,
} }
} }
return earlyWarningTriggered, earlyWarningReason, congestedTriggered, congestedReason, idx return earlyWarningTriggered, earlyWarningReason, congestedTriggered, congestedReason, max(0, idx)
} }
func (c *congestionDetector) congestionDetectionStateMachine() { func (c *congestionDetector) congestionDetectionStateMachine() {
@@ -464,7 +492,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
switch state { switch state {
case CongestionStateNone: case CongestionStateNone:
if congestedTriggered { if congestedTriggered {
c.params.Logger.Warnw("invalid congested state transition", nil, "from", state) c.params.Logger.Warnw("invalid congested state transition", nil, "from", state, "reason", congestedReason)
} }
if earlyWarningTriggered { if earlyWarningTriggered {
newState = CongestionStateEarlyWarning newState = CongestionStateEarlyWarning
@@ -481,7 +509,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
case CongestionStateEarlyWarningHangover: case CongestionStateEarlyWarningHangover:
if congestedTriggered { if congestedTriggered {
c.params.Logger.Warnw("invalid congested state transition", nil, "from", state) c.params.Logger.Warnw("invalid congested state transition", nil, "from", state, "reason", congestedReason)
} }
if earlyWarningTriggered { if earlyWarningTriggered {
newState = CongestionStateEarlyWarning newState = CongestionStateEarlyWarning
@@ -497,7 +525,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
case CongestionStateCongestedHangover: case CongestionStateCongestedHangover:
if congestedTriggered { if congestedTriggered {
c.params.Logger.Warnw("invalid congested state transition", nil, "from", state) c.params.Logger.Warnw("invalid congested state transition", nil, "from", state, "reason", congestedReason)
} }
if earlyWarningTriggered { if earlyWarningTriggered {
newState = CongestionStateEarlyWarning newState = CongestionStateEarlyWarning
@@ -516,7 +544,24 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
} }
} }
func (c *congestionDetector) updateTrend(pg *packetGroup) { func (c *congestionDetector) resetCTRTrend() {
c.congestedCTRTrend = ccutils.NewTrendDetector[float64](ccutils.TrendDetectorParams{
Name: "ssbwe-ctr",
Logger: c.params.Logger,
Config: c.params.Config.CongestedCTRTrend,
})
c.congestedTrafficStats = newTrafficStats(trafficStatsParams{
Config: c.params.Config.WeightedLoss,
Logger: c.params.Logger,
})
}
func (c *congestionDetector) clearCTRTrend() {
c.congestedCTRTrend = nil
c.congestedTrafficStats = nil
}
func (c *congestionDetector) updateCTRTrend(pg *packetGroup) {
if c.congestedCTRTrend == nil { if c.congestedCTRTrend == nil {
return return
} }
@@ -529,30 +574,24 @@ func (c *congestionDetector) updateTrend(pg *packetGroup) {
// quantise CTR to filter out small changes // quantise CTR to filter out small changes
c.congestedCTRTrend.AddValue(float64(int((ctr+(c.params.Config.CongestedCTREpsilon/2))/c.params.Config.CongestedCTREpsilon)) * c.params.Config.CongestedCTREpsilon) c.congestedCTRTrend.AddValue(float64(int((ctr+(c.params.Config.CongestedCTREpsilon/2))/c.params.Config.CongestedCTREpsilon)) * c.params.Config.CongestedCTREpsilon)
if c.congestedCTRTrend.GetDirection() == ccutils.TrendDirectionDownward { if c.congestedCTRTrend.GetDirection() != ccutils.TrendDirectionDownward {
c.params.Logger.Infow("captured traffic ratio is trending downward", "channel", c.congestedCTRTrend.ToString()) return
c.lock.RLock()
state := c.congestionState
estimatedAvailableChannelCapacity := c.estimatedAvailableChannelCapacity
onCongestionStateChange := c.onCongestionStateChange
c.lock.RUnlock()
if onCongestionStateChange != nil {
onCongestionStateChange(state, estimatedAvailableChannelCapacity)
}
// reset to get new set of samples for next trend
c.congestedCTRTrend = ccutils.NewTrendDetector[float64](ccutils.TrendDetectorParams{
Name: "ssbwe-ctr",
Logger: c.params.Logger,
Config: c.params.Config.CongestedCTRTrend,
})
c.congestedTrafficStats = newTrafficStats(trafficStatsParams{
Config: c.params.Config.WeightedLoss,
Logger: c.params.Logger,
})
} }
c.params.Logger.Infow("captured traffic ratio is trending downward", "channel", c.congestedCTRTrend.ToString())
c.lock.RLock()
state := c.congestionState
estimatedAvailableChannelCapacity := c.estimatedAvailableChannelCapacity
onCongestionStateChange := c.onCongestionStateChange
c.lock.RUnlock()
if onCongestionStateChange != nil {
onCongestionStateChange(state, estimatedAvailableChannelCapacity)
}
// reset to get new set of samples for next trend
c.resetCTRTrend()
} }
func (c *congestionDetector) estimateAvailableChannelCapacity() { func (c *congestionDetector) estimateAvailableChannelCapacity() {
@@ -560,19 +599,19 @@ func (c *congestionDetector) estimateAvailableChannelCapacity() {
return return
} }
bst := c.packetTracker.BaseSendTime() threshold, ok := c.packetTracker.BaseSendTimeThreshold(c.params.Config.RateMeasurementWindowDurationMax.Microseconds())
if bst == 0 { if !ok {
return return
} }
threshold := mono.UnixMicro() - bst - c.params.Config.RateMeasurementWindowDurationMax.Microseconds()
agg := newTrafficStats(trafficStatsParams{ agg := newTrafficStats(trafficStatsParams{
Config: c.params.Config.WeightedLoss, Config: c.params.Config.WeightedLoss,
Logger: c.params.Logger, Logger: c.params.Logger,
}) })
for idx := len(c.packetGroups) - 1; idx >= 0; idx-- { var idx int
for idx = len(c.packetGroups) - 1; idx >= 0; idx-- {
pg := c.packetGroups[idx] pg := c.packetGroups[idx]
if pg.MinSendTime() < threshold { if mst := pg.MinSendTime(); mst != 0 && mst < threshold {
break break
} }
@@ -580,7 +619,12 @@ func (c *congestionDetector) estimateAvailableChannelCapacity() {
} }
if agg.Duration() < c.params.Config.RateMeasurementWindowDurationMin.Microseconds() { if agg.Duration() < c.params.Config.RateMeasurementWindowDurationMin.Microseconds() {
c.params.Logger.Infow("not enough data to estimate available channel capacity", "duration", agg.Duration()) c.params.Logger.Infow(
"not enough data to estimate available channel capacity",
"duration", agg.Duration(),
"numGroups", len(c.packetGroups),
"oldestUsed", max(0, idx),
)
return return
} }
@@ -600,8 +644,9 @@ func (c *congestionDetector) processFeedbackReport(fbr feedbackReport) {
c.packetGroups, c.packetGroups,
newPacketGroup( newPacketGroup(
packetGroupParams{ packetGroupParams{
Config: c.params.Config.PacketGroup, Config: c.params.Config.PacketGroup,
Logger: c.params.Logger, WeightedLoss: c.params.Config.WeightedLoss,
Logger: c.params.Logger,
}, },
0, 0,
), ),
@@ -621,14 +666,15 @@ func (c *congestionDetector) processFeedbackReport(fbr feedbackReport) {
if err == errGroupFinalized { if err == errGroupFinalized {
// previous group ended, start a new group // previous group ended, start a new group
c.updateTrend(pg) c.updateCTRTrend(pg)
// SSBWE-REMOVE c.params.Logger.Infow("packet group done", "group", pg, "numGroups", len(c.packetGroups)) // SSBWE-REMOVE // SSBWE-REMOVE c.params.Logger.Infow("packet group done", "group", pg, "numGroups", len(c.packetGroups)) // SSBWE-REMOVE
pqd, _ := pg.PropagatedQueuingDelay() pqd, _ := pg.PropagatedQueuingDelay()
pg = newPacketGroup( pg = newPacketGroup(
packetGroupParams{ packetGroupParams{
Config: c.params.Config.PacketGroup, Config: c.params.Config.PacketGroup,
Logger: c.params.Logger, WeightedLoss: c.params.Config.WeightedLoss,
Logger: c.params.Logger,
}, },
pqd, pqd,
) )
+4 -1
View File
@@ -221,7 +221,7 @@ func (p *packetGroup) MinSendTime() int64 {
} }
func (p *packetGroup) SendWindow() (int64, int64) { func (p *packetGroup) SendWindow() (int64, int64) {
return p.maxSendTime, p.minSendTime return p.minSendTime, p.maxSendTime
} }
func (p *packetGroup) PropagatedQueuingDelay() (int64, bool) { func (p *packetGroup) PropagatedQueuingDelay() (int64, bool) {
@@ -275,6 +275,9 @@ 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)
pqd, _ := p.PropagatedQueuingDelay()
e.AddInt64("propagatedQueuingDelay", pqd)
e.AddBool("isFinalized", p.isFinalized) e.AddBool("isFinalized", p.isFinalized)
return nil return nil
+7 -9
View File
@@ -15,18 +15,12 @@
package sendsidebwe package sendsidebwe
import ( import (
"errors"
"math/rand" "math/rand"
"sync" "sync"
"time" "time"
"github.com/livekit/protocol/logger" "github.com/livekit/protocol/logger"
) "github.com/livekit/protocol/utils/mono"
// -------------------------------------------------------------------------------
var (
errNoPacketInRange = errors.New("no packet in range")
) )
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
@@ -84,11 +78,15 @@ func (p *packetTracker) RecordPacketSendAndGetSequenceNumber(at time.Time, size
return uint16(pi.sequenceNumber) return uint16(pi.sequenceNumber)
} }
func (p *packetTracker) BaseSendTime() int64 { func (p *packetTracker) BaseSendTimeThreshold(threshold int64) (int64, bool) {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
return p.baseSendTime if p.baseSendTime == 0 {
return 0, false
}
return mono.UnixMicro() - p.baseSendTime - threshold, true
} }
func (p *packetTracker) RecordPacketIndicationFromRemote(sn uint16, recvTime int64) (piRecv packetInfo, sendDelta, recvDelta int64) { func (p *packetTracker) RecordPacketIndicationFromRemote(sn uint16, recvTime int64) (piRecv packetInfo, sendDelta, recvDelta int64) {
+1 -1
View File
@@ -62,7 +62,7 @@ func newTrafficStats(params trafficStatsParams) *trafficStats {
} }
func (ts *trafficStats) Merge(rhs *trafficStats) { func (ts *trafficStats) Merge(rhs *trafficStats) {
if rhs.minSendTime == 0 || rhs.minSendTime < ts.minSendTime { if ts.minSendTime == 0 || rhs.minSendTime < ts.minSendTime {
ts.minSendTime = rhs.minSendTime ts.minSendTime = rhs.minSendTime
} }
if rhs.maxSendTime > ts.maxSendTime { if rhs.maxSendTime > ts.maxSendTime {
+26 -25
View File
@@ -18,6 +18,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/livekit/livekit-server/pkg/sfu/ccutils"
"github.com/livekit/livekit-server/pkg/sfu/sendsidebwe" "github.com/livekit/livekit-server/pkg/sfu/sendsidebwe"
"github.com/livekit/protocol/logger" "github.com/livekit/protocol/logger"
) )
@@ -66,7 +67,7 @@ var (
type ProbeControllerParams struct { type ProbeControllerParams struct {
Config ProbeControllerConfig Config ProbeControllerConfig
Prober *Prober Prober *ccutils.Prober
Logger logger.Logger Logger logger.Logger
} }
@@ -78,10 +79,10 @@ type ProbeController struct {
probeInterval time.Duration probeInterval time.Duration
lastProbeStartTime time.Time lastProbeStartTime time.Time
probeGoalBps int64 probeGoalBps int64
probeClusterId ProbeClusterId probeClusterId ccutils.ProbeClusterId
doneProbeClusterInfo ProbeClusterInfo doneProbeClusterInfo ccutils.ProbeClusterInfo
abortedProbeClusterId ProbeClusterId abortedProbeClusterId ccutils.ProbeClusterId
goalReachedProbeClusterId ProbeClusterId goalReachedProbeClusterId ccutils.ProbeClusterId
probeTrendObserved bool probeTrendObserved bool
probeEndTime time.Time probeEndTime time.Time
probeDuration time.Duration probeDuration time.Duration
@@ -117,23 +118,24 @@ func (p *ProbeController) Reset() {
p.clearProbeLocked() p.clearProbeLocked()
} }
func (p *ProbeController) ProbeClusterDone(info ProbeClusterInfo) { func (p *ProbeController) ProbeClusterDone(info ccutils.ProbeClusterInfo) {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock()
if p.probeClusterId != info.Id { if p.probeClusterId != info.Id {
p.params.Logger.Debugw("not expected probe cluster", "probeClusterId", p.probeClusterId, "resetProbeClusterId", info.Id) p.params.Logger.Debugw("not expected probe cluster", "probeClusterId", p.probeClusterId, "resetProbeClusterId", info.Id)
p.lock.Unlock()
return return
} }
p.doneProbeClusterInfo = info p.doneProbeClusterInfo = info
p.lock.Unlock()
} }
func (p *ProbeController) CheckProbe(trend ChannelTrend, highestEstimate int64) { func (p *ProbeController) CheckProbe(trend ChannelTrend, highestEstimate int64) {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
if p.probeClusterId == ProbeClusterIdInvalid { if p.probeClusterId == ccutils.ProbeClusterIdInvalid {
return return
} }
@@ -181,15 +183,15 @@ func (p *ProbeController) MaybeFinalizeProbe(
return false, false, false return false, false, false
} }
if p.goalReachedProbeClusterId != ProbeClusterIdInvalid { if p.goalReachedProbeClusterId != ccutils.ProbeClusterIdInvalid {
// finalise goal reached probe cluster // finalise goal reached probe cluster
p.finalizeProbeLocked(ChannelTrendNeutral) p.finalizeProbeLocked(ChannelTrendNeutral)
return true, true, true return true, true, true
} }
if (isComplete || p.abortedProbeClusterId != ProbeClusterIdInvalid) && if (isComplete || p.abortedProbeClusterId != ccutils.ProbeClusterIdInvalid) &&
p.probeEndTime.IsZero() && p.probeEndTime.IsZero() &&
p.doneProbeClusterInfo.Id != ProbeClusterIdInvalid && p.doneProbeClusterInfo.Id == p.probeClusterId { p.doneProbeClusterInfo.Id != ccutils.ProbeClusterIdInvalid && p.doneProbeClusterInfo.Id == p.probeClusterId {
// ensure any queueing due to probing is flushed // ensure any queueing due to probing is flushed
// STREAM-ALLOCATOR-TODO: CongestionControlProbeConfig.SettleWait should actually be a certain number of RTTs. // STREAM-ALLOCATOR-TODO: CongestionControlProbeConfig.SettleWait should actually be a certain number of RTTs.
expectedDuration := float64(9.0) expectedDuration := float64(9.0)
@@ -227,7 +229,7 @@ func (p *ProbeController) DoesProbeNeedFinalize() bool {
p.lock.RLock() p.lock.RLock()
defer p.lock.RUnlock() defer p.lock.RUnlock()
return p.abortedProbeClusterId != ProbeClusterIdInvalid || p.goalReachedProbeClusterId != ProbeClusterIdInvalid return p.abortedProbeClusterId != ccutils.ProbeClusterIdInvalid || p.goalReachedProbeClusterId != ccutils.ProbeClusterIdInvalid
} }
func (p *ProbeController) finalizeProbeLocked(trend ChannelTrend) (isNotFailing bool) { func (p *ProbeController) finalizeProbeLocked(trend ChannelTrend) (isNotFailing bool) {
@@ -250,7 +252,7 @@ func (p *ProbeController) finalizeProbeLocked(trend ChannelTrend) (isNotFailing
return true return true
} }
func (p *ProbeController) InitProbe(probeGoalDeltaBps int64, expectedBandwidthUsage int64) (ProbeClusterId, int64) { func (p *ProbeController) InitProbe(probeGoalDeltaBps int64, expectedBandwidthUsage int64) (ccutils.ProbeClusterId, int64) {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
@@ -263,16 +265,16 @@ func (p *ProbeController) InitProbe(probeGoalDeltaBps int64, expectedBandwidthUs
} }
p.probeGoalBps = expectedBandwidthUsage + desiredIncreaseBps p.probeGoalBps = expectedBandwidthUsage + desiredIncreaseBps
p.doneProbeClusterInfo = ProbeClusterInfo{Id: ProbeClusterIdInvalid} p.doneProbeClusterInfo = ccutils.ProbeClusterInfo{Id: ccutils.ProbeClusterIdInvalid}
p.abortedProbeClusterId = ProbeClusterIdInvalid p.abortedProbeClusterId = ccutils.ProbeClusterIdInvalid
p.goalReachedProbeClusterId = ProbeClusterIdInvalid p.goalReachedProbeClusterId = ccutils.ProbeClusterIdInvalid
p.probeTrendObserved = false p.probeTrendObserved = false
p.probeEndTime = time.Time{} p.probeEndTime = time.Time{}
p.probeClusterId = p.params.Prober.AddCluster( p.probeClusterId = p.params.Prober.AddCluster(
ProbeClusterModeUniform, ccutils.ProbeClusterModeUniform,
int(p.probeGoalBps), int(p.probeGoalBps),
int(expectedBandwidthUsage), int(expectedBandwidthUsage),
p.probeDuration, p.probeDuration,
@@ -285,13 +287,12 @@ func (p *ProbeController) InitProbe(probeGoalDeltaBps int64, expectedBandwidthUs
} }
// SSBWE-TODO: try to do same path for both SSBWE and regular, the congesting part might be different though // SSBWE-TODO: try to do same path for both SSBWE and regular, the congesting part might be different though
func (p *ProbeController) pollProbe(probeClusterId ProbeClusterId) { func (p *ProbeController) pollProbe(probeClusterId ccutils.ProbeClusterId) {
if p.sendSideBWE == nil { if p.sendSideBWE == nil {
return return
} }
startingEstimate := p.sendSideBWE.GetEstimatedAvailableChannelCapacity() startingEstimate := p.sendSideBWE.GetEstimatedAvailableChannelCapacity()
go func() { go func() {
for { for {
p.lock.Lock() p.lock.Lock()
@@ -352,10 +353,10 @@ func (p *ProbeController) pollProbe(probeClusterId ProbeClusterId) {
} }
func (p *ProbeController) clearProbeLocked() { func (p *ProbeController) clearProbeLocked() {
p.probeClusterId = ProbeClusterIdInvalid p.probeClusterId = ccutils.ProbeClusterIdInvalid
p.doneProbeClusterInfo = ProbeClusterInfo{Id: ProbeClusterIdInvalid} p.doneProbeClusterInfo = ccutils.ProbeClusterInfo{Id: ccutils.ProbeClusterIdInvalid}
p.abortedProbeClusterId = ProbeClusterIdInvalid p.abortedProbeClusterId = ccutils.ProbeClusterIdInvalid
p.goalReachedProbeClusterId = ProbeClusterIdInvalid p.goalReachedProbeClusterId = ccutils.ProbeClusterIdInvalid
} }
func (p *ProbeController) backoffProbeIntervalLocked() { func (p *ProbeController) backoffProbeIntervalLocked() {
@@ -404,14 +405,14 @@ func (p *ProbeController) IsInProbe() bool {
} }
func (p *ProbeController) isInProbeLocked() bool { func (p *ProbeController) isInProbeLocked() bool {
return p.probeClusterId != ProbeClusterIdInvalid return p.probeClusterId != ccutils.ProbeClusterIdInvalid
} }
func (p *ProbeController) CanProbe() bool { func (p *ProbeController) CanProbe() bool {
p.lock.RLock() p.lock.RLock()
defer p.lock.RUnlock() defer p.lock.RUnlock()
return time.Since(p.lastProbeStartTime) >= p.probeInterval && p.probeClusterId == ProbeClusterIdInvalid return time.Since(p.lastProbeStartTime) >= p.probeInterval && p.probeClusterId == ccutils.ProbeClusterIdInvalid
} }
// ------------------------------------------------ // ------------------------------------------------
+22 -16
View File
@@ -30,6 +30,7 @@ import (
"github.com/livekit/livekit-server/pkg/sfu" "github.com/livekit/livekit-server/pkg/sfu"
"github.com/livekit/livekit-server/pkg/sfu/buffer" "github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/livekit-server/pkg/sfu/ccutils"
"github.com/livekit/livekit-server/pkg/sfu/sendsidebwe" "github.com/livekit/livekit-server/pkg/sfu/sendsidebwe"
"github.com/livekit/livekit-server/pkg/utils" "github.com/livekit/livekit-server/pkg/utils"
) )
@@ -195,7 +196,7 @@ type StreamAllocator struct {
probeController *ProbeController probeController *ProbeController
prober *Prober prober *ccutils.Prober
channelObserver *ChannelObserver channelObserver *ChannelObserver
// STREAM-ALLOCATOR-DATA rateMonitor *RateMonitor // STREAM-ALLOCATOR-DATA rateMonitor *RateMonitor
@@ -218,7 +219,7 @@ func NewStreamAllocator(params StreamAllocatorParams, enabled bool, allowPause b
params: params, params: params,
enabled: enabled, enabled: enabled,
allowPause: allowPause, allowPause: allowPause,
prober: NewProber(ProberParams{ prober: ccutils.NewProber(ccutils.ProberParams{
Logger: params.Logger, Logger: params.Logger,
}), }),
// STREAM-ALLOCATOR-DATA rateMonitor: NewRateMonitor(), // STREAM-ALLOCATOR-DATA rateMonitor: NewRateMonitor(),
@@ -562,7 +563,7 @@ func (s *StreamAllocator) OnSendProbe(bytesToSend int) {
} }
// called when prober finishes a probe cluster, could be called when prober is reset which stops an active cluster // called when prober finishes a probe cluster, could be called when prober is reset which stops an active cluster
func (s *StreamAllocator) OnProbeClusterDone(info ProbeClusterInfo) { func (s *StreamAllocator) OnProbeClusterDone(info ccutils.ProbeClusterInfo) {
s.postEvent(Event{ s.postEvent(Event{
Signal: streamAllocatorSignalProbeClusterDone, Signal: streamAllocatorSignalProbeClusterDone,
Data: info, Data: info,
@@ -759,7 +760,7 @@ func (s *StreamAllocator) handleSignalSendProbe(event Event) {
} }
func (s *StreamAllocator) handleSignalProbeClusterDone(event Event) { func (s *StreamAllocator) handleSignalProbeClusterDone(event Event) {
info, _ := event.Data.(ProbeClusterInfo) info, _ := event.Data.(ccutils.ProbeClusterInfo)
s.probeController.ProbeClusterDone(info) s.probeController.ProbeClusterDone(info)
} }
@@ -1409,23 +1410,28 @@ func (s *StreamAllocator) initProbe(probeGoalDeltaBps int64) {
expectedBandwidthUsage := s.getExpectedBandwidthUsage() expectedBandwidthUsage := s.getExpectedBandwidthUsage()
probeClusterId, probeGoalBps := s.probeController.InitProbe(probeGoalDeltaBps, expectedBandwidthUsage) probeClusterId, probeGoalBps := s.probeController.InitProbe(probeGoalDeltaBps, expectedBandwidthUsage)
channelState := "" logFields := []any{
if s.channelObserver != nil {
channelState = s.channelObserver.ToString()
}
s.channelObserver = s.newChannelObserverProbe()
s.channelObserver.SeedEstimate(s.lastReceivedEstimate)
s.params.Logger.Debugw(
"stream allocator: starting probe",
"probeClusterId", probeClusterId, "probeClusterId", probeClusterId,
"current usage", expectedBandwidthUsage, "current usage", expectedBandwidthUsage,
"committed", s.committedChannelCapacity, "committed", s.committedChannelCapacity,
"lastReceived", s.lastReceivedEstimate,
"channel", channelState,
"probeGoalDeltaBps", probeGoalDeltaBps, "probeGoalDeltaBps", probeGoalDeltaBps,
"goalBps", probeGoalBps, "goalBps", probeGoalBps,
) }
if s.sendSideBWE != nil {
channelState := ""
if s.channelObserver != nil {
channelState = s.channelObserver.ToString()
}
s.channelObserver = s.newChannelObserverProbe()
s.channelObserver.SeedEstimate(s.lastReceivedEstimate)
logFields = append(
logFields,
"lastReceived", s.lastReceivedEstimate,
"channel", channelState,
)
}
s.params.Logger.Debugw("stream allocator: starting probe", logFields...)
} }
func (s *StreamAllocator) maybeProbe() { func (s *StreamAllocator) maybeProbe() {