pkg/policy: Add benchmark for ForEachGo #22845
Merged
+17
−1
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.
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