rewrite flow control auto-tuning

This commit is contained in:
Marten Seemann
2017-12-21 15:29:47 +07:00
parent ac05343b00
commit f7526b9883
5 changed files with 118 additions and 78 deletions

View File

@@ -48,21 +48,31 @@ var _ = Describe("Connection Flow controller", func() {
controller.receiveWindow = 100
controller.receiveWindowSize = 60
controller.maxReceiveWindowSize = 1000
controller.bytesRead = 100 - 60
})
It("gets a window update", func() {
controller.AddBytesRead(80)
windowSize := controller.receiveWindowSize
oldOffset := controller.bytesRead
dataRead := windowSize/2 - 1 // make sure not to trigger auto-tuning
controller.AddBytesRead(dataRead)
offset := controller.GetWindowUpdate()
Expect(offset).To(Equal(protocol.ByteCount(80 + 60)))
Expect(offset).To(Equal(protocol.ByteCount(oldOffset + dataRead + 60)))
})
It("autotunes the window", func() {
controller.AddBytesRead(80)
oldOffset := controller.bytesRead
oldWindowSize := controller.receiveWindowSize
rtt := 20 * time.Millisecond
setRtt(rtt)
controller.lastWindowUpdateTime = time.Now().Add(-4*protocol.WindowUpdateThreshold*rtt + time.Millisecond)
controller.epochStartTime = time.Now().Add(-time.Millisecond)
controller.epochStartOffset = oldOffset
dataRead := oldWindowSize/2 + 1
controller.AddBytesRead(dataRead)
offset := controller.GetWindowUpdate()
Expect(offset).To(Equal(protocol.ByteCount(80 + 2*60)))
newWindowSize := controller.receiveWindowSize
Expect(newWindowSize).To(Equal(2 * oldWindowSize))
Expect(offset).To(Equal(protocol.ByteCount(oldOffset + dataRead + newWindowSize)))
})
})
})
@@ -71,10 +81,11 @@ var _ = Describe("Connection Flow controller", func() {
var (
oldWindowSize protocol.ByteCount
receiveWindow protocol.ByteCount = 10000
receiveWindowSize protocol.ByteCount = 600
receiveWindowSize protocol.ByteCount = 1000
)
BeforeEach(func() {
controller.bytesRead = receiveWindowSize - receiveWindowSize
controller.receiveWindow = receiveWindow
controller.receiveWindowSize = receiveWindowSize
oldWindowSize = controller.receiveWindowSize
@@ -82,8 +93,8 @@ var _ = Describe("Connection Flow controller", func() {
})
It("sets the minimum window window size", func() {
controller.EnsureMinimumWindowSize(1000)
Expect(controller.receiveWindowSize).To(Equal(protocol.ByteCount(1000)))
controller.EnsureMinimumWindowSize(1800)
Expect(controller.receiveWindowSize).To(Equal(protocol.ByteCount(1800)))
})
It("doesn't reduce the window window size", func() {
@@ -97,14 +108,9 @@ var _ = Describe("Connection Flow controller", func() {
Expect(controller.receiveWindowSize).To(Equal(max))
})
It("doesn't auto-tune the window after the window size was increased", func() {
setRtt(20 * time.Millisecond)
controller.bytesRead = 9900 // receive window is 10000
controller.lastWindowUpdateTime = time.Now().Add(-20 * time.Millisecond)
controller.EnsureMinimumWindowSize(912)
offset := controller.getWindowUpdate()
Expect(controller.receiveWindowSize).To(Equal(protocol.ByteCount(912))) // no auto-tuning
Expect(offset).To(Equal(protocol.ByteCount(9900 + 912)))
It("starts a new epoch after the window size was increased", func() {
controller.EnsureMinimumWindowSize(1912)
Expect(controller.epochStartTime).To(BeTemporally("~", time.Now(), 100*time.Millisecond))
})
})
})