Reduce VPN control packet latency
This commit is contained in:
@@ -51,6 +51,7 @@ const (
|
||||
vpnGatewayBatchMaxPackets = 2048
|
||||
vpnGatewayBatchMaxBytes = 8 * 1024 * 1024
|
||||
vpnGatewayBatchFlushTimeout = 3 * time.Millisecond
|
||||
vpnGatewayPriorityBatchWait = 20 * time.Millisecond
|
||||
)
|
||||
|
||||
type readWriteCloser interface {
|
||||
@@ -350,9 +351,34 @@ func (g *Gateway) uploadGatewayPackets(ctx context.Context, priorityPackets <-ch
|
||||
}
|
||||
flushPriority := func(packet []byte) {
|
||||
flush()
|
||||
if addPacket(packet) {
|
||||
flush()
|
||||
if !addPacket(packet) {
|
||||
return
|
||||
}
|
||||
deadline := time.Now().Add(vpnGatewayPriorityBatchWait)
|
||||
for len(batch) < vpnGatewayBatchMaxPackets && batchBytes < vpnGatewayBatchMaxBytes {
|
||||
wait := time.Until(deadline)
|
||||
if wait <= 0 {
|
||||
break
|
||||
}
|
||||
timer := time.NewTimer(wait)
|
||||
select {
|
||||
case next := <-priorityPackets:
|
||||
if !timer.Stop() {
|
||||
select {
|
||||
case <-timer.C:
|
||||
default:
|
||||
}
|
||||
}
|
||||
if !addPacket(next) {
|
||||
flush()
|
||||
_ = addPacket(next)
|
||||
}
|
||||
case <-timer.C:
|
||||
flush()
|
||||
return
|
||||
}
|
||||
}
|
||||
flush()
|
||||
}
|
||||
for {
|
||||
if len(batch) == 0 && timerActive {
|
||||
|
||||
Reference in New Issue
Block a user