send multiple packets at once, if the pacing delay is very small

This is an optimization to avoid waking of the run loop every couple of
microseconds.
This commit is contained in:
Marten Seemann
2018-01-08 10:03:26 +07:00
parent 5ef89733ae
commit 9ef3a47da5
9 changed files with 214 additions and 88 deletions

View File

@@ -153,6 +153,18 @@ func (mr *MockSentPacketHandlerMockRecorder) SetHandshakeComplete() *gomock.Call
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHandshakeComplete", reflect.TypeOf((*MockSentPacketHandler)(nil).SetHandshakeComplete))
}
// ShouldSendNumPackets mocks base method
func (m *MockSentPacketHandler) ShouldSendNumPackets() int {
ret := m.ctrl.Call(m, "ShouldSendNumPackets")
ret0, _ := ret[0].(int)
return ret0
}
// ShouldSendNumPackets indicates an expected call of ShouldSendNumPackets
func (mr *MockSentPacketHandlerMockRecorder) ShouldSendNumPackets() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShouldSendNumPackets", reflect.TypeOf((*MockSentPacketHandler)(nil).ShouldSendNumPackets))
}
// ShouldSendRetransmittablePacket mocks base method
func (m *MockSentPacketHandler) ShouldSendRetransmittablePacket() bool {
ret := m.ctrl.Call(m, "ShouldSendRetransmittablePacket")

View File

@@ -131,3 +131,8 @@ const NumCachedCertificates = 128
// 1. it reduces the framing overhead
// 2. it reduces the head-of-line blocking, when a packet is lost
const MinStreamFrameSize ByteCount = 128
// MinPacingDelay is the minimum duration that is used for packet pacing
// If the packet packing frequency is higher, multiple packets might be sent at once.
// Example: For a packet pacing delay of 20 microseconds, we would send 5 packets at once, wait for 100 microseconds, and so forth.
const MinPacingDelay time.Duration = 100 * time.Microsecond

View File

@@ -114,6 +114,14 @@ func MinTime(a, b time.Time) time.Time {
return a
}
// MaxTime returns the later time
func MaxTime(a, b time.Time) time.Time {
if a.After(b) {
return a
}
return b
}
// MaxPacketNumber returns the max packet number
func MaxPacketNumber(a, b protocol.PacketNumber) protocol.PacketNumber {
if a > b {

View File

@@ -49,6 +49,13 @@ var _ = Describe("Min / Max", func() {
Expect(MaxPacketNumber(1, 2)).To(Equal(protocol.PacketNumber(2)))
Expect(MaxPacketNumber(2, 1)).To(Equal(protocol.PacketNumber(2)))
})
It("returns the maximum time", func() {
a := time.Now()
b := a.Add(time.Second)
Expect(MaxTime(a, b)).To(Equal(b))
Expect(MaxTime(b, a)).To(Equal(b))
})
})
Context("Min", func() {