Skip to content

Commit

Permalink
device: switch to regular mutex for keypair guard
Browse files Browse the repository at this point in the history
name                              old time/op      new time/op      delta
TrieIPv4Peers100Addresses1000-32      83.5ns ± 0%      83.3ns ± 0%   ~     (p=1.000 n=1+1)
TrieIPv4Peers10Addresses10-32         33.6ns ± 0%      33.4ns ± 0%   ~     (p=1.000 n=1+1)
TrieIPv6Peers100Addresses1000-32      83.3ns ± 0%      83.2ns ± 0%   ~     (p=1.000 n=1+1)
TrieIPv6Peers10Addresses10-32         33.5ns ± 0%      33.2ns ± 0%   ~     (p=1.000 n=1+1)
Latency-32                             216µs ± 0%       216µs ± 0%   ~     (p=1.000 n=1+1)
Throughput-32                         2.31µs ± 0%      2.28µs ± 0%   ~     (p=1.000 n=1+1)
UAPIGet-32                            2.28µs ± 0%      2.13µs ± 0%   ~     (p=1.000 n=1+1)
WaitPool-32                           4.18µs ± 0%      4.14µs ± 0%   ~     (p=1.000 n=1+1)

name                              old packet-loss  new packet-loss  delta
Throughput-32                           0.00 ± 0%        0.01 ± 0%   ~     (p=1.000 n=1+1)

name                              old alloc/op     new alloc/op     delta
UAPIGet-32                              224B ± 0%        224B ± 0%   ~     (all equal)

name                              old allocs/op    new allocs/op    delta
UAPIGet-32                              17.0 ± 0%        17.0 ± 0%   ~     (all equal)
  • Loading branch information
raggi committed Sep 8, 2022
1 parent 657e769 commit 5290a10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,8 @@ func (device *Device) SendKeepalivesToPeersWithCurrentKeypair() {

device.peers.RLock()
for _, peer := range device.peers.keyMap {
peer.keypairs.RLock()
sendKeepalive := peer.keypairs.current != nil && !peer.keypairs.current.created.Add(RejectAfterTime).Before(time.Now())
peer.keypairs.RUnlock()
if sendKeepalive {
current := peer.keypairs.Current()
if current.created.Add(RejectAfterTime).Before(time.Now()) {
peer.SendKeepalive()
}
}
Expand Down
6 changes: 3 additions & 3 deletions device/keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ type Keypair struct {
}

type Keypairs struct {
sync.RWMutex
sync.Mutex
current *Keypair
previous *Keypair
next *Keypair
}

func (kp *Keypairs) Current() *Keypair {
kp.RLock()
defer kp.RUnlock()
kp.Lock()
defer kp.Unlock()
return kp.current
}

Expand Down

0 comments on commit 5290a10

Please sign in to comment.