Skip to content

fix(backend): improve IPPrefixReconcileQuery performance #6249

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

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

fatih-acar
Copy link
Contributor

@fatih-acar fatih-acar commented Apr 7, 2025

By directly filtering the node labels. Using WHERE in labels() did not trigger the NodeByLabelScan and thus processed all nodes.

Also add a WHERE IN clause for the binary address lookup so that the binary address index is effectively used.
Looking up for the binary address + prefix length tuple prevented the planner from using the index.

This brings a 10% improvement according to the testing framework (using TestSite), with way lesser CPU usage.

@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Apr 7, 2025
@fatih-acar fatih-acar force-pushed the fac-ipam-prefix-reconcile-perf-improvement branch from 3ebb39c to e001b78 Compare April 7, 2025 18:45
Copy link

codspeed-hq bot commented Apr 7, 2025

CodSpeed Performance Report

Merging #6249 will not alter performance

Comparing fac-ipam-prefix-reconcile-perf-improvement (79a1610) with stable (f9dfb54)

Summary

✅ 10 untouched benchmarks

@fatih-acar fatih-acar marked this pull request as ready for review April 25, 2025 08:02
@fatih-acar fatih-acar requested a review from a team as a code owner April 25, 2025 08:02
Copy link
Collaborator

@dgarros dgarros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you add a newsfragment to include it in the release note

By directly filtering the node labels. Using WHERE in labels() did not
trigger the NodeByLabelScan and thus processed all nodes.
Also add a WHERE IN clause for the binary address lookup so that the
binary address index is effectively used.
Looking up for the binary address + prefix length tuple prevented the
planner from using the index.

Signed-off-by: Fatih Acar <[email protected]>
@fatih-acar fatih-acar force-pushed the fac-ipam-prefix-reconcile-perf-improvement branch from e001b78 to 79a1610 Compare April 25, 2025 11:42
@fatih-acar
Copy link
Contributor Author

Please can you add a newsfragment to include it in the release note

Added one, feel free to merge if it's ok for you.

self.params["possible_prefix_list"] = []
for possible_prefix, max_length in possible_prefix_map.items():
self.params["possible_prefix_and_length_list"].append([possible_prefix, max_length])
self.params["possible_prefix_list"].append(possible_prefix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also started using a dict instead of two lists for filtering like this, which saves on the number of variables you need to pass in with the query
in this case, the param would be something like possible_prefix_length_map and it would look like {possible_prefix: max_length}
then in the query it would look like

WHERE $possible_prefix_length_map[av.binary_address] IS NOT NULL
AND av.prefixlen <= $possible_prefix_length_map[av.binary_address]

@ajtmccarty ajtmccarty merged commit 0170e9a into stable Apr 25, 2025
35 checks passed
@ajtmccarty ajtmccarty deleted the fac-ipam-prefix-reconcile-perf-improvement branch April 25, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants