Skip to content
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

Displaying the page of a prefix with many child prefixes (each having a child range) runs into gateway timeout #14500

Closed
reduzent opened this issue Dec 12, 2023 · 6 comments · Fixed by #15041
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@reduzent
Copy link

reduzent commented Dec 12, 2023

Deployment Type

Self-hosted

NetBox Version

v3.6.6

Python Version

3.11

Steps to Reproduce

The page /ipam/prefixes/1/ on our Netbox instance takes more than 20mins to display and runs into a timeout when not increasing timeout values.

My test system is a Debian 12 VM (VMware VM) with netbox 3.6.6. The system has two CPU cores and 4 GB Memory. Initial state is an empty database.

I can trigger the 504 Gateway Time-out (nginx error) when I create a prefix with 1000 child prefixes where each child prefix has one child range.

This is how I create the objects in nbshell:

mainpref = Prefix(prefix='10.128.0.0/11', status='active')
mainpref.full_clean()
mainpref.save()

mainpref = Prefix.objects.filter(prefix='10.128.0.0/11')[0]

prefsize = 256
prefcount = 1000

for i in range(0, prefcount*prefsize, prefsize):
    newpref = Prefix(prefix=mainpref.prefix[i].format() + '/24', status='active')
    newpref.full_clean()
    newpref.save()

for cpref in mainpref.get_child_prefixes():
    newrange = IPRange(start_address=cpref.prefix[100].format() + '/24' , end_address=cpref.prefix[250].format() + '/24' , status='active')
    newrange.full_clean()
    newrange.save()

If you apply this to a new installation, this URL triggers the timeout:

/ipam/prefixes/1/

Or click the result of this search:

/ipam/prefixes/?q=10.128.0.0%2F11

There is a related #13471 where it appears that we can't do much about it but hope that this going to be addressed in Netbox itself.

Expected Behavior

The page should be rendered within reasonable time.

Observed Behavior

We get a 504 when trying to visit the particular page.

@reduzent reduzent added the type: bug A confirmed report of unexpected behavior in the application label Dec 12, 2023
@reduzent reduzent changed the title Displaying the page of a Prefix with many Child Ranges, IPAdresses and Child Prefix runs into gateway timeout Displaying the page of a prefix with many child prefixes (each having a child range) runs into gateway timeout Dec 12, 2023
@reduzent
Copy link
Author

This is a duplicate of #13880 which was closed due missing information. Missing information is now hopefully provided.

@jeremystretch jeremystretch added severity: medium Results in substantial degraded or broken functionality for specfic workflows status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Dec 12, 2023
@jeremystretch
Copy link
Member

The delay stems from the call to get_available_ips() for the parent prefix. It's actually happening twice: first with the call to return the number of available IPs, and again to return the first available IP. We need to optimize the logic for calculating available IPs when accounting for ranges.

@arthanson arthanson self-assigned this Jan 24, 2024
@arthanson arthanson removed the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Jan 24, 2024
@Smixi
Copy link
Contributor

Smixi commented Feb 5, 2024

Hello,
I made a small PR for this if you want to look at it. I just investigated specifically on the mentionned function, but I guess it can be used anywhere where netaddr.ipset are used.

This is related to how adding and removing items in the sets works. It's seem its way faster to make a list of network items then transform it as a ipset rather than adding them one by one. I think this is because it make internal loops everytime you add items in it.

The page loads with the given script in ~6s on my computer.

@arthanson
Copy link
Collaborator

Assigning to you @Smixi as I'm working on other bugfixes right now.

@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Feb 5, 2024
@Smixi
Copy link
Contributor

Smixi commented Feb 5, 2024

Note: Maybe we can also add cached property into prefix as it is made inside IPRange ? It will solve the second point mentionned here :

The delay stems from the call to get_available_ips() for the parent prefix. It's actually happening twice: first with the call to return the number of available IPs, and again to return the first available IP.

Or create another issue ?

@reduzent
Copy link
Author

reduzent commented Feb 6, 2024

Nice. Thanks for fixing!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants