Fix (hopefully) state transition. (#3375)
My previous PR was trying to fix a premature transition from CONGESTED -> NONE state. But, that introduced a bug which accelerated the transition from EARLY_WARNING -> CONGESTED state due to holding the `queuingRegion` state variable. Fix by not holding `queuingRegion` in state and take result of processing runs. NOTE: This can still use some work to make the state machine cleaner. Initially, I was passing around a bunch of variables which was uncouth. Then moved things to state which made code easier to read and also log different things, but it causes problems like the ones above. Will take another look and think more about making it more robust.
This commit is contained in:
@@ -509,7 +509,6 @@ type congestionDetector struct {
|
|||||||
congestedTrafficStats *trafficStats
|
congestedTrafficStats *trafficStats
|
||||||
congestedPacketGroup *packetGroup
|
congestedPacketGroup *packetGroup
|
||||||
|
|
||||||
queuingRegion queuingRegion
|
|
||||||
congestionReason congestionReason
|
congestionReason congestionReason
|
||||||
qdMeasurement *qdMeasurement
|
qdMeasurement *qdMeasurement
|
||||||
lossMeasurement *lossMeasurement
|
lossMeasurement *lossMeasurement
|
||||||
@@ -550,7 +549,6 @@ func (c *congestionDetector) Reset() {
|
|||||||
|
|
||||||
c.clearCTRTrend()
|
c.clearCTRTrend()
|
||||||
|
|
||||||
c.queuingRegion = queuingRegionIndeterminate
|
|
||||||
c.congestionReason = congestionReasonNone
|
c.congestionReason = congestionReasonNone
|
||||||
c.qdMeasurement = nil
|
c.qdMeasurement = nil
|
||||||
c.lossMeasurement = nil
|
c.lossMeasurement = nil
|
||||||
@@ -849,7 +847,7 @@ func (c *congestionDetector) updateCongestionSignal(
|
|||||||
qdDQRConfig CongestionSignalConfig,
|
qdDQRConfig CongestionSignalConfig,
|
||||||
lossJQRConfig CongestionSignalConfig,
|
lossJQRConfig CongestionSignalConfig,
|
||||||
lossDQRConfig CongestionSignalConfig,
|
lossDQRConfig CongestionSignalConfig,
|
||||||
) {
|
) queuingRegion {
|
||||||
c.qdMeasurement = newQDMeasurement(
|
c.qdMeasurement = newQDMeasurement(
|
||||||
qdJQRConfig,
|
qdJQRConfig,
|
||||||
qdDQRConfig,
|
qdDQRConfig,
|
||||||
@@ -877,23 +875,26 @@ func (c *congestionDetector) updateCongestionSignal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qr := queuingRegionIndeterminate
|
||||||
qdQueuingRegion := c.qdMeasurement.QueuingRegion()
|
qdQueuingRegion := c.qdMeasurement.QueuingRegion()
|
||||||
lossQueuingRegion := c.lossMeasurement.QueuingRegion()
|
lossQueuingRegion := c.lossMeasurement.QueuingRegion()
|
||||||
switch {
|
switch {
|
||||||
case qdQueuingRegion == queuingRegionJQR:
|
case qdQueuingRegion == queuingRegionJQR:
|
||||||
c.queuingRegion = queuingRegionJQR
|
qr = queuingRegionJQR
|
||||||
c.congestionReason = congestionReasonQueuingDelay
|
c.congestionReason = congestionReasonQueuingDelay
|
||||||
case lossQueuingRegion == queuingRegionJQR:
|
case lossQueuingRegion == queuingRegionJQR:
|
||||||
c.queuingRegion = queuingRegionJQR
|
qr = queuingRegionJQR
|
||||||
c.congestionReason = congestionReasonLoss
|
c.congestionReason = congestionReasonLoss
|
||||||
case qdQueuingRegion == queuingRegionDQR && lossQueuingRegion == queuingRegionDQR:
|
case qdQueuingRegion == queuingRegionDQR && lossQueuingRegion == queuingRegionDQR:
|
||||||
c.queuingRegion = queuingRegionDQR
|
qr = queuingRegionDQR
|
||||||
c.congestionReason = congestionReasonNone
|
c.congestionReason = congestionReasonNone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return qr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *congestionDetector) updateEarlyWarningSignal() {
|
func (c *congestionDetector) updateEarlyWarningSignal() queuingRegion {
|
||||||
c.updateCongestionSignal(
|
return c.updateCongestionSignal(
|
||||||
c.params.Config.QueuingDelayEarlyWarningJQR,
|
c.params.Config.QueuingDelayEarlyWarningJQR,
|
||||||
c.params.Config.QueuingDelayEarlyWarningDQR,
|
c.params.Config.QueuingDelayEarlyWarningDQR,
|
||||||
c.params.Config.LossEarlyWarningJQR,
|
c.params.Config.LossEarlyWarningJQR,
|
||||||
@@ -901,8 +902,8 @@ func (c *congestionDetector) updateEarlyWarningSignal() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *congestionDetector) updateCongestedSignal() {
|
func (c *congestionDetector) updateCongestedSignal() queuingRegion {
|
||||||
c.updateCongestionSignal(
|
return c.updateCongestionSignal(
|
||||||
c.params.Config.QueuingDelayCongestedJQR,
|
c.params.Config.QueuingDelayCongestedJQR,
|
||||||
c.params.Config.QueuingDelayCongestedDQR,
|
c.params.Config.QueuingDelayCongestedDQR,
|
||||||
c.params.Config.LossCongestedJQR,
|
c.params.Config.LossCongestedJQR,
|
||||||
@@ -916,34 +917,26 @@ func (c *congestionDetector) congestionDetectionStateMachine() (bool, bwe.Conges
|
|||||||
|
|
||||||
switch fromState {
|
switch fromState {
|
||||||
case bwe.CongestionStateNone:
|
case bwe.CongestionStateNone:
|
||||||
c.updateEarlyWarningSignal()
|
if c.updateEarlyWarningSignal() == queuingRegionJQR {
|
||||||
if c.queuingRegion == queuingRegionJQR {
|
|
||||||
toState = bwe.CongestionStateEarlyWarning
|
toState = bwe.CongestionStateEarlyWarning
|
||||||
}
|
}
|
||||||
|
|
||||||
case bwe.CongestionStateEarlyWarning:
|
case bwe.CongestionStateEarlyWarning:
|
||||||
c.updateCongestedSignal()
|
if c.updateCongestedSignal() == queuingRegionJQR {
|
||||||
if c.queuingRegion == queuingRegionJQR {
|
|
||||||
toState = bwe.CongestionStateCongested
|
toState = bwe.CongestionStateCongested
|
||||||
} else {
|
} else if c.updateEarlyWarningSignal() == queuingRegionDQR {
|
||||||
c.updateEarlyWarningSignal()
|
toState = bwe.CongestionStateNone
|
||||||
if c.queuingRegion == queuingRegionDQR {
|
|
||||||
toState = bwe.CongestionStateNone
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case bwe.CongestionStateCongested:
|
case bwe.CongestionStateCongested:
|
||||||
c.updateCongestedSignal()
|
if c.updateCongestedSignal() == queuingRegionDQR {
|
||||||
if c.queuingRegion == queuingRegionDQR {
|
|
||||||
toState = bwe.CongestionStateNone
|
toState = bwe.CongestionStateNone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.estimateAvailableChannelCapacity()
|
|
||||||
|
|
||||||
// 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 {
|
||||||
|
c.estimateAvailableChannelCapacity()
|
||||||
fromState, toState = c.updateCongestionState(toState)
|
fromState, toState = c.updateCongestionState(toState)
|
||||||
shouldNotify = true
|
shouldNotify = true
|
||||||
}
|
}
|
||||||
@@ -1040,20 +1033,18 @@ func (c *congestionDetector) estimateAvailableChannelCapacity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// when in JQR, use contributing groups,
|
// when congested, use contributing groups,
|
||||||
// else use a time windowed measurement
|
// else use a time windowed measurement
|
||||||
useWindow := false
|
useWindow := false
|
||||||
isAggValid := true
|
isAggValid := true
|
||||||
minGroupIdx := 0
|
minGroupIdx := 0
|
||||||
maxGroupIdx := len(c.packetGroups) - 1
|
maxGroupIdx := len(c.packetGroups) - 1
|
||||||
if c.queuingRegion == queuingRegionJQR {
|
switch c.congestionReason {
|
||||||
switch c.congestionReason {
|
case congestionReasonQueuingDelay:
|
||||||
case congestionReasonQueuingDelay:
|
minGroupIdx, maxGroupIdx = c.qdMeasurement.GroupRange()
|
||||||
minGroupIdx, maxGroupIdx = c.qdMeasurement.GroupRange()
|
case congestionReasonLoss:
|
||||||
case congestionReasonLoss:
|
minGroupIdx, maxGroupIdx = c.lossMeasurement.GroupRange()
|
||||||
minGroupIdx, maxGroupIdx = c.lossMeasurement.GroupRange()
|
default:
|
||||||
}
|
|
||||||
} else {
|
|
||||||
useWindow = true
|
useWindow = true
|
||||||
isAggValid = false
|
isAggValid = false
|
||||||
}
|
}
|
||||||
@@ -1085,7 +1076,6 @@ func (c *congestionDetector) updateCongestionState(state bwe.CongestionState) (b
|
|||||||
loggingFields := []any{
|
loggingFields := []any{
|
||||||
"from", c.congestionState,
|
"from", c.congestionState,
|
||||||
"to", state,
|
"to", state,
|
||||||
"queuingRegion", c.queuingRegion,
|
|
||||||
"congestionReason", c.congestionReason,
|
"congestionReason", c.congestionReason,
|
||||||
"qdMeasurement", c.qdMeasurement,
|
"qdMeasurement", c.qdMeasurement,
|
||||||
"lossMeasurement", c.lossMeasurement,
|
"lossMeasurement", c.lossMeasurement,
|
||||||
@@ -1093,7 +1083,7 @@ func (c *congestionDetector) updateCongestionState(state bwe.CongestionState) (b
|
|||||||
"estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity,
|
"estimatedAvailableChannelCapacity", c.estimatedAvailableChannelCapacity,
|
||||||
"estimateTrafficStats", c.estimateTrafficStats,
|
"estimateTrafficStats", c.estimateTrafficStats,
|
||||||
}
|
}
|
||||||
if c.queuingRegion == queuingRegionJQR {
|
if c.congestionReason != congestionReasonNone {
|
||||||
var minGroupIdx, maxGroupIdx int
|
var minGroupIdx, maxGroupIdx int
|
||||||
switch c.congestionReason {
|
switch c.congestionReason {
|
||||||
case congestionReasonQueuingDelay:
|
case congestionReasonQueuingDelay:
|
||||||
|
|||||||
Reference in New Issue
Block a user