Skip to content
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

fqdn: Fix notifyOnDNSMsg benchmark #32454

Merged

Conversation

pippolo84
Copy link
Member

The design of BenchmarkNotifyOnDNSMsg was flawed due to the usage of b.N as benchmark input size. b.N is used by the Go benchmarking framework to find a reliable timing for the code under test. Changing the amount of work done at each benchmark call leads to unreliable numbers. For more info refer to the Go documentation:

The benchmark function must run the target code b.N times. During
benchmark execution, b.N is adjusted until the benchmark function
lasts long enough to be timed reliably.

And the section Traps for young players in the blog post https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go

To fix it, the benchmark has been updated to setup a reasonable fixed number of endpoints.

Also, since the code was behind the latest development in the policy and fqdn subsystems, it has been updated to run correctly. Specifically:

  • the global LocalNodeStore is set once at startup
  • the FQDN selectors are added to the selector cache with a dummy user
  • the daemon context is properly initialized
  • the FQDN related global opts are set to their defaults to avoid noisy logs

Example run:

goos: linux
goarch: amd64
pkg: github.com/cilium/cilium/daemon/cmd
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
BenchmarkNotifyOnDNSMsg-8   	      21	  47992143 ns/op	30757230 B/op	  357646 allocs/op
BenchmarkNotifyOnDNSMsg-8   	      24	  48773334 ns/op	30590877 B/op	  355639 allocs/op
BenchmarkNotifyOnDNSMsg-8   	      22	  47940489 ns/op	30719252 B/op	  358088 allocs/op
BenchmarkNotifyOnDNSMsg-8   	      24	  48019454 ns/op	30364074 B/op	  353470 allocs/op
BenchmarkNotifyOnDNSMsg-8   	      24	  66607283 ns/op	30634838 B/op	  356352 allocs/op
PASS

Related: #32297 (comment)

@pippolo84 pippolo84 added kind/bug/CI This is a bug in the testing code. area/fqdn Affects the FQDN policies feature labels May 10, 2024
@pippolo84 pippolo84 requested a review from a team as a code owner May 10, 2024 09:09
@pippolo84 pippolo84 requested a review from doniacld May 10, 2024 09:09
@maintainer-s-little-helper maintainer-s-little-helper bot added dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels May 10, 2024
@github-actions github-actions bot added the sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. label May 10, 2024
@pippolo84 pippolo84 added the release-note/misc This PR makes changes that have no direct user impact. label May 10, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label May 10, 2024
@pippolo84 pippolo84 force-pushed the pr/pippolo84/fix-notifyondnsmsg-bench branch from fd1cbbf to 70df921 Compare May 13, 2024 09:31
daemon/cmd/fqdn_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@doniacld doniacld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit comment, otherwise lgtm 🚀
NB: Particularly appreciate the commit message.

Add defaults values for DNSProxyLockCount and DNSProxyLockTimeout in
order to refer them both in the global options initialization and in the
notifyOnDNSMessage benchmark.

Signed-off-by: Fabio Falzoi <[email protected]>
The design of BenchmarkNotifyOnDNSMsg was flawed due to the usage of b.N
as benchmark input size. b.N is used by the Go benchmarking framework to
find a reliable timing for the code under test. Changing the amount of
work done at each benchmark call leads to unreliable numbers.  For more
info refer to the Go documentation:

	The benchmark function must run the target code b.N times. During
	benchmark execution, b.N is adjusted until the benchmark function
	lasts long enough to be timed reliably.

And the section `Traps for young players` in the blog post
https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go

To fix it, the benchmark has been updated to setup a reasonable fixed
number of endpoints.

Also, since the code was behind the latest development in the policy and
fqdn subsystems, it has been updated to run correctly. Specifically:

- the global LocalNodeStore is set once at startup
- the FQDN selectors are added to the selector cache with a dummy user
- the daemon context is properly initialized
- the FQDN related global opts are set to their defaults to avoid noisy
  logs

Example run:

goos: linux
goarch: amd64
pkg: github.com/cilium/cilium/daemon/cmd
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
BenchmarkNotifyOnDNSMsg-8   	      21	  47992143 ns/op	30757230 B/op	  357646 allocs/op
BenchmarkNotifyOnDNSMsg-8   	      24	  48773334 ns/op	30590877 B/op	  355639 allocs/op
BenchmarkNotifyOnDNSMsg-8   	      22	  47940489 ns/op	30719252 B/op	  358088 allocs/op
BenchmarkNotifyOnDNSMsg-8   	      24	  48019454 ns/op	30364074 B/op	  353470 allocs/op
BenchmarkNotifyOnDNSMsg-8   	      24	  66607283 ns/op	30634838 B/op	  356352 allocs/op
PASS

Signed-off-by: Fabio Falzoi <[email protected]>
@pippolo84 pippolo84 force-pushed the pr/pippolo84/fix-notifyondnsmsg-bench branch from 70df921 to 2aa79d5 Compare May 14, 2024 17:00
@pippolo84 pippolo84 requested a review from a team as a code owner May 14, 2024 17:00
@pippolo84 pippolo84 requested a review from danehans May 14, 2024 17:00
@pippolo84
Copy link
Member Author

/test

@pippolo84
Copy link
Member Author

pippolo84 commented May 15, 2024

Given this PR I'm removing @danehans as reviewer. @doniacld do you mind taking another look at this for the sig-agent approval? I've just defined the additional constants. Thanks! 🙏

@pippolo84 pippolo84 requested review from doniacld and removed request for danehans May 15, 2024 17:03
Copy link
Contributor

@doniacld doniacld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! Thanks for the changes!

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label May 17, 2024
@julianwiedmann julianwiedmann added this pull request to the merge queue May 21, 2024
Merged via the queue into cilium:main with commit db5fcdc May 21, 2024
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/fqdn Affects the FQDN policies feature kind/bug/CI This is a bug in the testing code. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants