question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve performance when rendering the prefix hierarchy

See original GitHub issue

NetBox 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
jeremystretchcommented, May 27, 2021

I did a quick benchmark of the #6087 branch against develop using the following parameters:

  • 1,049,660 prefixes defined (1,092 of which are IPv6)
  • Showing 100 per page
  • Utilization column hidden
  • DEBUG off

I made five requests for /ipam/prefixes/?per_page=100 and recorded the total load time reported by the browser. Times are below.

v2.11.4 #6087
21.92s 0.92s
21.52s 0.90s
21.65s 0.93s
21.51s 0.90s
21.58s 0.93s

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.

$ time ./manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization
Running migrations:
  Applying ipam.0047_prefix_depth_children... OK
  Applying ipam.0048_prefix_populate_depth_children...
Updating 1049660 prefixes...
 OK

real	8m9.779s
user	7m17.770s
sys	0m0.679s

Obviously this is far from a scientific test, though I believe it illustrates the enormity of the performance improvements gained with this work.

2reactions
jeremystretchcommented, Apr 6, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improve string - prefix matching performance - Stack Overflow
I would structure the code so that the bloom filter is checked from within the code that's computing the hash.
Read more >
Energy Characterization and Optimization of Parallel Prefix ...
This paper is a first attempt to address the energy aspects of CPPS (cache-aware parallel prefix-sums), a high performance parallel prefix-sums ...
Read more >
Graphics Performance Improvements - Oracle
Because the rendering of Swing hierarchies relies heavily on common operations like setColor and Graphics. create , the invalidation and re-creation of  ......
Read more >
Optimizing Your Scene - Babylon.js Documentation
How To Optimize Your Scene. This tutorial will help you find some links and info on how you can improve your scene regarding...
Read more >
11 Ways to Improve JSON Performance & Usage - Stackify
Most libraries enable you to specify attributes on your classes to override the names of the fields as they are being serialized. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found