-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Optimize CIDR label functions #19843
Merged
joamaki
merged 3 commits into
cilium:master
from
christarazi:pr/christarazi/optimize-cidr-labels-str
Jun 3, 2022
Merged
Optimize CIDR label functions #19843
joamaki
merged 3 commits into
cilium:master
from
christarazi:pr/christarazi/optimize-cidr-labels-str
Jun 3, 2022
Conversation
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
christarazi
added
area/daemon
Impacts operation of the Cilium daemon.
area/proxy
Impacts proxy components, including DNS, Kafka, Envoy and/or XDS servers.
sig/policy
Impacts whether traffic is allowed or denied based on user-defined policies.
kind/performance
There is a performance impact of this.
release-note/misc
This PR makes changes that have no direct user impact.
labels
May 16, 2022
maintainer-s-little-helper
bot
added
dont-merge/needs-release-note-label
The author needs to describe the release impact of these changes.
and removed
dont-merge/needs-release-note-label
The author needs to describe the release impact of these changes.
labels
May 16, 2022
/test |
christarazi
changed the title
pr/christarazi/optimize cidr labels str
Optimize CIDR label functions
May 16, 2022
ianvernon
approved these changes
May 17, 2022
jrajahalme
approved these changes
May 24, 2022
christarazi
force-pushed
the
pr/christarazi/optimize-cidr-labels-str
branch
from
May 24, 2022 21:46
439c4c7
to
f9af34e
Compare
Member
Author
/test Job 'Cilium-PR-K8s-GKE' failed: Click to show.Test Name
Failure Output
If it is a flake and a GitHub issue doesn't already exist to track it, comment |
/mlh new-flake Cilium-PR-K8s-1.23-kernel-net-next |
This will come in handy for upcoming commits that will try to improve the performance of these functions. Signed-off-by: Chris Tarazi <chris@isovalent.com>
Use strings.Builder instead of fmt.Sprintf() which is known to be not performant. This optimization was identified by inspecting a pprof (memory profile) of a cluster with a wildcard L7 DNS rule policy (matchPattern: '*') and a workload selected by the policy making a large amount of unique DNS requests. ``` $ go test -v -run '^$' -bench 'Benchmark_maskedIPNetToLabelString' -benchtime 50000x -benchmem ./pkg/labels/cidr > old.txt $ go test -v -run '^$' -bench 'Benchmark_maskedIPNetToLabelString' -benchtime 50000x -benchmem ./pkg/labels/cidr > new.txt $ benchcmp old.txt new.txt benchcmp is deprecated in favor of benchstat: https://pkg.go.dev/golang.org/x/perf/cmd/benchstat benchmark old ns/op new ns/op delta Benchmark_maskedIPNetToLabelString-8 8122 4450 -45.21% benchmark old allocs new allocs delta Benchmark_maskedIPNetToLabelString-8 39 32 -17.95% benchmark old bytes new bytes delta Benchmark_maskedIPNetToLabelString-8 488 368 -24.59% ``` Signed-off-by: Chris Tarazi <chris@isovalent.com>
Avoid using fmt.Sprintf() when a simple string concatentation does the same job, and preallocate slices where possible. These optimizations were identified by inspecting a pprof (memory profile) of a cluster with a wildcard L7 DNS rule policy (matchPattern: '*') and a workload selected by the policy making a large amount of unique DNS requests. Without the previous commit that optimizes the maskedIPToLabelString(): ``` $ go test -v -run '^$' -bench 'Benchmark_GetCIDRLabels' -benchtime 5000x -benchmem ./pkg/labels/cidr > old.txt $ go test -v -run '^$' -bench 'Benchmark_GetCIDRLabels' -benchtime 5000x -benchmem ./pkg/labels/cidr > new.txt $ benchcmp old.txt new.txt benchcmp is deprecated in favor of benchstat: https://pkg.go.dev/golang.org/x/perf/cmd/benchstat benchmark old ns/op new ns/op delta Benchmark_GetCIDRLabels-8 391590 390163 -0.36% benchmark old allocs new allocs delta Benchmark_GetCIDRLabels-8 1455 1424 -2.13% benchmark old bytes new bytes delta Benchmark_GetCIDRLabels-8 64143 63189 -1.49% ``` With previous commit: ``` benchmark old ns/op new ns/op delta Benchmark_GetCIDRLabels-8 390163 295259 -24.32% benchmark old allocs new allocs delta Benchmark_GetCIDRLabels-8 1424 1131 -20.58% benchmark old bytes new bytes delta Benchmark_GetCIDRLabels-8 63189 58707 -7.09% ``` Signed-off-by: Chris Tarazi <chris@isovalent.com>
christarazi
force-pushed
the
pr/christarazi/optimize-cidr-labels-str
branch
from
May 27, 2022 23:59
f9af34e
to
4ec97d9
Compare
/test |
Marking ready to merge given CI passed except for known aws-cni failure (fixed in #20049) and approving reviews. |
christarazi
added
the
ready-to-merge
This PR has passed all tests and received consensus from code owners to merge.
label
Jun 2, 2022
maintainer-s-little-helper
bot
moved this from Needs backport from master
to Backport pending to v1.10
in 1.11.6
Jun 8, 2022
joestringer
added
backport-done/1.11
The backport for Cilium 1.11.x for this PR is done.
and removed
backport-pending/1.11
labels
Jun 9, 2022
maintainer-s-little-helper
bot
moved this from Backport pending to v1.10
to Backport done to v1.11
in 1.11.6
Jun 9, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area/daemon
Impacts operation of the Cilium daemon.
area/proxy
Impacts proxy components, including DNS, Kafka, Envoy and/or XDS servers.
backport-done/1.11
The backport for Cilium 1.11.x for this PR is done.
kind/performance
There is a performance impact of this.
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.
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.
See commit msgs.
Related: #19571