mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-08 21:39:53 +00:00
fix: BBR bandwidth estimation edge case
This commit is contained in:
parent
282ec2a0c5
commit
89429598bf
@ -21,6 +21,8 @@ import (
|
|||||||
//
|
//
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
minBps = 65536 // 64 kbps
|
||||||
|
|
||||||
invalidPacketNumber = -1
|
invalidPacketNumber = -1
|
||||||
initialCongestionWindowPackets = 32
|
initialCongestionWindowPackets = 32
|
||||||
|
|
||||||
@ -283,10 +285,7 @@ func newBbrSender(
|
|||||||
maxCongestionWindowWithNetworkParametersAdjusted: initialMaxCongestionWindow,
|
maxCongestionWindowWithNetworkParametersAdjusted: initialMaxCongestionWindow,
|
||||||
maxDatagramSize: initialMaxDatagramSize,
|
maxDatagramSize: initialMaxDatagramSize,
|
||||||
}
|
}
|
||||||
b.pacer = common.NewPacer(func() congestion.ByteCount {
|
b.pacer = common.NewPacer(b.bandwidthForPacer)
|
||||||
// Pacer wants bytes per second, but Bandwidth is in bits per second.
|
|
||||||
return congestion.ByteCount(float64(b.bandwidthEstimate()) * b.congestionWindowGain / float64(BytesPerSecond))
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if b.tracer != nil {
|
if b.tracer != nil {
|
||||||
@ -536,6 +535,17 @@ func (b *bbrSender) bandwidthEstimate() Bandwidth {
|
|||||||
return b.maxBandwidth.GetBest()
|
return b.maxBandwidth.GetBest()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *bbrSender) bandwidthForPacer() congestion.ByteCount {
|
||||||
|
bps := congestion.ByteCount(float64(b.bandwidthEstimate()) * b.congestionWindowGain / float64(BytesPerSecond))
|
||||||
|
if bps < minBps {
|
||||||
|
// We need to make sure that the bandwidth value for pacer is never zero,
|
||||||
|
// otherwise it will go into an edge case where HasPacingBudget = false
|
||||||
|
// but TimeUntilSend is before, causing the quic-go send loop to go crazy and get stuck.
|
||||||
|
return minBps
|
||||||
|
}
|
||||||
|
return bps
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the current estimate of the RTT of the connection. Outside of the
|
// Returns the current estimate of the RTT of the connection. Outside of the
|
||||||
// edge cases, this is minimum RTT.
|
// edge cases, this is minimum RTT.
|
||||||
func (b *bbrSender) getMinRtt() time.Duration {
|
func (b *bbrSender) getMinRtt() time.Duration {
|
||||||
|
@ -43,6 +43,9 @@ func (p *Pacer) Budget(now time.Time) congestion.ByteCount {
|
|||||||
return p.maxBurstSize()
|
return p.maxBurstSize()
|
||||||
}
|
}
|
||||||
budget := p.budgetAtLastSent + (p.getBandwidth()*congestion.ByteCount(now.Sub(p.lastSentTime).Nanoseconds()))/1e9
|
budget := p.budgetAtLastSent + (p.getBandwidth()*congestion.ByteCount(now.Sub(p.lastSentTime).Nanoseconds()))/1e9
|
||||||
|
if budget < 0 { // protect against overflows
|
||||||
|
budget = congestion.ByteCount(1<<62 - 1)
|
||||||
|
}
|
||||||
return minByteCount(p.maxBurstSize(), budget)
|
return minByteCount(p.maxBurstSize(), budget)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user