Improve performance when rendering the prefix hierarchy
See original GitHub issueNetBox version
v2.10.8
Feature type
Change to existing functionality
Proposed functionality
Employ MPTT for constructing the prefix hierarchy. This entails automatically assigning each prefix to its parent (if any) and recalculating the hierarchy. NetBox currently employs MPTT for several models (e.g. nesting regions) but adopting it for prefixes will require the automatic assignment and re-assignment of parents as prefixes are added and removed.
Use case
MPTT allows us to more efficiently model the prefix hierarchy, and obviates the need to make verbose SQL annotations to count parent and child prefixes. However, it further consideration is needed regarding the automatic assignment of parent prefixes.
Database changes
Extend ipam.Prefix to an MPTT-enabled model by adding the parent_id
, tree_id
, level
, lft
, and rght
fields.
External dependencies
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:7 (7 by maintainers)
Top GitHub Comments
I did a quick benchmark of the #6087 branch against
develop
using the following parameters:DEBUG
offI made five requests for
/ipam/prefixes/?per_page=100
and recorded the total load time reported by the browser. Times are below.Clearly, some pretty huge gains in performance.
It’s worth reiterating that I’ve hidden the utilization column from the prefixes tables for these tests, since that imposes additional overhead. (All other default columns were retained.) Still, with the utilization column included (though no child IP addresses defined), load times averaged around five seconds with #6087 in place.
Migrating the roughly one million prefixes took about eight minutes on my development machine. A more realistic deployment with perhaps around 100 thousand prefixes should take less than a minute.
Obviously this is far from a scientific test, though I believe it illustrates the enormity of the performance improvements gained with this work.
@tyler-8 there would be some degree of performance impact at write time, but it should greatly reduce the amount of time required to render the prefixes list. This proposal is still just a rough idea: further testing is needed to determine its viability.