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

pkg/policy: Add benchmark for ForEachGo #22845

Merged

Conversation

christarazi
Copy link
Member

@christarazi christarazi commented Dec 22, 2022

I added this benchmark code in order to evaluate whether ForEachGo could
be switched to a model where the number of goroutines are limited to the
number of CPUs. The performance difference was quite drastic. For a
benchmark run that took about ~10s prior to the change, it took about
~8m after the change.

One of the callers of ForEachGo bumps the policy revision of each
endpoint, which is a relatively cheap operation (incrementing an atomic
int), it doesn't seem worth optimizing ForEachGo.

The other caller of ForEachGo is for regenerating the endpoints. Under
the hood, regenerating endpoints is already limited by a semaphore,
bounded by number of CPUs, so there's no need to limit ForEachGo itself.

One could argue that launching as many goroutines as endpoints on a node
is a concern, especially to the Go scheduler. However, given the
performance impact of bounding ForEachGo, it seems that it may not be
worth pre-optimizing now until we have more evidence that ForEachGo can
cause issues.

For now, I'll submit this benchmark-adding commit so that we may
evaluate this code in the future.

Signed-off-by: Chris Tarazi chris@isovalent.com

@christarazi christarazi added 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 Dec 22, 2022
@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. and removed dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Dec 22, 2022
@github-actions github-actions bot added the kind/community-contribution This was a contribution made by a community member. label Dec 22, 2022
@christarazi christarazi force-pushed the pr/christarazi/for-each-go-benchmark branch 2 times, most recently from 807f6f1 to a360e8c Compare December 22, 2022 19:40
@christarazi christarazi removed the kind/community-contribution This was a contribution made by a community member. label Dec 22, 2022
@christarazi christarazi marked this pull request as ready for review December 22, 2022 19:44
@christarazi christarazi requested a review from a team as a code owner December 22, 2022 19:44
I added this benchmark code in order to evaluate whether ForEachGo could
be switched to a model where the number of goroutines are limited to the
number of CPUs. The performance difference was quite drastic. For a
benchmark run that took about ~10s prior to the change, it took about
~8m after the change.

One of the callers of ForEachGo bumps the policy revision of each
endpoint, which is a relatively cheap operation (incrementing an atomic
int), it doesn't seem worth optimizing ForEachGo.

The other caller of ForEachGo is for regenerating the endpoints. Under
the hood, regenerating endpoints is already limited by a semaphore,
bounded by number of CPUs, so there's no need to limit ForEachGo itself.

One could argue that launching as many goroutines as endpoints on a node
is a concern, especially to the Go scheduler. However, given the
performance impact of bounding ForEachGo, it seems that it may not be
worth pre-optimizing now until we have more evidence that ForEachGo can
cause issues.

For now, I'll submit this benchmark-adding commit so that we may
evaluate this code in the future.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
@christarazi christarazi force-pushed the pr/christarazi/for-each-go-benchmark branch from a360e8c to c9939a6 Compare January 4, 2023 19:46
@joestringer joestringer merged commit 70b3624 into cilium:master Jan 19, 2023
@christarazi christarazi deleted the pr/christarazi/for-each-go-benchmark branch January 19, 2023 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/performance There is a performance impact of this. 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

2 participants