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:
@@ -117,7 +117,7 @@
|
||||
// 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 nearest data center.
|
||||
package streamallocator
|
||||
package ccutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils/mono"
|
||||
"github.com/pion/rtcp"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
@@ -33,6 +34,10 @@ type CongestionSignalConfig struct {
|
||||
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 (
|
||||
DefaultQueuingDelayEarlyWarningCongestionSignalConfig = CongestionSignalConfig{
|
||||
MinNumberOfGroups: 1,
|
||||
@@ -111,7 +116,7 @@ func (q *qdMeasurement) ProcessPacketGroup(pg *packetGroup) {
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -121,11 +126,26 @@ func (q *qdMeasurement) IsSealed() 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 {
|
||||
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
|
||||
}
|
||||
|
||||
l.numGroups++
|
||||
l.ts.Merge(pg.Traffic())
|
||||
|
||||
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()
|
||||
}
|
||||
if l.numGroups >= l.congestedConfig.MinNumberOfGroups && duration >= l.congestedConfig.MinDuration.Microseconds() {
|
||||
if l.congestedConfig.IsTriggered(l.numGroups, duration) {
|
||||
l.congestedWeightedLoss = l.ts.WeightedLoss()
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -232,7 +268,7 @@ var (
|
||||
|
||||
DefaultCongestionDetectorConfig = CongestionDetectorConfig{
|
||||
PacketGroup: DefaultPacketGroupConfig,
|
||||
PacketGroupMaxAge: 30 * time.Second,
|
||||
PacketGroupMaxAge: 15 * time.Second,
|
||||
JQRMinDelay: 15 * time.Millisecond,
|
||||
DQRMaxDelay: 5 * time.Millisecond,
|
||||
WeightedLoss: defaultWeightedLossConfig,
|
||||
@@ -327,6 +363,8 @@ func (c *congestionDetector) updateCongestionState(state CongestionState, reason
|
||||
"from", c.congestionState,
|
||||
"to", state,
|
||||
"reason", reason,
|
||||
"numPacketGroups", len(c.packetGroups),
|
||||
"numContributingGroups", len(c.packetGroups[oldestContributingGroup:]),
|
||||
"contributingGroups", logger.ObjectSlice(c.packetGroups[oldestContributingGroup:]),
|
||||
"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
|
||||
// reducing/relieving congestion
|
||||
if state == CongestionStateCongested && prevState != CongestionStateCongested {
|
||||
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.resetCTRTrend()
|
||||
} else if state != CongestionStateCongested {
|
||||
c.congestedCTRTrend = nil
|
||||
c.congestedTrafficStats = nil
|
||||
c.clearCTRTrend()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,11 +417,10 @@ func (c *congestionDetector) prunePacketGroups() {
|
||||
return
|
||||
}
|
||||
|
||||
bst := c.packetTracker.BaseSendTime()
|
||||
if bst == 0 {
|
||||
threshold, ok := c.packetTracker.BaseSendTimeThreshold(c.params.Config.PacketGroupMaxAge.Microseconds())
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
threshold := mono.UnixMicro() - bst - c.params.Config.PacketGroupMaxAge.Microseconds()
|
||||
|
||||
for idx, pg := range c.packetGroups {
|
||||
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() {
|
||||
@@ -464,7 +492,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
|
||||
switch state {
|
||||
case CongestionStateNone:
|
||||
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 {
|
||||
newState = CongestionStateEarlyWarning
|
||||
@@ -481,7 +509,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
|
||||
|
||||
case CongestionStateEarlyWarningHangover:
|
||||
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 {
|
||||
newState = CongestionStateEarlyWarning
|
||||
@@ -497,7 +525,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
|
||||
|
||||
case CongestionStateCongestedHangover:
|
||||
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 {
|
||||
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 {
|
||||
return
|
||||
}
|
||||
@@ -529,30 +574,24 @@ func (c *congestionDetector) updateTrend(pg *packetGroup) {
|
||||
// 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)
|
||||
|
||||
if c.congestedCTRTrend.GetDirection() == ccutils.TrendDirectionDownward {
|
||||
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.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,
|
||||
})
|
||||
if c.congestedCTRTrend.GetDirection() != ccutils.TrendDirectionDownward {
|
||||
return
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -560,19 +599,19 @@ func (c *congestionDetector) estimateAvailableChannelCapacity() {
|
||||
return
|
||||
}
|
||||
|
||||
bst := c.packetTracker.BaseSendTime()
|
||||
if bst == 0 {
|
||||
threshold, ok := c.packetTracker.BaseSendTimeThreshold(c.params.Config.RateMeasurementWindowDurationMax.Microseconds())
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
threshold := mono.UnixMicro() - bst - c.params.Config.RateMeasurementWindowDurationMax.Microseconds()
|
||||
|
||||
agg := newTrafficStats(trafficStatsParams{
|
||||
Config: c.params.Config.WeightedLoss,
|
||||
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]
|
||||
if pg.MinSendTime() < threshold {
|
||||
if mst := pg.MinSendTime(); mst != 0 && mst < threshold {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -580,7 +619,12 @@ func (c *congestionDetector) estimateAvailableChannelCapacity() {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -600,8 +644,9 @@ func (c *congestionDetector) processFeedbackReport(fbr feedbackReport) {
|
||||
c.packetGroups,
|
||||
newPacketGroup(
|
||||
packetGroupParams{
|
||||
Config: c.params.Config.PacketGroup,
|
||||
Logger: c.params.Logger,
|
||||
Config: c.params.Config.PacketGroup,
|
||||
WeightedLoss: c.params.Config.WeightedLoss,
|
||||
Logger: c.params.Logger,
|
||||
},
|
||||
0,
|
||||
),
|
||||
@@ -621,14 +666,15 @@ func (c *congestionDetector) processFeedbackReport(fbr feedbackReport) {
|
||||
|
||||
if err == errGroupFinalized {
|
||||
// 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
|
||||
pqd, _ := pg.PropagatedQueuingDelay()
|
||||
pg = newPacketGroup(
|
||||
packetGroupParams{
|
||||
Config: c.params.Config.PacketGroup,
|
||||
Logger: c.params.Logger,
|
||||
Config: c.params.Config.PacketGroup,
|
||||
WeightedLoss: c.params.Config.WeightedLoss,
|
||||
Logger: c.params.Logger,
|
||||
},
|
||||
pqd,
|
||||
)
|
||||
|
||||
@@ -221,7 +221,7 @@ func (p *packetGroup) MinSendTime() int64 {
|
||||
}
|
||||
|
||||
func (p *packetGroup) SendWindow() (int64, int64) {
|
||||
return p.maxSendTime, p.minSendTime
|
||||
return p.minSendTime, p.maxSendTime
|
||||
}
|
||||
|
||||
func (p *packetGroup) PropagatedQueuingDelay() (int64, bool) {
|
||||
@@ -275,6 +275,9 @@ func (p *packetGroup) MarshalLogObject(e zapcore.ObjectEncoder) error {
|
||||
})
|
||||
ts.Merge(p.Traffic())
|
||||
e.AddObject("trafficStats", ts)
|
||||
e.AddInt64("queuingDelay", p.queuingDelay)
|
||||
pqd, _ := p.PropagatedQueuingDelay()
|
||||
e.AddInt64("propagatedQueuingDelay", pqd)
|
||||
|
||||
e.AddBool("isFinalized", p.isFinalized)
|
||||
return nil
|
||||
|
||||
@@ -15,18 +15,12 @@
|
||||
package sendsidebwe
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
var (
|
||||
errNoPacketInRange = errors.New("no packet in range")
|
||||
"github.com/livekit/protocol/utils/mono"
|
||||
)
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
@@ -84,11 +78,15 @@ func (p *packetTracker) RecordPacketSendAndGetSequenceNumber(at time.Time, size
|
||||
return uint16(pi.sequenceNumber)
|
||||
}
|
||||
|
||||
func (p *packetTracker) BaseSendTime() int64 {
|
||||
func (p *packetTracker) BaseSendTimeThreshold(threshold int64) (int64, bool) {
|
||||
p.lock.Lock()
|
||||
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) {
|
||||
|
||||
@@ -62,7 +62,7 @@ func newTrafficStats(params trafficStatsParams) *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
|
||||
}
|
||||
if rhs.maxSendTime > ts.maxSendTime {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/ccutils"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/sendsidebwe"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
@@ -66,7 +67,7 @@ var (
|
||||
|
||||
type ProbeControllerParams struct {
|
||||
Config ProbeControllerConfig
|
||||
Prober *Prober
|
||||
Prober *ccutils.Prober
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
@@ -78,10 +79,10 @@ type ProbeController struct {
|
||||
probeInterval time.Duration
|
||||
lastProbeStartTime time.Time
|
||||
probeGoalBps int64
|
||||
probeClusterId ProbeClusterId
|
||||
doneProbeClusterInfo ProbeClusterInfo
|
||||
abortedProbeClusterId ProbeClusterId
|
||||
goalReachedProbeClusterId ProbeClusterId
|
||||
probeClusterId ccutils.ProbeClusterId
|
||||
doneProbeClusterInfo ccutils.ProbeClusterInfo
|
||||
abortedProbeClusterId ccutils.ProbeClusterId
|
||||
goalReachedProbeClusterId ccutils.ProbeClusterId
|
||||
probeTrendObserved bool
|
||||
probeEndTime time.Time
|
||||
probeDuration time.Duration
|
||||
@@ -117,23 +118,24 @@ func (p *ProbeController) Reset() {
|
||||
p.clearProbeLocked()
|
||||
}
|
||||
|
||||
func (p *ProbeController) ProbeClusterDone(info ProbeClusterInfo) {
|
||||
func (p *ProbeController) ProbeClusterDone(info ccutils.ProbeClusterInfo) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
if p.probeClusterId != info.Id {
|
||||
p.params.Logger.Debugw("not expected probe cluster", "probeClusterId", p.probeClusterId, "resetProbeClusterId", info.Id)
|
||||
p.lock.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
p.doneProbeClusterInfo = info
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ProbeController) CheckProbe(trend ChannelTrend, highestEstimate int64) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
if p.probeClusterId == ProbeClusterIdInvalid {
|
||||
if p.probeClusterId == ccutils.ProbeClusterIdInvalid {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -181,15 +183,15 @@ func (p *ProbeController) MaybeFinalizeProbe(
|
||||
return false, false, false
|
||||
}
|
||||
|
||||
if p.goalReachedProbeClusterId != ProbeClusterIdInvalid {
|
||||
if p.goalReachedProbeClusterId != ccutils.ProbeClusterIdInvalid {
|
||||
// finalise goal reached probe cluster
|
||||
p.finalizeProbeLocked(ChannelTrendNeutral)
|
||||
return true, true, true
|
||||
}
|
||||
|
||||
if (isComplete || p.abortedProbeClusterId != ProbeClusterIdInvalid) &&
|
||||
if (isComplete || p.abortedProbeClusterId != ccutils.ProbeClusterIdInvalid) &&
|
||||
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
|
||||
// STREAM-ALLOCATOR-TODO: CongestionControlProbeConfig.SettleWait should actually be a certain number of RTTs.
|
||||
expectedDuration := float64(9.0)
|
||||
@@ -227,7 +229,7 @@ func (p *ProbeController) DoesProbeNeedFinalize() bool {
|
||||
p.lock.RLock()
|
||||
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) {
|
||||
@@ -250,7 +252,7 @@ func (p *ProbeController) finalizeProbeLocked(trend ChannelTrend) (isNotFailing
|
||||
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()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
@@ -263,16 +265,16 @@ func (p *ProbeController) InitProbe(probeGoalDeltaBps int64, expectedBandwidthUs
|
||||
}
|
||||
p.probeGoalBps = expectedBandwidthUsage + desiredIncreaseBps
|
||||
|
||||
p.doneProbeClusterInfo = ProbeClusterInfo{Id: ProbeClusterIdInvalid}
|
||||
p.abortedProbeClusterId = ProbeClusterIdInvalid
|
||||
p.goalReachedProbeClusterId = ProbeClusterIdInvalid
|
||||
p.doneProbeClusterInfo = ccutils.ProbeClusterInfo{Id: ccutils.ProbeClusterIdInvalid}
|
||||
p.abortedProbeClusterId = ccutils.ProbeClusterIdInvalid
|
||||
p.goalReachedProbeClusterId = ccutils.ProbeClusterIdInvalid
|
||||
|
||||
p.probeTrendObserved = false
|
||||
|
||||
p.probeEndTime = time.Time{}
|
||||
|
||||
p.probeClusterId = p.params.Prober.AddCluster(
|
||||
ProbeClusterModeUniform,
|
||||
ccutils.ProbeClusterModeUniform,
|
||||
int(p.probeGoalBps),
|
||||
int(expectedBandwidthUsage),
|
||||
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
|
||||
func (p *ProbeController) pollProbe(probeClusterId ProbeClusterId) {
|
||||
func (p *ProbeController) pollProbe(probeClusterId ccutils.ProbeClusterId) {
|
||||
if p.sendSideBWE == nil {
|
||||
return
|
||||
}
|
||||
|
||||
startingEstimate := p.sendSideBWE.GetEstimatedAvailableChannelCapacity()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
p.lock.Lock()
|
||||
@@ -352,10 +353,10 @@ func (p *ProbeController) pollProbe(probeClusterId ProbeClusterId) {
|
||||
}
|
||||
|
||||
func (p *ProbeController) clearProbeLocked() {
|
||||
p.probeClusterId = ProbeClusterIdInvalid
|
||||
p.doneProbeClusterInfo = ProbeClusterInfo{Id: ProbeClusterIdInvalid}
|
||||
p.abortedProbeClusterId = ProbeClusterIdInvalid
|
||||
p.goalReachedProbeClusterId = ProbeClusterIdInvalid
|
||||
p.probeClusterId = ccutils.ProbeClusterIdInvalid
|
||||
p.doneProbeClusterInfo = ccutils.ProbeClusterInfo{Id: ccutils.ProbeClusterIdInvalid}
|
||||
p.abortedProbeClusterId = ccutils.ProbeClusterIdInvalid
|
||||
p.goalReachedProbeClusterId = ccutils.ProbeClusterIdInvalid
|
||||
}
|
||||
|
||||
func (p *ProbeController) backoffProbeIntervalLocked() {
|
||||
@@ -404,14 +405,14 @@ func (p *ProbeController) IsInProbe() bool {
|
||||
}
|
||||
|
||||
func (p *ProbeController) isInProbeLocked() bool {
|
||||
return p.probeClusterId != ProbeClusterIdInvalid
|
||||
return p.probeClusterId != ccutils.ProbeClusterIdInvalid
|
||||
}
|
||||
|
||||
func (p *ProbeController) CanProbe() bool {
|
||||
p.lock.RLock()
|
||||
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
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"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/utils"
|
||||
)
|
||||
@@ -195,7 +196,7 @@ type StreamAllocator struct {
|
||||
|
||||
probeController *ProbeController
|
||||
|
||||
prober *Prober
|
||||
prober *ccutils.Prober
|
||||
|
||||
channelObserver *ChannelObserver
|
||||
// STREAM-ALLOCATOR-DATA rateMonitor *RateMonitor
|
||||
@@ -218,7 +219,7 @@ func NewStreamAllocator(params StreamAllocatorParams, enabled bool, allowPause b
|
||||
params: params,
|
||||
enabled: enabled,
|
||||
allowPause: allowPause,
|
||||
prober: NewProber(ProberParams{
|
||||
prober: ccutils.NewProber(ccutils.ProberParams{
|
||||
Logger: params.Logger,
|
||||
}),
|
||||
// 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
|
||||
func (s *StreamAllocator) OnProbeClusterDone(info ProbeClusterInfo) {
|
||||
func (s *StreamAllocator) OnProbeClusterDone(info ccutils.ProbeClusterInfo) {
|
||||
s.postEvent(Event{
|
||||
Signal: streamAllocatorSignalProbeClusterDone,
|
||||
Data: info,
|
||||
@@ -759,7 +760,7 @@ func (s *StreamAllocator) handleSignalSendProbe(event Event) {
|
||||
}
|
||||
|
||||
func (s *StreamAllocator) handleSignalProbeClusterDone(event Event) {
|
||||
info, _ := event.Data.(ProbeClusterInfo)
|
||||
info, _ := event.Data.(ccutils.ProbeClusterInfo)
|
||||
s.probeController.ProbeClusterDone(info)
|
||||
}
|
||||
|
||||
@@ -1409,23 +1410,28 @@ func (s *StreamAllocator) initProbe(probeGoalDeltaBps int64) {
|
||||
expectedBandwidthUsage := s.getExpectedBandwidthUsage()
|
||||
probeClusterId, probeGoalBps := s.probeController.InitProbe(probeGoalDeltaBps, expectedBandwidthUsage)
|
||||
|
||||
channelState := ""
|
||||
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",
|
||||
logFields := []any{
|
||||
"probeClusterId", probeClusterId,
|
||||
"current usage", expectedBandwidthUsage,
|
||||
"committed", s.committedChannelCapacity,
|
||||
"lastReceived", s.lastReceivedEstimate,
|
||||
"channel", channelState,
|
||||
"probeGoalDeltaBps", probeGoalDeltaBps,
|
||||
"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() {
|
||||
|
||||
Reference in New Issue
Block a user