TWCC probing (#3234)

* WIP

* WIP

* WIP

* make it compile

* typo

* clean up

* fmt

* fixes
This commit is contained in:
Raja Subramanian
2024-12-06 00:13:36 +05:30
committed by GitHub
parent d862917249
commit 94488d434d
16 changed files with 911 additions and 454 deletions
+193 -36
View File
@@ -63,6 +63,58 @@ var (
// -------------------------------------------------------------------------------
type ProbeSignalConfig struct {
MinBytesRatio float64 `yaml:"min_bytes_ratio,omitempty"`
MinDurationRatio float64 `yaml:"min_duration_ratio,omitempty"`
JQRMinDelay time.Duration `yaml:"jqr_min_delay,omitempty"`
DQRMaxDelay time.Duration `yaml:"dqr_max_delay,omitempty"`
WeightedLoss WeightedLossConfig `yaml:"weighted_loss,omitempty"`
CongestionMinLoss float64 `yaml:"congestion_min_loss,omitempty"`
}
func (p ProbeSignalConfig) IsValid(pci ccutils.ProbeClusterInfo) bool {
return pci.Result.Bytes() > int(p.MinBytesRatio*float64(pci.Goal.DesiredBytes)) && pci.Result.Duration() > time.Duration(p.MinDurationRatio*float64(pci.Goal.Duration))
}
func (p ProbeSignalConfig) ProbeSignal(ppg *probePacketGroup) (ccutils.ProbeSignal, int64) {
ts := newTrafficStats(trafficStatsParams{
Config: p.WeightedLoss,
})
ts.Merge(ppg.Traffic())
pqd := ppg.PropagatedQueuingDelay()
if pqd > p.JQRMinDelay.Microseconds() {
return ccutils.ProbeSignalCongesting, ts.AcknowledgedBitrate()
}
if ts.WeightedLoss() > p.CongestionMinLoss {
return ccutils.ProbeSignalCongesting, ts.AcknowledgedBitrate()
}
if pqd < p.DQRMaxDelay.Microseconds() {
return ccutils.ProbeSignalClearing, ts.AcknowledgedBitrate()
}
return ccutils.ProbeSignalInconclusive, ts.AcknowledgedBitrate()
}
var (
DefaultProbeSignalConfig = ProbeSignalConfig{
MinBytesRatio: 0.5,
MinDurationRatio: 0.5,
JQRMinDelay: 15 * time.Millisecond,
DQRMaxDelay: 5 * time.Millisecond,
WeightedLoss: defaultWeightedLossConfig,
CongestionMinLoss: 0.25,
}
)
// -------------------------------------------------------------------------------
type qdMeasurement struct {
earlyWarningConfig CongestionSignalConfig
congestedConfig CongestionSignalConfig
@@ -94,7 +146,7 @@ func (q *qdMeasurement) ProcessPacketGroup(pg *packetGroup) {
return
}
pqd, pqdOk := pg.PropagatedQueuingDelay()
pqd, pqdOk := pg.FinalizedPropagatedQueuingDelay()
if !pqdOk {
return
}
@@ -234,6 +286,10 @@ type CongestionDetectorConfig struct {
PacketGroup PacketGroupConfig `yaml:"packet_group,omitempty"`
PacketGroupMaxAge time.Duration `yaml:"packet_group_max_age,omitempty"`
ProbePacketGroup ProbePacketGroupConfig `yaml:"probe_packet_group,omitempty"`
ProbeRegulator ccutils.ProbeRegulatorConfig `yaml:"probe_regulator,omitempty"`
ProbeSignal ProbeSignalConfig `yaml:"probe_signal,omitempty"`
JQRMinDelay time.Duration `yaml:"jqr_min_delay,omitempty"`
DQRMaxDelay time.Duration `yaml:"dqr_max_delay,omitempty"`
@@ -268,24 +324,34 @@ var (
}
DefaultCongestionDetectorConfig = CongestionDetectorConfig{
PacketGroup: DefaultPacketGroupConfig,
PacketGroupMaxAge: 15 * time.Second,
JQRMinDelay: 15 * time.Millisecond,
DQRMaxDelay: 5 * time.Millisecond,
WeightedLoss: defaultWeightedLossConfig,
CongestionMinLoss: 0.25,
QueuingDelayEarlyWarning: DefaultQueuingDelayEarlyWarningCongestionSignalConfig,
LossEarlyWarning: DefaultLossEarlyWarningCongestionSignalConfig,
EarlyWarningHangover: 500 * time.Millisecond,
QueuingDelayCongested: DefaultQueuingDelayCongestedCongestionSignalConfig,
LossCongested: DefaultLossCongestedCongestionSignalConfig,
CongestedHangover: 3 * time.Second,
PacketGroup: DefaultPacketGroupConfig,
PacketGroupMaxAge: 15 * time.Second,
ProbePacketGroup: DefaultPacketGroupConfigProbe,
ProbeRegulator: ccutils.DefaultProbeRegulatorConfig,
ProbeSignal: DefaultProbeSignalConfig,
JQRMinDelay: 15 * time.Millisecond,
DQRMaxDelay: 5 * time.Millisecond,
WeightedLoss: defaultWeightedLossConfig,
CongestionMinLoss: 0.25,
QueuingDelayEarlyWarning: DefaultQueuingDelayEarlyWarningCongestionSignalConfig,
LossEarlyWarning: DefaultLossEarlyWarningCongestionSignalConfig,
EarlyWarningHangover: 500 * time.Millisecond,
QueuingDelayCongested: DefaultQueuingDelayCongestedCongestionSignalConfig,
LossCongested: DefaultLossCongestedCongestionSignalConfig,
CongestedHangover: 3 * time.Second,
RateMeasurementWindowDurationMin: 800 * time.Millisecond,
RateMeasurementWindowDurationMax: 2 * time.Second,
PeriodicCheckInterval: 2 * time.Second,
PeriodicCheckIntervalCongested: 200 * time.Millisecond,
CongestedCTRTrend: defaultTrendDetectorConfigCongestedCTR,
CongestedCTREpsilon: 0.05,
PeriodicCheckInterval: 2 * time.Second,
PeriodicCheckIntervalCongested: 200 * time.Millisecond,
CongestedCTRTrend: defaultTrendDetectorConfigCongestedCTR,
CongestedCTREpsilon: 0.05,
}
)
@@ -307,11 +373,16 @@ type congestionDetector struct {
lock sync.RWMutex
feedbackReports deque.Deque[feedbackReport]
rtt float64
*packetTracker
twccFeedback *twccFeedback
packetGroups []*packetGroup
probePacketGroup *probePacketGroup
probeRegulator *ccutils.ProbeRegulator
wake chan struct{}
stop core.Fuse
@@ -326,9 +397,14 @@ type congestionDetector struct {
func newCongestionDetector(params congestionDetectorParams) *congestionDetector {
c := &congestionDetector{
params: params,
packetTracker: newPacketTracker(packetTrackerParams{Logger: params.Logger}),
twccFeedback: newTWCCFeedback(twccFeedbackParams{Logger: params.Logger}),
params: params,
rtt: bwe.DefaultRTT,
packetTracker: newPacketTracker(packetTrackerParams{Logger: params.Logger}),
twccFeedback: newTWCCFeedback(twccFeedbackParams{Logger: params.Logger}),
probeRegulator: ccutils.NewProbeRegulator(ccutils.ProbeRegulatorParams{
Config: params.Config.ProbeRegulator,
Logger: params.Logger,
}),
wake: make(chan struct{}, 1),
estimatedAvailableChannelCapacity: 100_000_000,
congestionState: bwe.CongestionStateNone,
@@ -371,11 +447,87 @@ func (c *congestionDetector) HandleTWCCFeedback(report *rtcp.TransportLayerCC) {
}
}
func (c *congestionDetector) CongestionState() bwe.CongestionState {
c.lock.RLock()
defer c.lock.RUnlock()
func (c *congestionDetector) UpdateRTT(rtt float64) {
if rtt == 0 {
c.rtt = bwe.DefaultRTT
} else {
if c.rtt == 0 {
c.rtt = rtt
} else {
c.rtt = bwe.RTTSmoothingFactor*rtt + (1.0-bwe.RTTSmoothingFactor)*c.rtt
}
}
}
return c.congestionState
func (c *congestionDetector) CanProbe() bool {
c.lock.Lock()
defer c.lock.Unlock()
return c.congestionState == bwe.CongestionStateNone && c.probePacketGroup == nil && c.probeRegulator.CanProbe()
}
func (c *congestionDetector) ProbeDuration() time.Duration {
c.lock.Lock()
defer c.lock.Unlock()
return c.probeRegulator.ProbeDuration()
}
func (c *congestionDetector) ProbeClusterStarting(pci ccutils.ProbeClusterInfo) {
c.lock.Lock()
defer c.lock.Unlock()
c.probePacketGroup = newProbePacketGroup(
probePacketGroupParams{
Config: c.params.Config.ProbePacketGroup,
WeightedLoss: c.params.Config.WeightedLoss,
Logger: c.params.Logger,
},
pci,
)
c.packetTracker.ProbeClusterStarting(pci.Id)
}
func (c *congestionDetector) ProbeClusterDone(pci ccutils.ProbeClusterInfo) {
c.lock.Lock()
defer c.lock.Unlock()
c.packetTracker.ProbeClusterDone(pci.Id)
if c.probePacketGroup != nil {
c.probePacketGroup.ProbeClusterDone(pci)
}
}
func (c *congestionDetector) ProbeClusterFinalize() (ccutils.ProbeSignal, int64, bool) {
c.lock.Lock()
defer c.lock.Unlock()
if c.probePacketGroup == nil {
return ccutils.ProbeSignalInconclusive, 0, false
}
pci, isFinalized := c.probePacketGroup.MaybeFinalizeProbe(c.packetTracker.ProbeMaxSequenceNumber(), c.rtt)
if !isFinalized {
return ccutils.ProbeSignalInconclusive, 0, isFinalized
}
isSignalValid := c.params.Config.ProbeSignal.IsValid(pci)
c.params.Logger.Debugw(
"send side bwe: probe finalized",
"isSignalValid", isSignalValid,
"probeClusterInfo", pci,
"probePacketGroup", c.probePacketGroup,
)
probeSignal, estimatedAvailableChannelCapacity := c.params.Config.ProbeSignal.ProbeSignal(c.probePacketGroup)
if probeSignal == ccutils.ProbeSignalClearing && estimatedAvailableChannelCapacity > c.estimatedAvailableChannelCapacity {
c.estimatedAvailableChannelCapacity = estimatedAvailableChannelCapacity
}
c.probeRegulator.ProbeSignal(probeSignal, pci.CreatedAt)
c.probePacketGroup = nil
return probeSignal, c.estimatedAvailableChannelCapacity, true
}
func (c *congestionDetector) prunePacketGroups() {
@@ -458,7 +610,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
switch state {
case bwe.CongestionStateNone:
if congestedTriggered {
c.params.Logger.Warnw("invalid congested state transition", nil, "from", state, "reason", congestedReason)
c.params.Logger.Warnw("send side bwe: invalid congested state transition", nil, "from", state, "reason", congestedReason)
}
if earlyWarningTriggered {
newState = bwe.CongestionStateEarlyWarning
@@ -475,7 +627,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
case bwe.CongestionStateEarlyWarningHangover:
if congestedTriggered {
c.params.Logger.Warnw("invalid congested state transition", nil, "from", state, "reason", congestedReason)
c.params.Logger.Warnw("send side bwe: invalid congested state transition", nil, "from", state, "reason", congestedReason)
}
if earlyWarningTriggered {
newState = bwe.CongestionStateEarlyWarning
@@ -491,7 +643,7 @@ func (c *congestionDetector) congestionDetectionStateMachine() {
case bwe.CongestionStateCongestedHangover:
if congestedTriggered {
c.params.Logger.Warnw("invalid congested state transition", nil, "from", state, "reason", congestedReason)
c.params.Logger.Warnw("send side bwe: invalid congested state transition", nil, "from", state, "reason", congestedReason)
}
if earlyWarningTriggered {
newState = bwe.CongestionStateEarlyWarning
@@ -543,7 +695,7 @@ func (c *congestionDetector) updateCTRTrend(pg *packetGroup) {
return
}
c.params.Logger.Infow("captured traffic ratio is trending downward", "channel", c.congestedCTRTrend)
c.params.Logger.Infow("send side bwe: captured traffic ratio is trending downward", "channel", c.congestedCTRTrend)
if bweListener := c.getBWEListener(); bweListener != nil {
bweListener.OnCongestionStateChange(c.congestionState, c.estimatedAvailableChannelCapacity)
@@ -554,7 +706,7 @@ func (c *congestionDetector) updateCTRTrend(pg *packetGroup) {
}
func (c *congestionDetector) estimateAvailableChannelCapacity() {
if len(c.packetGroups) == 0 {
if len(c.packetGroups) == 0 || c.probePacketGroup != nil {
return
}
@@ -579,7 +731,7 @@ func (c *congestionDetector) estimateAvailableChannelCapacity() {
if agg.Duration() < c.params.Config.RateMeasurementWindowDurationMin.Microseconds() {
c.params.Logger.Infow(
"not enough data to estimate available channel capacity",
"send side bwe: not enough data to estimate available channel capacity",
"duration", agg.Duration(),
"numGroups", len(c.packetGroups),
"oldestUsed", max(0, idx),
@@ -592,7 +744,7 @@ func (c *congestionDetector) estimateAvailableChannelCapacity() {
func (c *congestionDetector) updateCongestionState(state bwe.CongestionState, reason string, oldestContributingGroup int) {
c.params.Logger.Infow(
"congestion state change",
"send side bwe: congestion state change",
"from", c.congestionState,
"to", state,
"reason", reason,
@@ -629,7 +781,7 @@ func (c *congestionDetector) updateCongestionState(state bwe.CongestionState, re
func (c *congestionDetector) processFeedbackReport(fbr feedbackReport) {
recvRefTime, isOutOfOrder := c.twccFeedback.ProcessReport(fbr.report, fbr.at)
if isOutOfOrder {
c.params.Logger.Infow("received out-of-order feedback report")
c.params.Logger.Infow("send side bwe: received out-of-order feedback report")
}
if len(c.packetGroups) == 0 {
@@ -652,6 +804,10 @@ func (c *congestionDetector) processFeedbackReport(fbr feedbackReport) {
return
}
if c.probePacketGroup != nil {
c.probePacketGroup.Add(pi, sendDelta, recvDelta, isLost)
}
err := pg.Add(pi, sendDelta, recvDelta, isLost)
if err == nil {
return
@@ -662,18 +818,19 @@ func (c *congestionDetector) processFeedbackReport(fbr feedbackReport) {
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,
WeightedLoss: c.params.Config.WeightedLoss,
Logger: c.params.Logger,
},
pqd,
pg.PropagatedQueuingDelay(),
)
c.packetGroups = append(c.packetGroups, pg)
pg.Add(pi, sendDelta, recvDelta, isLost)
if err = pg.Add(pi, sendDelta, recvDelta, isLost); err != nil {
c.params.Logger.Warnw("send side bwe: could not add packet to new packet group", err, "packetInfo", pi, "packetGroup", pg)
}
return
}
@@ -683,7 +840,7 @@ func (c *congestionDetector) processFeedbackReport(fbr feedbackReport) {
if err := opg.Add(pi, sendDelta, recvDelta, isLost); err == nil {
return
} else if err == errGroupFinalized {
c.params.Logger.Infow("unpected finalized group", "packetInfo", pi, "packetGroup", opg)
c.params.Logger.Infow("send side bwe: unexpected finalized group", "packetInfo", pi, "packetGroup", opg)
}
}
}
+12 -8
View File
@@ -230,16 +230,20 @@ func (p *packetGroup) SendWindow() (int64, int64) {
return p.minSendTime, p.maxSendTime
}
func (p *packetGroup) PropagatedQueuingDelay() (int64, bool) {
func (p *packetGroup) PropagatedQueuingDelay() int64 {
if p.queuingDelay+p.aggregateRecvDelta-p.aggregateSendDelta > 0 {
return p.queuingDelay + p.aggregateRecvDelta - p.aggregateSendDelta
}
return max(0, p.aggregateRecvDelta-p.aggregateSendDelta)
}
func (p *packetGroup) FinalizedPropagatedQueuingDelay() (int64, bool) {
if !p.isFinalized {
return 0, false
}
if p.queuingDelay+p.aggregateRecvDelta-p.aggregateSendDelta > 0 {
return p.queuingDelay + p.aggregateRecvDelta - p.aggregateSendDelta, true
}
return max(0, p.aggregateRecvDelta-p.aggregateSendDelta), true
return p.PropagatedQueuingDelay(), true
}
func (p *packetGroup) Traffic() *trafficStats {
@@ -251,6 +255,7 @@ func (p *packetGroup) Traffic() *trafficStats {
ackedPackets: p.acked.numPackets(),
ackedBytes: p.acked.numBytes(),
lostPackets: p.lost.numPackets(),
lostBytes: p.lost.numBytes(),
}
}
@@ -282,8 +287,7 @@ 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.AddInt64("propagatedQueuingDelay", p.PropagatedQueuingDelay())
e.AddBool("isFinalized", p.isFinalized)
return nil
+31 -1
View File
@@ -41,6 +41,9 @@ type packetTracker struct {
baseRecvTime int64
piLastRecv *packetInfo
probeClusterId ccutils.ProbeClusterId
probeMaxSequenceNumber uint64
}
func newPacketTracker(params packetTrackerParams) *packetTracker {
@@ -73,7 +76,7 @@ func (p *packetTracker) RecordPacketSendAndGetSequenceNumber(
probeClusterId: probeClusterId,
isProbe: isProbe,
}
// SSBWE-REMOVE p.params.Logger.Infow("packet sent", "packetInfo", pi) // SSBWE-REMOVE
//p.params.Logger.Infow("send side bwe: packet sent", "packetInfo", pi) // SSBWE-REMOVE
p.sequenceNumber++
@@ -82,6 +85,10 @@ func (p *packetTracker) RecordPacketSendAndGetSequenceNumber(
p.piLastRecv = nil
}
if p.probeClusterId != ccutils.ProbeClusterIdInvalid && p.probeClusterId == pi.probeClusterId && pi.sequenceNumber > p.probeMaxSequenceNumber {
p.probeMaxSequenceNumber = pi.sequenceNumber
}
return uint16(pi.sequenceNumber)
}
@@ -137,3 +144,26 @@ func (p *packetTracker) getPacketInfoExisting(sn uint16) *packetInfo {
return nil
}
func (p *packetTracker) ProbeClusterStarting(probeClusterId ccutils.ProbeClusterId) {
p.lock.Lock()
defer p.lock.Unlock()
p.probeClusterId = probeClusterId
}
func (p *packetTracker) ProbeClusterDone(probeClusterId ccutils.ProbeClusterId) {
p.lock.Lock()
defer p.lock.Unlock()
if p.probeClusterId == probeClusterId {
p.probeClusterId = ccutils.ProbeClusterIdInvalid
}
}
func (p *packetTracker) ProbeMaxSequenceNumber() uint64 {
p.lock.Lock()
defer p.lock.Unlock()
return p.probeMaxSequenceNumber
}
@@ -0,0 +1,132 @@
// Copyright 2023 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sendsidebwe
import (
"time"
"github.com/livekit/livekit-server/pkg/sfu/ccutils"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils/mono"
"go.uber.org/zap/zapcore"
)
// -------------------------------------------------------------
type ProbePacketGroupConfig struct {
PacketGroup PacketGroupConfig `yaml:"packet_group,omitempty"`
SettleWaitNumRTT uint32 `yaml:"settle_wait_num_rtt,omitempty"`
SettleWaitMin time.Duration `yaml:"settle_wait_min,omitempty"`
SettleWaitMax time.Duration `yaml:"settle_wait_max,omitempty"`
}
var (
// large numbers to treat a probe packet group as one
DefaultPacketGroupConfigProbe = ProbePacketGroupConfig{
PacketGroup: PacketGroupConfig{
MinPackets: 16384,
MaxWindowDuration: time.Minute,
},
SettleWaitNumRTT: 10,
SettleWaitMin: 500 * time.Millisecond,
SettleWaitMax: 10 * time.Second,
}
)
// -------------------------------------------------------------
type probePacketGroupParams struct {
Config ProbePacketGroupConfig
WeightedLoss WeightedLossConfig
Logger logger.Logger
}
type probePacketGroup struct {
params probePacketGroupParams
pci ccutils.ProbeClusterInfo
*packetGroup
maxSequenceNumber uint64
doneAt time.Time
}
func newProbePacketGroup(params probePacketGroupParams, pci ccutils.ProbeClusterInfo) *probePacketGroup {
return &probePacketGroup{
params: params,
pci: pci,
packetGroup: newPacketGroup(
packetGroupParams{
Config: params.Config.PacketGroup,
WeightedLoss: params.WeightedLoss,
Logger: params.Logger,
},
0,
),
}
}
func (p *probePacketGroup) ProbeClusterDone(pci ccutils.ProbeClusterInfo) {
if p.pci.Id != pci.Id {
return
}
p.pci.Result = pci.Result
p.doneAt = mono.Now()
}
func (p *probePacketGroup) MaybeFinalizeProbe(maxSequenceNumber uint64, rtt float64) (ccutils.ProbeClusterInfo, bool) {
if p.doneAt.IsZero() {
return ccutils.ProbeClusterInfoInvalid, false
}
if maxSequenceNumber != 0 && p.maxSequenceNumber >= maxSequenceNumber {
return p.pci, true
}
settleWait := time.Duration(float64(p.params.Config.SettleWaitNumRTT) * rtt * float64(time.Second))
if settleWait < p.params.Config.SettleWaitMin {
settleWait = p.params.Config.SettleWaitMin
}
if settleWait > p.params.Config.SettleWaitMax {
settleWait = p.params.Config.SettleWaitMax
}
if time.Since(p.doneAt) < settleWait {
return ccutils.ProbeClusterInfoInvalid, false
}
return p.pci, true
}
func (p *probePacketGroup) Add(pi *packetInfo, sendDelta, recvDelta int64, isLost bool) error {
if !p.doneAt.IsZero() || pi.probeClusterId != p.pci.Id {
return nil
}
p.maxSequenceNumber = max(p.maxSequenceNumber, pi.sequenceNumber)
return p.packetGroup.Add(pi, sendDelta, recvDelta, isLost)
}
func (p *probePacketGroup) MarshalLogObject(e zapcore.ObjectEncoder) error {
if p == nil {
return nil
}
e.AddObject("pci", p.pci)
e.AddObject("packetGroup", p.packetGroup)
e.AddUint64("maxSequenceNumber", p.maxSequenceNumber)
e.AddTime("doneAt", p.doneAt)
return nil
}
+35 -2
View File
@@ -15,7 +15,10 @@
package sendsidebwe
import (
"time"
"github.com/livekit/livekit-server/pkg/sfu/bwe"
"github.com/livekit/livekit-server/pkg/sfu/ccutils"
"github.com/livekit/protocol/logger"
"github.com/pion/rtcp"
)
@@ -100,12 +103,42 @@ func (s *SendSideBWE) Stop() {
s.congestionDetector.Stop()
}
func (s *SendSideBWE) RecordPacketSendAndGetSequenceNumber(
atMicro int64,
size int,
isRTX bool,
probeClusterId ccutils.ProbeClusterId,
isProbe bool,
) uint16 {
return s.congestionDetector.RecordPacketSendAndGetSequenceNumber(atMicro, size, isRTX, probeClusterId, isProbe)
}
func (s *SendSideBWE) HandleTWCCFeedback(report *rtcp.TransportLayerCC) {
s.congestionDetector.HandleTWCCFeedback(report)
}
func (s *SendSideBWE) CongestionState() bwe.CongestionState {
return s.congestionDetector.CongestionState()
func (s *SendSideBWE) UpdateRTT(rtt float64) {
s.congestionDetector.UpdateRTT(rtt)
}
func (s *SendSideBWE) CanProbe() bool {
return s.congestionDetector.CanProbe()
}
func (s *SendSideBWE) ProbeDuration() time.Duration {
return s.congestionDetector.ProbeDuration()
}
func (s *SendSideBWE) ProbeClusterStarting(pci ccutils.ProbeClusterInfo) {
s.congestionDetector.ProbeClusterStarting(pci)
}
func (s *SendSideBWE) ProbeClusterDone(pci ccutils.ProbeClusterInfo) {
s.congestionDetector.ProbeClusterDone(pci)
}
func (s *SendSideBWE) ProbeClusterFinalize() (ccutils.ProbeSignal, int64, bool) {
return s.congestionDetector.ProbeClusterFinalize()
}
// ------------------------------------------------
+15 -4
View File
@@ -53,6 +53,7 @@ type trafficStats struct {
ackedPackets int
ackedBytes int
lostPackets int
lostBytes int
}
func newTrafficStats(params trafficStatsParams) *trafficStats {
@@ -73,6 +74,11 @@ func (ts *trafficStats) Merge(rhs *trafficStats) {
ts.ackedPackets += rhs.ackedPackets
ts.ackedBytes += rhs.ackedBytes
ts.lostPackets += rhs.lostPackets
ts.lostBytes += rhs.lostBytes
}
func (ts *trafficStats) NumBytes() int {
return ts.ackedBytes + ts.lostBytes
}
func (ts *trafficStats) Duration() int64 {
@@ -80,6 +86,11 @@ func (ts *trafficStats) Duration() int64 {
}
func (ts *trafficStats) AcknowledgedBitrate() int64 {
duration := ts.Duration()
if duration == 0 {
return 0
}
ackedBitrate := int64(ts.ackedBytes) * 8 * 1e6 / ts.Duration()
return int64(float64(ackedBitrate) * ts.CapturedTrafficRatio())
}
@@ -112,10 +123,10 @@ func (ts *trafficStats) WeightedLoss() float64 {
pps := totalPackets * 1e6 / float64(ts.Duration())
// Log10 is used to give higher weight for the same loss ratio at higher packet rates,
// for e.g. with a penalty factor of 0.25
// - 10% loss at 20 pps = 0.1 * log10(20) * 0.25 = 0.032
// - 10% loss at 100 pps = 0.1 * log10(100) * 0.25 = 0.05
// - 10% loss at 1000 pps = 0.1 * log10(1000) * 0.25 = 0.075
// for e.g.
// - 10% loss at 20 pps = 0.1 * log10(20) = 0.130
// - 10% loss at 100 pps = 0.1 * log10(100) = 0.2
// - 10% loss at 1000 pps = 0.1 * log10(1000) = 0.3
return lossRatio * math.Log10(pps)
}
+2 -2
View File
@@ -66,7 +66,7 @@ func newTWCCFeedback(params twccFeedbackParams) *twccFeedback {
}
func (t *twccFeedback) ProcessReport(report *rtcp.TransportLayerCC, at time.Time) (int64, bool) {
// SSBWE-REMOVE t.params.Logger.Infow("TWCC feedback", "report", report.String()) // SSBWE-REMOVE
// t.params.Logger.Infow("send side bwe: TWCC feedback", "report", report.String()) // SSBWE-REMOVE
t.numReports++
if t.lastFeedbackTime.IsZero() {
t.lastFeedbackTime = at
@@ -99,7 +99,7 @@ func (t *twccFeedback) ProcessReport(report *rtcp.TransportLayerCC, at time.Time
if !isOutOfOrder {
sinceLast := at.Sub(t.lastFeedbackTime)
// SSBWE-REMOVE t.params.Logger.Infow("report received", "at", at, "sinceLast", sinceLast, "pktCount", report.FbPktCount) // SSBWE-REMOVE
// t.params.Logger.Infow("send side bwe: report received", "at", at, "sinceLast", sinceLast, "pktCount", report.FbPktCount) // SSBWE-REMOVE
if t.estimatedFeedbackInterval == 0 {
t.estimatedFeedbackInterval = sinceLast
} else {