Repository navigation
Conversation
try_to_allocate_dynamic_ip loads every reserved IP across all deployments and, to drop addresses already covered by a larger block, compared each entry against every other entry. That full pairwise scan is O(n^2) in the total number of reserved IPs and runs on every dynamic allocation, pegging a worker CPU and stalling "Preparing deployment" and compilation-VM creation on busy directors. Only an entry that spans more than one address (a reserved CIDR block) can cover another entry; the /32 and /128 host reservations that make up the bulk of the table never can. Restricting the inner scan to those blocks produces identical dedup output while making the pass linear in the host count. Verified behaviour-identical to the previous dedup across edge cases, IPv6, and randomized inputs, and on large sets (dedup at 16k reserved IPs: ~117s -> ~0.09s). Signed-off-by: Nayden Petrov <nayden.petrov@sap.com>
ManualNetworkSubnet.parse deduplicates restricted_ips with the same full pairwise scan found in try_to_allocate_dynamic_ip. The set is small here (reserved CIDR blocks plus a few host entries) so it is not a hot path, but it is the identical O(n^2) pattern and the identical fix: only an entry that spans more than one address can contain another, so the inner scan is restricted to those blocks. Behaviour-identical to the previous dedup, verified across randomized IPv4 and IPv6 restricted-IP sets. Signed-off-by: Nayden Petrov <nayden.petrov@sap.com>
|
No actionable comments were generated in the recent review. WalkthroughDynamic IP allocation and manual subnet parsing now consider only multi-address reservations as potential containing blocks. Both paths remove reservations covered by a larger block. A new spec checks dynamic IP allocation time with 16,000 reservations. Suggested reviewers: Merge Risk:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the reserved-IP deduplication optimization.
No open issues 🎉
What changed in this PR
Optimizes reserved-IP deduplication in the director’s dynamic IP allocator and subnet parser by limiting containment checks to multi-address blocks, preserving the existing containment predicate.
Changes:
- Excludes single-address reservations from potential containers, reducing work for host-heavy reservation sets.
- Skips containment scans entirely when no multi-address blocks exist.
- Applies the same optimization to restricted IPs during manual subnet parsing.
| File | Description |
|---|---|
src/bosh-director/lib/bosh/director/deployment_plan/manual_network_subnet.rb |
Limits restricted-IP containment checks to multi-address blocks. |
src/bosh-director/lib/bosh/director/deployment_plan/ip_provider/ip_repo.rb |
Reduces deduplication work during dynamic IP allocation. |
Review effort: Balanced
Alphasite
left a comment
There was a problem hiding this comment.
It took me a second to figure out why there were all these single IP exclusions...
I think it's worth the comment mentioning that the IP for each Nic is represented as an exclusion, so we can ignore those when checking ip block intersection.
|
Lets not merge for now. I am not convinced that this alone addresses the issue that was raised in Slack. Thank you for the suggestions!
|
- Explain in the comment that reserved IPs are per-NIC single-address exclusions (/32 or /128) alongside the occasional larger block, so only multi-address blocks can be containers and the scan is restricted to them. - Add a spec that allocates a dynamic IP against 16k reserved IPs and asserts it completes well under 3 seconds, guarding against reintroducing the O(n^2) scan. Signed-off-by: Nayden Petrov <nayden.petrov@sap.com>
bd0af23
What
IpRepo#try_to_allocate_dynamic_ipdeduplicates its set of unavailable addresses by removing any reservation already covered by a larger (smaller-prefix) block. It did this with a full pairwise scan - every entry compared against every other entry:addresses_we_cant_allocatestarts fromall_ip_addresses- every reserved IP in the director, across all deployments. The scan is therefore O(n²) in the total number of reserved IPs, and it runs on every dynamic IP allocation.This change restricts the inner comparison to the only entries that can actually contain another - blocks that span more than one address (
ip.count > 1), i.e. reserved CIDR ranges, of which there are very few. The/32//128host reservations that dominate the table can never be containers, so excluding them from the scan produces identical dedup output while making the pass linear in the host count.The identical dedup pattern appears in
ManualNetworkSubnet.parseover the subnet'srestricted_ips; the same transformation is applied there. It is not a hot path (that set is small and the dedup runs once per subnet-parse), but it is the same code and the same fix, so both are updated together for consistency.Why / impact
On a busy director the quadratic scan pegs a worker CPU at 100% and stalls
bosh deploy, with no cancellation checkpoint inside the loop (so the task is also uncancellable). It is paid per reservation, so it compounds across the instance IPs reserved during Preparing deployment and across each compilation VM IP reservation.Measured cost of the dedup step alone (real
IpAddrOrCidrobjects):Correctness
The change is behaviour-preserving by construction: the predicate is unchanged, and the only
(ip, other_ip)pairs removed from consideration are those whereother_ip.prefix < ip.prefixcan never hold - another_ipat host width (count == 1) cannot be below anyip's prefix, sinceip.prefixnever exceeds host width. Socontaining_blockscaptures every possible container.Verified identical to the previous dedup (end-to-end allocated address from the real
find_next_available_ip) across:/24 ⊃ /26 ⊃ /32), mid-range reserved, sub-/32block allocation (/30,/28,/124), fully-packed range, host just belowfirst, many blocks + hosts, and IPv6 (host+block, nested, non-/128allocation).The
ManualNetworkSubnet.parsededup was verified the same way - identical output to the original across 50,000 randomized IPv4 and IPv6restricted_ipssets.Testing
bosh-directorunit specs pass, including the IP provider / repo, manual network (+ subnet),IpAddrOrCidr, network planner, and reservation suites.Caution
This is not tested on an actual deployment.