Displaying a page of a Prefix takes 20 min #13471
-
Showing the page of our Prefix with the most child prefixes and containing the most IP addresses takes ~ 20 min in the browser. This is the URL (internal only): https://netbox.myorg.org/ipam/prefixes/13/ Child prefixes: 1851 Querying the object with the nbshell doesn't exhibit any noticeable lag. Assuming other institutions may maintain even larger networks in netbox, there is probably something odd with our setup. Any hints for investigating this further are much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
BTW: This is on Python 3.9.2 | Django 4.1.10 | NetBox 3.5.6 | Debian 11 |
Beta Was this translation helpful? Give feedback.
-
I think we need to look at what SQL queries are being issued to the database. It's possible that while counting the child objects, Netbox is either querying all objects, or generating a separate query per object. Doing this is very easy. Set For example, on my system (3.5.7), if I go to Debug mode does drastically slow down the system, so your 20 minutes could become longer again - so you might want to start with a tighter prefix. Now, at a quick glance, it does look pretty broken to me. I was expecting to see
There are no "LIMIT" clauses there, so it clearly is iterating over them all. The backtrace for the child IP addresses is interesting. It shows a template expansion:
and
I think it's doing an incredibly expensive calculation, just to work out the number of available IP addresses to show the prefix utilization: it has to query all IPs within the prefix. Similarly, the query for all child prefixes:
And for child ranges:
So your answer is: there's nothing odd with your setup, it's just that Netbox isn't optimised for large networks (and the use of an ORM is hiding the expensive queries it does in the background). |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your very detailed explanation. Does that mean the experienced behavior is related to the fundamental system architecture of netbox and cannot easily addressed? |
Beta Was this translation helpful? Give feedback.
-
Hello,
slow variant.
fast variant. |
Beta Was this translation helpful? Give feedback.
-
@candlerb Do you think it is worthwile open an issue about that? My gut tells me that we are not a particularly large organization and that others might run into similar issues. |
Beta Was this translation helpful? Give feedback.
I think we need to look at what SQL queries are being issued to the database. It's possible that while counting the child objects, Netbox is either querying all objects, or generating a separate query per object.
Doing this is very easy. Set
DEBUG=True
in configuration.py, then restart. This enables a debug tool button on the top-right corner, which you can click to expand.For example, on my system (3.5.7), if I go to
/ipam/prefixes/17/
which is an outer container prefix, I see tabs for Child Prefixes (11), Child Ranges (6), IP Addresses (73). The Debug panel tells me "29 queries in 71.42ms"Debug mode does drastically slow down the system, so your 20 minutes could become longer again - …