Skip to content

sources: look up existing IP addresses by address instead of a full scan - #622

Open
tyderian1978 wants to merge 1 commit into
bb-Ricardo:developmentfrom
tyderian1978:perf/ip-address-index
Open

tyderian1978 wants to merge 1 commit into
bb-Ricardo:developmentfrom
tyderian1978:perf/ip-address-index

Conversation

@tyderian1978

Copy link
Copy Markdown

Disclaimer: AI generated, based off the work we're doing with Netbox.

What happens

For every address a source reports, add_update_interface() scans every IP address in the inventory to find the existing object, and with skip_fhrp_group_ips once more for an FHRP group binding. Where NetBox is fed from an IPAM, the inventory holds tens of thousands of IPs; with our ~36,000, that scan was about a tenth of a vCenter run.

Fix

SourceBase.ip_address_objects_for(address) keeps an index by address (without prefix length) and returns the candidates in inventory order, so the matching logic and its order are unchanged; both scans use it, and the loop still checks each candidate's address as before. The inventory only appends during a run, so the index catches up with the objects added since the last lookup instead of being rebuilt.

Tests

tests/test_ip_address_index.py: the same candidates in the same order as a full scan (IPv4 and IPv6, several prefix lengths of one address, an address that is a prefix of another as a string), and objects added after the first lookup are found. Both fail on development without the change. Full suite: 609 passed, 8 skipped; the FHRP tests (test_fhrp_ip_binding.py) pass unchanged.

Together with the vCenter tag cache (separate PR), a dry run against our production NetBox and vCenters went from 38 min 45 s to 27 min 42 s, with identical planned changes.

add_update_interface() scanned every IP address in the inventory for each
address a source reported, once to find the existing object and, with
skip_fhrp_group_ips, once more for an FHRP group binding. Where NetBox is
fed from an IPAM the inventory holds tens of thousands of IPs; with ~36,000
that scan was about a tenth of a vCenter run.

SourceBase.ip_address_objects_for() keeps an index by address (without
prefix length) and returns the candidates in inventory order. The inventory
only appends, so the index catches up with objects added since the last
lookup. The matching logic and its order are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant