perf: introduce endpoint slice indexer#9221
Conversation
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
✅ Deploy Preview for cerulean-figolla-1f9435 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9221 +/- ##
==========================================
+ Coverage 74.89% 74.91% +0.01%
==========================================
Files 252 252
Lines 40799 40819 +20
==========================================
+ Hits 30558 30581 +23
+ Misses 8158 8153 -5
- Partials 2083 2085 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
this's a tradeoff between memory and cpu, should we add feature flag? |
|
So, I agree that it would be better for user to choose controller behavior. |
|
Agreed on adding config options for it but would propose we make this the default behavior. |
let's discuss this in the meeting this week. |


What this PR does / why we need it:
Currently, we have a bottleneck when listing EndpointSlices in large-scale environments.
We observed this with pprof; see #7573
The current implementation uses a label selector when listing EndpointSlice. In controller-runtime's cache client, label selectors first fetch all resources from cache, either in the specified namespace or across all namespaces, and then filter out non-matching items. when there are many EndpointSlices, this becomes expensive.
https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/cache/internal/cache_reader.go#L112-L188
This PR adds field indexers for EndpointSlices and uses indexed field selectors instead of label selectors when looking up EndpointSlices for a backend.
In a test environment with 2,000 Services and 4,000 EndpointSlices, this made the EndpointSlice listing path about 12x faster.
Before
After
Which issue(s) this PR fixes:
Fixes #7573
Release Notes: Yes