forked from quic-go/quic-go
Merge pull request #2591 from lucas-clemente/reduce-flowcontrol-time-now-calls
reduce calls to time.Now() from the flow controller
This commit is contained in:
@@ -68,7 +68,7 @@ func (c *baseFlowController) AddBytesRead(n protocol.ByteCount) {
|
|||||||
// pretend we sent a WindowUpdate when reading the first byte
|
// pretend we sent a WindowUpdate when reading the first byte
|
||||||
// this way auto-tuning of the window size already works for the first WindowUpdate
|
// this way auto-tuning of the window size already works for the first WindowUpdate
|
||||||
if c.bytesRead == 0 {
|
if c.bytesRead == 0 {
|
||||||
c.startNewAutoTuningEpoch()
|
c.startNewAutoTuningEpoch(time.Now())
|
||||||
}
|
}
|
||||||
c.bytesRead += n
|
c.bytesRead += n
|
||||||
}
|
}
|
||||||
@@ -105,15 +105,16 @@ func (c *baseFlowController) maybeAdjustWindowSize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fraction := float64(bytesReadInEpoch) / float64(c.receiveWindowSize)
|
fraction := float64(bytesReadInEpoch) / float64(c.receiveWindowSize)
|
||||||
if time.Since(c.epochStartTime) < time.Duration(4*fraction*float64(rtt)) {
|
now := time.Now()
|
||||||
|
if now.Sub(c.epochStartTime) < time.Duration(4*fraction*float64(rtt)) {
|
||||||
// window is consumed too fast, try to increase the window size
|
// window is consumed too fast, try to increase the window size
|
||||||
c.receiveWindowSize = utils.MinByteCount(2*c.receiveWindowSize, c.maxReceiveWindowSize)
|
c.receiveWindowSize = utils.MinByteCount(2*c.receiveWindowSize, c.maxReceiveWindowSize)
|
||||||
}
|
}
|
||||||
c.startNewAutoTuningEpoch()
|
c.startNewAutoTuningEpoch(now)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *baseFlowController) startNewAutoTuningEpoch() {
|
func (c *baseFlowController) startNewAutoTuningEpoch(now time.Time) {
|
||||||
c.epochStartTime = time.Now()
|
c.epochStartTime = now
|
||||||
c.epochStartOffset = c.bytesRead
|
c.epochStartOffset = c.bytesRead
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ var _ = Describe("Base Flow controller", func() {
|
|||||||
|
|
||||||
It("doesn't increase the window size when no RTT estimate is available", func() {
|
It("doesn't increase the window size when no RTT estimate is available", func() {
|
||||||
setRtt(0)
|
setRtt(0)
|
||||||
controller.startNewAutoTuningEpoch()
|
controller.startNewAutoTuningEpoch(time.Now())
|
||||||
controller.AddBytesRead(400)
|
controller.AddBytesRead(400)
|
||||||
offset := controller.getWindowUpdate()
|
offset := controller.getWindowUpdate()
|
||||||
Expect(offset).ToNot(BeZero()) // make sure a window update is sent
|
Expect(offset).ToNot(BeZero()) // make sure a window update is sent
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package flowcontrol
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/congestion"
|
"github.com/lucas-clemente/quic-go/internal/congestion"
|
||||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||||
@@ -86,7 +87,7 @@ func (c *connectionFlowController) EnsureMinimumWindowSize(inc protocol.ByteCoun
|
|||||||
if inc > c.receiveWindowSize {
|
if inc > c.receiveWindowSize {
|
||||||
c.logger.Debugf("Increasing receive flow control window for the connection to %d kB, in response to stream flow control window increase", c.receiveWindowSize/(1<<10))
|
c.logger.Debugf("Increasing receive flow control window for the connection to %d kB, in response to stream flow control window increase", c.receiveWindowSize/(1<<10))
|
||||||
c.receiveWindowSize = utils.MinByteCount(inc, c.maxReceiveWindowSize)
|
c.receiveWindowSize = utils.MinByteCount(inc, c.maxReceiveWindowSize)
|
||||||
c.startNewAutoTuningEpoch()
|
c.startNewAutoTuningEpoch(time.Now())
|
||||||
}
|
}
|
||||||
c.mutex.Unlock()
|
c.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user