diff --git a/flowcontrol/flow_controller.go b/flowcontrol/flow_controller.go index 6a0d38556..5ec0f89df 100644 --- a/flowcontrol/flow_controller.go +++ b/flowcontrol/flow_controller.go @@ -119,6 +119,11 @@ func (c *flowController) IncrementHighestReceived(increment protocol.ByteCount) } func (c *flowController) AddBytesRead(n protocol.ByteCount) { + // pretend we sent a WindowUpdate when reading the first byte + // this way auto-tuning of the window increment already works for the first WindowUpdate + if c.bytesRead == 0 { + c.lastWindowUpdateTime = time.Now() + } c.bytesRead += n } diff --git a/flowcontrol/flow_controller_test.go b/flowcontrol/flow_controller_test.go index 1c822997c..8700a1499 100644 --- a/flowcontrol/flow_controller_test.go +++ b/flowcontrol/flow_controller_test.go @@ -316,7 +316,7 @@ var _ = Describe("Flow controller", func() { It("returns the new increment when updating the window", func() { setRtt(10 * time.Millisecond) - controller.bytesRead = 9900 // receive window is 10000 + controller.AddBytesRead(9900) // receive window is 10000 controller.lastWindowUpdateTime = time.Now().Add(-19 * time.Millisecond) necessary, newIncrement, offset := controller.MaybeUpdateWindow() Expect(necessary).To(BeTrue()) @@ -325,9 +325,26 @@ var _ = Describe("Flow controller", func() { Expect(offset).To(Equal(protocol.ByteCount(9900 + newIncrement))) }) + It("increases the increment sent in the first WindowUpdate, if data is read fast enough", func() { + setRtt(10 * time.Millisecond) + controller.AddBytesRead(9900) + necessary, newIncrement, _ := controller.MaybeUpdateWindow() + Expect(necessary).To(BeTrue()) + Expect(newIncrement).To(Equal(2 * oldIncrement)) + }) + + It("doesn't increamse the increment sent in the first WindowUpdate, if data is read slowly", func() { + setRtt(2 * time.Millisecond) + controller.AddBytesRead(9900) + time.Sleep(5 * time.Millisecond) // more than 2x RTT + necessary, newIncrement, _ := controller.MaybeUpdateWindow() + Expect(necessary).To(BeTrue()) + Expect(newIncrement).To(BeZero()) + }) + It("only returns the increment if it was increased", func() { setRtt(10 * time.Millisecond) - controller.bytesRead = 9900 // receive window is 10000 + controller.AddBytesRead(9900) // receive window is 10000 controller.lastWindowUpdateTime = time.Now().Add(-21 * time.Millisecond) necessary, newIncrement, offset := controller.MaybeUpdateWindow() Expect(necessary).To(BeTrue())