diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-27 18:13:53 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-27 18:38:27 +0100 |
commit | 1b092ce584cbee0f86f3e25b5498870c8ca96652 (patch) | |
tree | f8f7119546aafab5d48f6dd9078bfbf18a753b1a /device/peer.go | |
parent | a11dec5dc12255ee032ce730eef3c82e77c84ed2 (diff) |
device: get rid of nonce routine
This moves to a simple queue with no routine processing it, to reduce
scheduler pressure.
This splits latency in half!
benchmark old ns/op new ns/op delta
BenchmarkThroughput-16 2394 2364 -1.25%
BenchmarkLatency-16 259652 120810 -53.47%
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device/peer.go')
-rw-r--r-- | device/peer.go | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/device/peer.go b/device/peer.go index a103b5d..af2f57f 100644 --- a/device/peer.go +++ b/device/peer.go @@ -16,10 +16,6 @@ import ( "golang.zx2c4.com/wireguard/conn" ) -const ( - PeerRoutineNumber = 2 -) - type Peer struct { isRunning AtomicBool sync.RWMutex // Mostly protects endpoint, but is generally taken whenever we modify peer @@ -54,17 +50,11 @@ type Peer struct { sentLastMinuteHandshake AtomicBool } - signals struct { - newKeypairArrived chan struct{} - flushNonceQueue chan struct{} - } - queue struct { sync.RWMutex - nonce chan *QueueOutboundElement // nonce / pre-handshake queue - outbound chan *QueueOutboundElement // sequential ordering of work - inbound chan *QueueInboundElement // sequential ordering of work - packetInNonceQueueIsAwaitingKey AtomicBool + staged chan *QueueOutboundElement // staged packets before a handshake is available + outbound chan *QueueOutboundElement // sequential ordering of work + inbound chan *QueueInboundElement // sequential ordering of work } routines struct { @@ -197,25 +187,20 @@ func (peer *Peer) Start() { peer.routines.stopping.Wait() peer.routines.stop = make(chan struct{}) - peer.routines.stopping.Add(PeerRoutineNumber) + peer.routines.stopping.Add(1) // prepare queues peer.queue.Lock() - peer.queue.nonce = make(chan *QueueOutboundElement, QueueOutboundSize) + peer.queue.staged = make(chan *QueueOutboundElement, QueueStagedSize) peer.queue.outbound = make(chan *QueueOutboundElement, QueueOutboundSize) peer.queue.inbound = make(chan *QueueInboundElement, QueueInboundSize) peer.queue.Unlock() peer.timersInit() peer.handshake.lastSentHandshake = time.Now().Add(-(RekeyTimeout + time.Second)) - peer.signals.newKeypairArrived = make(chan struct{}, 1) - peer.signals.flushNonceQueue = make(chan struct{}, 1) // wait for routines to start - // RoutineNonce writes to the encryption queue; keep it alive until we are done. - device.queue.encryption.wg.Add(1) - go peer.RoutineNonce() go peer.RoutineSequentialSender() go peer.RoutineSequentialReceiver() @@ -245,7 +230,7 @@ func (peer *Peer) ZeroAndFlushAll() { handshake.Clear() handshake.mutex.Unlock() - peer.FlushNonceQueue() + peer.FlushStagedPackets() } func (peer *Peer) ExpireCurrentKeypairs() { @@ -291,8 +276,8 @@ func (peer *Peer) Stop() { // close queues peer.queue.Lock() - close(peer.queue.nonce) close(peer.queue.inbound) + close(peer.queue.outbound) peer.queue.Unlock() peer.ZeroAndFlushAll() |