[Perf] Optimize findMigWithMatchingBasename with O(1) prefix map lookup#9476
[Perf] Optimize findMigWithMatchingBasename with O(1) prefix map lookup#9476tetianakh wants to merge 1 commit intokubernetes:masterfrom
Conversation
Implement O(1) prefix map lookup in findMigWithMatchingBasename to avoid O(N) linear search over all MIGs when resolving MIG for an instance. Benchmark results (scale: 200 MIGs, 200 ready nodes, 100 deleted nodes, 100 upcoming nodes): | Metric | Before (Unoptimized) | After (Optimized) | Difference | | :--- | :--- | :--- | :--- | | Time | 5.099 ms ± 27% | 3.230 ms ± 40% | -36.64% | | Memory | 1164.6 KiB ± 1% | 563.9 KiB ± 1% | -51.58% | | Allocs | 3.398k ± 2% | 8.246k ± 0% | +142.69% | The optimization reduces CPU time by ~36% and memory allocations by ~50% at this scale. Includes benchmark test file and README.
|
Hi @tetianakh. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tetianakh The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Implements O(1) prefix map lookup in findMigWithMatchingBasename to avoid O(N) linear search over all MIGs when resolving MIG for an instance.
Whn GetMigforInstance is called for deleted nodes, the deleted nodes are never in the cache, so findMigWithMatchingBasename is always executed. On a large cluster that has a lot of deleted nodes, each GetMigforInstance call site (which iterates over all nodes) can take a few seconds.
Benchmark results (scale: 200 MIGs, 200 ready nodes, 100 deleted nodes, 100 upcoming nodes):
The optimization reduces CPU time by ~36% and memory allocations by ~50% at this scale.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: