-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
device: add BenchmarkAllowedIPsInsertRemove #36
Open
bradfitz
wants to merge
1
commit into
WireGuard:master
Choose a base branch
from
bradfitz:bradfitz/benchmark_allowed_ip_insert_remove
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,3 +258,49 @@ func TestTrieIPv6(t *testing.T) { | |
assertEQ(h, 0x24046800, 0x40040800, 0x10101010, 0x10101010) | ||
assertEQ(a, 0x24046800, 0x40040800, 0xdeadbeef, 0xdeadbeef) | ||
} | ||
|
||
// Repeatedly insert and remove IPv4 /32s from AllowedIPs. | ||
func BenchmarkAllowedIPsInsertRemove(b *testing.B) { | ||
// First, make 64k peers, all with unique IPs, in a seeded pseudo-random order. | ||
const num = 256 * 256 | ||
var peers [num]*Peer | ||
var ips [num]net.IP | ||
for i := range peers { | ||
peers[i] = new(Peer) | ||
ips[i] = net.IPv4(100, 64, byte(i>>8), byte(i)).To4() | ||
} | ||
rand.Seed(1) | ||
rand.Shuffle(num, func(i, j int) { ips[i], ips[j] = ips[j], ips[i] }) | ||
|
||
// Then repeatedly add one and remove one that was insert 32k inserts back. | ||
b.ResetTimer() | ||
var a AllowedIPs | ||
for i := 0; i < b.N; i++ { | ||
a.Insert(ips[i%num], 32, peers[i%num]) | ||
a.RemoveByPeer(peers[(i+num/2)%num]) | ||
} | ||
|
||
// Finally, some stats & validity checks. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This work at the end is getting added to your total benchmark time and making your number fuzzier. Does calling |
||
nodes, numPeer := 0, 0 | ||
peersSeen := map[*Peer]bool{} | ||
foreachEntry(a.IPv4, func(n *trieEntry) { | ||
nodes++ | ||
if n.peer != nil { | ||
numPeer++ | ||
peersSeen[n.peer] = true | ||
} | ||
}) | ||
b.Logf("for N=%v: nodes=%v, peers=%v, unique_peers=%v", b.N, nodes, numPeer, len(peersSeen)) | ||
if numPeer != len(peersSeen) { | ||
b.Errorf("walked %d nodes with peers != %d unique peers seen", numPeer, len(peersSeen)) | ||
} | ||
} | ||
|
||
func foreachEntry(n *trieEntry, f func(*trieEntry)) { | ||
if n == nil { | ||
return | ||
} | ||
f(n) | ||
foreachEntry(n.child[0], f) | ||
foreachEntry(n.child[1], f) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/insert /inserted /