Throughput optimizations
This commit is contained in:
parent
5547895dcb
commit
246c2ce89c
3 changed files with 46 additions and 4 deletions
2
go.mod
2
go.mod
|
|
@ -6,4 +6,4 @@ require github.com/golang/protobuf v1.3.1
|
|||
|
||||
require github.com/lucas-clemente/quic-go v0.15.2
|
||||
|
||||
replace github.com/lucas-clemente/quic-go => github.com/tobyxdd/quic-go v0.1.1-tquic-1
|
||||
replace github.com/lucas-clemente/quic-go => github.com/tobyxdd/quic-go v0.1.2-tquic-1
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -115,8 +115,8 @@ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod
|
|||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||
github.com/tobyxdd/quic-go v0.1.1-tquic-1 h1:KDhDFNe+IlI+ZOvEG6wA5JcNq8OUO029OYi8bq7XnSU=
|
||||
github.com/tobyxdd/quic-go v0.1.1-tquic-1/go.mod h1:qxmO5Y4ZMhdNkunGfxuZnZXnJwYpW9vjQkyrZ7BsgUI=
|
||||
github.com/tobyxdd/quic-go v0.1.2-tquic-1 h1:PPbkQyNNlI2ZXFWDspBGvOTXAWTX/y82mVy+kDzKtgY=
|
||||
github.com/tobyxdd/quic-go v0.1.2-tquic-1/go.mod h1:qxmO5Y4ZMhdNkunGfxuZnZXnJwYpW9vjQkyrZ7BsgUI=
|
||||
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
|
||||
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
|
||||
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
|
||||
|
|
|
|||
|
|
@ -5,11 +5,22 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ackRateMinSampleInterval = 4 * time.Second
|
||||
ackRateMaxSampleInterval = 20 * time.Second
|
||||
ackRateMinACKSampleCount = 200
|
||||
)
|
||||
|
||||
// BrutalSender sends packets at a constant rate and does not react to any changes in the network environment,
|
||||
// hence the name.
|
||||
type BrutalSender struct {
|
||||
rttStats *congestion.RTTStats
|
||||
bps congestion.ByteCount
|
||||
|
||||
ackCount, lossCount uint64
|
||||
ackRate float64
|
||||
ackRateNextUpdateMin time.Time
|
||||
ackRateNextUpdateMax time.Time
|
||||
}
|
||||
|
||||
func NewBrutalSender(bps congestion.ByteCount) *BrutalSender {
|
||||
|
|
@ -27,7 +38,13 @@ func (b *BrutalSender) TimeUntilSend(bytesInFlight congestion.ByteCount) time.Du
|
|||
}
|
||||
|
||||
func (b *BrutalSender) CanSend(bytesInFlight congestion.ByteCount) bool {
|
||||
return bytesInFlight < b.GetCongestionWindow()
|
||||
if b.ackRate == 0 {
|
||||
return bytesInFlight < b.GetCongestionWindow()
|
||||
} else if b.ackRate > 0.5 {
|
||||
return bytesInFlight < congestion.ByteCount(float64(b.GetCongestionWindow())/b.ackRate)
|
||||
} else {
|
||||
return bytesInFlight < b.GetCongestionWindow()*2
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BrutalSender) GetCongestionWindow() congestion.ByteCount {
|
||||
|
|
@ -44,10 +61,35 @@ func (b *BrutalSender) OnPacketSent(sentTime time.Time, bytesInFlight congestion
|
|||
|
||||
func (b *BrutalSender) OnPacketAcked(number congestion.PacketNumber, ackedBytes congestion.ByteCount,
|
||||
priorInFlight congestion.ByteCount, eventTime time.Time) {
|
||||
b.ackCount += 1
|
||||
b.maybeUpdateACKRate()
|
||||
}
|
||||
|
||||
func (b *BrutalSender) OnPacketLost(number congestion.PacketNumber, lostBytes congestion.ByteCount,
|
||||
priorInFlight congestion.ByteCount) {
|
||||
b.lossCount += 1
|
||||
b.maybeUpdateACKRate()
|
||||
}
|
||||
|
||||
func (b *BrutalSender) maybeUpdateACKRate() {
|
||||
now := time.Now()
|
||||
if !now.After(b.ackRateNextUpdateMin) {
|
||||
return
|
||||
}
|
||||
// Min interval reached
|
||||
if b.ackCount >= ackRateMinACKSampleCount {
|
||||
b.ackRate = float64(b.ackCount) / float64(b.ackCount+b.lossCount)
|
||||
b.ackCount, b.lossCount = 0, 0
|
||||
b.ackRateNextUpdateMin = now.Add(ackRateMinSampleInterval)
|
||||
b.ackRateNextUpdateMax = now.Add(ackRateMaxSampleInterval)
|
||||
} else {
|
||||
if now.After(b.ackRateNextUpdateMax) {
|
||||
// Max interval reached, still not enough samples, reset
|
||||
b.ackCount, b.lossCount = 0, 0
|
||||
b.ackRateNextUpdateMin = now.Add(ackRateMinSampleInterval)
|
||||
b.ackRateNextUpdateMax = now.Add(ackRateMaxSampleInterval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BrutalSender) InSlowStart() bool {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue