Keep more state for easier logging/debuggability (#3280)
This commit is contained in:
@@ -135,6 +135,28 @@ func (q queuingRegion) String() string {
|
|||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type congestionReason int
|
||||||
|
|
||||||
|
const (
|
||||||
|
congestionReasonNone congestionReason = iota
|
||||||
|
congestionReasonQueuingDelay
|
||||||
|
congestionReasonLoss
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c congestionReason) String() string {
|
||||||
|
switch c {
|
||||||
|
case congestionReasonNone:
|
||||||
|
return "NONE"
|
||||||
|
case congestionReasonQueuingDelay:
|
||||||
|
return "QUEUING_DELAY"
|
||||||
|
case congestionReasonLoss:
|
||||||
|
return "LOSS"
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("%d", int(c))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------
|
||||||
type qdMeasurement struct {
|
type qdMeasurement struct {
|
||||||
config CongestionSignalConfig
|
config CongestionSignalConfig
|
||||||
jqrMin int64
|
jqrMin int64
|
||||||
@@ -203,8 +225,12 @@ func (q *qdMeasurement) IsSealed() bool {
|
|||||||
return q.isSealed
|
return q.isSealed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qdMeasurement) Result() (queuingRegion, int, int) {
|
func (q *qdMeasurement) QueuingRegion() queuingRegion {
|
||||||
return q.queuingRegion, q.minGroupIdx, q.maxGroupIdx
|
return q.queuingRegion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *qdMeasurement) GroupRange() (int, int) {
|
||||||
|
return max(0, q.minGroupIdx), max(0, q.maxGroupIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qdMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
|
func (q *qdMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
|
||||||
@@ -292,8 +318,12 @@ func (l *lossMeasurement) IsSealed() bool {
|
|||||||
return l.isSealed
|
return l.isSealed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lossMeasurement) Result() (queuingRegion, int, int) {
|
func (l *lossMeasurement) QueuingRegion() queuingRegion {
|
||||||
return l.queuingRegion, l.minGroupIdx, l.maxGroupIdx
|
return l.queuingRegion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *lossMeasurement) GroupRange() (int, int) {
|
||||||
|
return max(0, l.minGroupIdx), max(0, l.maxGroupIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *lossMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
|
func (l *lossMeasurement) MarshalLogObject(e zapcore.ObjectEncoder) error {
|
||||||
@@ -339,6 +369,8 @@ type CongestionDetectorConfig struct {
|
|||||||
CongestedCTRTrend ccutils.TrendDetectorConfig `yaml:"congested_ctr_trend,omitempty"`
|
CongestedCTRTrend ccutils.TrendDetectorConfig `yaml:"congested_ctr_trend,omitempty"`
|
||||||
CongestedCTREpsilon float64 `yaml:"congested_ctr_epsilon,omitempty"`
|
CongestedCTREpsilon float64 `yaml:"congested_ctr_epsilon,omitempty"`
|
||||||
CongestedPacketGroup PacketGroupConfig `yaml:"congested_packet_group,omitempty"`
|
CongestedPacketGroup PacketGroupConfig `yaml:"congested_packet_group,omitempty"`
|
||||||
|
|
||||||
|
EstimationWindowDuration time.Duration `yaml:"estimaton_window_duration,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -382,6 +414,8 @@ var (
|
|||||||
CongestedCTRTrend: defaultTrendDetectorConfigCongestedCTR,
|
CongestedCTRTrend: defaultTrendDetectorConfigCongestedCTR,
|
||||||
CongestedCTREpsilon: 0.05,
|
CongestedCTREpsilon: 0.05,
|
||||||
CongestedPacketGroup: defaultCongestedPacketGroupConfig,
|
CongestedPacketGroup: defaultCongestedPacketGroupConfig,
|
||||||
|
|
||||||
|
EstimationWindowDuration: time.Second,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -408,13 +442,20 @@ type congestionDetector struct {
|
|||||||
probeRegulator *ccutils.ProbeRegulator
|
probeRegulator *ccutils.ProbeRegulator
|
||||||
|
|
||||||
estimatedAvailableChannelCapacity int64
|
estimatedAvailableChannelCapacity int64
|
||||||
congestionState bwe.CongestionState
|
estimateTrafficStats *trafficStats
|
||||||
congestionStateSwitchedAt time.Time
|
|
||||||
|
congestionState bwe.CongestionState
|
||||||
|
congestionStateSwitchedAt time.Time
|
||||||
|
|
||||||
congestedCTRTrend *ccutils.TrendDetector[float64]
|
congestedCTRTrend *ccutils.TrendDetector[float64]
|
||||||
congestedTrafficStats *trafficStats
|
congestedTrafficStats *trafficStats
|
||||||
congestedPacketGroup *packetGroup
|
congestedPacketGroup *packetGroup
|
||||||
|
|
||||||
|
queuingRegion queuingRegion
|
||||||
|
congestionReason congestionReason
|
||||||
|
jqrQDMeasurement *qdMeasurement
|
||||||
|
jqrLossMeasurement *lossMeasurement
|
||||||
|
|
||||||
bweListener bwe.BWEListener
|
bweListener bwe.BWEListener
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,16 +475,27 @@ func (c *congestionDetector) Reset() {
|
|||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
c.rtt = bwe.DefaultRTT
|
c.rtt = bwe.DefaultRTT
|
||||||
|
|
||||||
c.packetGroups = nil
|
c.packetGroups = nil
|
||||||
|
|
||||||
c.probePacketGroup = nil
|
c.probePacketGroup = nil
|
||||||
c.probeRegulator = ccutils.NewProbeRegulator(ccutils.ProbeRegulatorParams{
|
c.probeRegulator = ccutils.NewProbeRegulator(ccutils.ProbeRegulatorParams{
|
||||||
Config: c.params.Config.ProbeRegulator,
|
Config: c.params.Config.ProbeRegulator,
|
||||||
Logger: c.params.Logger,
|
Logger: c.params.Logger,
|
||||||
})
|
})
|
||||||
|
|
||||||
c.estimatedAvailableChannelCapacity = 100_000_000
|
c.estimatedAvailableChannelCapacity = 100_000_000
|
||||||
|
c.estimateTrafficStats = nil
|
||||||
|
|
||||||
c.congestionState = bwe.CongestionStateNone
|
c.congestionState = bwe.CongestionStateNone
|
||||||
c.congestionStateSwitchedAt = mono.Now()
|
c.congestionStateSwitchedAt = mono.Now()
|
||||||
|
|
||||||
c.clearCTRTrend()
|
c.clearCTRTrend()
|
||||||
|
|
||||||
|
c.queuingRegion = queuingRegionIndeterminate
|
||||||
|
c.congestionReason = congestionReasonNone
|
||||||
|
c.jqrQDMeasurement = nil
|
||||||
|
c.jqrLossMeasurement = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *congestionDetector) SetBWEListener(bweListener bwe.BWEListener) {
|
func (c *congestionDetector) SetBWEListener(bweListener bwe.BWEListener) {
|
||||||
@@ -735,11 +787,11 @@ func (c *congestionDetector) prunePacketGroups() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *congestionDetector) getCongestionSignal(
|
func (c *congestionDetector) updateCongestionSignal(
|
||||||
stage string,
|
stage string,
|
||||||
qdConfig CongestionSignalConfig,
|
qdConfig CongestionSignalConfig,
|
||||||
lossConfig CongestionSignalConfig,
|
lossConfig CongestionSignalConfig,
|
||||||
) (queuingRegion, string, int, int) {
|
) {
|
||||||
qdMeasurement := newQdMeasurement(
|
qdMeasurement := newQdMeasurement(
|
||||||
qdConfig,
|
qdConfig,
|
||||||
c.params.Config.JQRMinDelay.Microseconds(),
|
c.params.Config.JQRMinDelay.Microseconds(),
|
||||||
@@ -765,30 +817,33 @@ func (c *congestionDetector) getCongestionSignal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reason := ""
|
c.congestionReason = congestionReasonNone
|
||||||
qr, minGroupIdx, maxGroupIdx := qdMeasurement.Result()
|
c.queuingRegion = qdMeasurement.QueuingRegion()
|
||||||
if qr == queuingRegionJQR {
|
if c.queuingRegion == queuingRegionJQR {
|
||||||
reason = "queuing-delay"
|
c.congestionReason = congestionReasonQueuingDelay
|
||||||
|
c.jqrQDMeasurement = qdMeasurement
|
||||||
} else {
|
} else {
|
||||||
qr, minGroupIdx, maxGroupIdx = lossMeasurement.Result()
|
c.jqrQDMeasurement = nil
|
||||||
if qr == queuingRegionJQR {
|
c.queuingRegion = lossMeasurement.QueuingRegion()
|
||||||
reason = "loss"
|
if c.queuingRegion == queuingRegionJQR {
|
||||||
|
c.congestionReason = congestionReasonLoss
|
||||||
|
c.jqrLossMeasurement = lossMeasurement
|
||||||
|
} else {
|
||||||
|
c.jqrLossMeasurement = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return qr, reason, max(0, minGroupIdx), max(0, maxGroupIdx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *congestionDetector) getEarlyWarningSignal() (queuingRegion, string, int, int) {
|
func (c *congestionDetector) updateEarlyWarningSignal() {
|
||||||
return c.getCongestionSignal(
|
c.updateCongestionSignal(
|
||||||
"early-warning",
|
"early-warning",
|
||||||
c.params.Config.QueuingDelayEarlyWarning,
|
c.params.Config.QueuingDelayEarlyWarning,
|
||||||
c.params.Config.LossEarlyWarning,
|
c.params.Config.LossEarlyWarning,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *congestionDetector) getCongestedSignal() (queuingRegion, string, int, int) {
|
func (c *congestionDetector) updateCongestedSignal() {
|
||||||
return c.getCongestionSignal(
|
c.updateCongestionSignal(
|
||||||
"congested",
|
"congested",
|
||||||
c.params.Config.QueuingDelayCongested,
|
c.params.Config.QueuingDelayCongested,
|
||||||
c.params.Config.LossCongested,
|
c.params.Config.LossCongested,
|
||||||
@@ -799,58 +854,53 @@ func (c *congestionDetector) congestionDetectionStateMachine() (bool, bwe.Conges
|
|||||||
fromState := c.congestionState
|
fromState := c.congestionState
|
||||||
toState := c.congestionState
|
toState := c.congestionState
|
||||||
|
|
||||||
var (
|
|
||||||
qr queuingRegion
|
|
||||||
reason string
|
|
||||||
minGroupIdx, maxGroupIdx int
|
|
||||||
)
|
|
||||||
switch fromState {
|
switch fromState {
|
||||||
case bwe.CongestionStateNone:
|
case bwe.CongestionStateNone:
|
||||||
qr, reason, minGroupIdx, maxGroupIdx = c.getEarlyWarningSignal()
|
c.updateEarlyWarningSignal()
|
||||||
if qr == queuingRegionJQR {
|
if c.queuingRegion == queuingRegionJQR {
|
||||||
toState = bwe.CongestionStateEarlyWarning
|
toState = bwe.CongestionStateEarlyWarning
|
||||||
}
|
}
|
||||||
|
|
||||||
case bwe.CongestionStateEarlyWarning:
|
case bwe.CongestionStateEarlyWarning:
|
||||||
qr, reason, minGroupIdx, maxGroupIdx = c.getCongestedSignal()
|
c.updateCongestedSignal()
|
||||||
if qr == queuingRegionJQR {
|
if c.queuingRegion == queuingRegionJQR {
|
||||||
toState = bwe.CongestionStateCongested
|
toState = bwe.CongestionStateCongested
|
||||||
} else {
|
} else {
|
||||||
qr, reason, minGroupIdx, maxGroupIdx = c.getEarlyWarningSignal()
|
c.updateEarlyWarningSignal()
|
||||||
if qr == queuingRegionDQR {
|
if c.queuingRegion == queuingRegionDQR {
|
||||||
toState = bwe.CongestionStateEarlyWarningHangover
|
toState = bwe.CongestionStateEarlyWarningHangover
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case bwe.CongestionStateEarlyWarningHangover:
|
case bwe.CongestionStateEarlyWarningHangover:
|
||||||
qr, reason, minGroupIdx, maxGroupIdx = c.getEarlyWarningSignal()
|
c.updateEarlyWarningSignal()
|
||||||
if qr == queuingRegionJQR {
|
if c.queuingRegion == queuingRegionJQR {
|
||||||
toState = 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 {
|
||||||
toState = bwe.CongestionStateNone
|
toState = bwe.CongestionStateNone
|
||||||
}
|
}
|
||||||
|
|
||||||
case bwe.CongestionStateCongested:
|
case bwe.CongestionStateCongested:
|
||||||
qr, reason, minGroupIdx, maxGroupIdx = c.getCongestedSignal()
|
c.updateCongestedSignal()
|
||||||
if qr == queuingRegionDQR {
|
if c.queuingRegion == queuingRegionDQR {
|
||||||
toState = bwe.CongestionStateCongestedHangover
|
toState = bwe.CongestionStateCongestedHangover
|
||||||
}
|
}
|
||||||
|
|
||||||
case bwe.CongestionStateCongestedHangover:
|
case bwe.CongestionStateCongestedHangover:
|
||||||
qr, reason, minGroupIdx, maxGroupIdx = c.getEarlyWarningSignal()
|
c.updateEarlyWarningSignal()
|
||||||
if qr == queuingRegionJQR {
|
if c.queuingRegion == queuingRegionJQR {
|
||||||
toState = 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 {
|
||||||
toState = bwe.CongestionStateNone
|
toState = bwe.CongestionStateNone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.estimateAvailableChannelCapacity(minGroupIdx)
|
c.estimateAvailableChannelCapacity()
|
||||||
|
|
||||||
// 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 toState != fromState {
|
if toState != fromState {
|
||||||
fromState, toState = c.updateCongestionState(toState, reason, minGroupIdx, maxGroupIdx)
|
fromState, toState = c.updateCongestionState(toState)
|
||||||
shouldNotify = true
|
shouldNotify = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -941,39 +991,71 @@ func (c *congestionDetector) updateCTRTrend(pi *packetInfo, sendDelta, recvDelta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *congestionDetector) estimateAvailableChannelCapacity(oldestContributingGroup int) {
|
func (c *congestionDetector) estimateAvailableChannelCapacity() {
|
||||||
if len(c.packetGroups) == 0 || c.congestedCTRTrend != nil || c.probePacketGroup != nil {
|
if len(c.packetGroups) == 0 || c.congestedCTRTrend != nil || c.probePacketGroup != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when in JQR, use contributing groups,
|
||||||
|
// else use a time windowed measurement
|
||||||
|
useWindow := false
|
||||||
|
isAggValid := true
|
||||||
|
minGroupIdx := 0
|
||||||
|
if c.jqrQDMeasurement != nil {
|
||||||
|
minGroupIdx, _ = c.jqrQDMeasurement.GroupRange()
|
||||||
|
} else if c.jqrLossMeasurement != nil {
|
||||||
|
minGroupIdx, _ = c.jqrLossMeasurement.GroupRange()
|
||||||
|
} else {
|
||||||
|
useWindow = true
|
||||||
|
isAggValid = false
|
||||||
|
}
|
||||||
|
|
||||||
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 >= oldestContributingGroup; idx-- {
|
for idx := len(c.packetGroups) - 1; idx >= minGroupIdx; idx-- {
|
||||||
pg := c.packetGroups[idx]
|
pg := c.packetGroups[idx]
|
||||||
if !pg.IsFinalized() {
|
if !pg.IsFinalized() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
agg.Merge(pg.Traffic())
|
agg.Merge(pg.Traffic())
|
||||||
|
if useWindow && agg.Duration() > c.params.Config.EstimationWindowDuration.Microseconds() {
|
||||||
|
isAggValid = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.estimatedAvailableChannelCapacity = agg.AcknowledgedBitrate()
|
if isAggValid {
|
||||||
|
c.estimatedAvailableChannelCapacity = agg.AcknowledgedBitrate()
|
||||||
|
c.estimateTrafficStats = agg
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *congestionDetector) updateCongestionState(state bwe.CongestionState, reason string, minGroupIdx int, maxGroupIdx int) (bwe.CongestionState, bwe.CongestionState) {
|
func (c *congestionDetector) updateCongestionState(state bwe.CongestionState) (bwe.CongestionState, bwe.CongestionState) {
|
||||||
loggingFields := []any{
|
loggingFields := []any{
|
||||||
"from", c.congestionState,
|
"from", c.congestionState,
|
||||||
"to", state,
|
"to", state,
|
||||||
"reason", reason,
|
"queuingRegion", c.queuingRegion,
|
||||||
|
"congestionReason", c.congestionReason,
|
||||||
"numPacketGroups", len(c.packetGroups),
|
"numPacketGroups", len(c.packetGroups),
|
||||||
"minGroupIdx", minGroupIdx,
|
|
||||||
"maxGroupIdx", maxGroupIdx,
|
|
||||||
"estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity,
|
"estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity,
|
||||||
|
"estimateTrafficStats", c.estimateTrafficStats,
|
||||||
}
|
}
|
||||||
if state == bwe.CongestionStateEarlyWarning || state == bwe.CongestionStateCongested {
|
if c.queuingRegion == queuingRegionJQR {
|
||||||
loggingFields = append(loggingFields, "contributingGroups", logger.ObjectSlice(c.packetGroups[minGroupIdx:maxGroupIdx+1]))
|
var minGroupIdx, maxGroupIdx int
|
||||||
|
if c.jqrQDMeasurement != nil {
|
||||||
|
minGroupIdx, maxGroupIdx = c.jqrQDMeasurement.GroupRange()
|
||||||
|
} else if c.jqrLossMeasurement != nil {
|
||||||
|
minGroupIdx, maxGroupIdx = c.jqrLossMeasurement.GroupRange()
|
||||||
|
}
|
||||||
|
loggingFields = append(
|
||||||
|
loggingFields,
|
||||||
|
"jqrQDMeasurement", c.jqrQDMeasurement,
|
||||||
|
"jqrLossMeasurement", c.jqrLossMeasurement,
|
||||||
|
"contributingGroups", logger.ObjectSlice(c.packetGroups[minGroupIdx:maxGroupIdx+1]),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
c.params.Logger.Infow("send side bwe: congestion state change", loggingFields...)
|
c.params.Logger.Infow("send side bwe: congestion state change", loggingFields...)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user