-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v4.4.8
Feature type
Data model extension
Proposed functionality
Currently, config context data is compiled for a device/VM on demand from the set of applicable ConfigContext instances that have been defined. In scenarios involving a large number of these instances, this can result in very complex, slow queries leading to long response times, as noted in #20358.
This FR proposes instead pre-calculating the config context data for all relevant objects (devices and VMs) via non-blocking background tasks whenever context data or devices/VMs are modified. This pre-rendered data could be cached locally on each device/VM to maximize query performance.
The primary challenge of this approach will be in reliably detecting all triggering changes. These include
- The creation, modification, or deletion of a ConfigContext object
- The creation or modification of a device/VM which impacts an associated ConfigContext object (e.g. changing the role of a device)
All updates to pre-rendered context data should be done via non-blocking asynchronous background jobs which are triggered after the relevant objects have been updated. Note that this does introduce a small window in which the rendered data for an object may be out of date. This could potentially be addressed by immediately nullifying the cached data whenever an update is queued, which would force an on-demand rendering of the context data for the object.
Use case
This approach shifts the delay of rendering config contexts to the background, optimizing for fast read queries and greatly reduced rendering times for device and VM config templates.
Database changes
A "private" nullable JSON field will likely be added to the Device and VirtualMachine models to store the pre-rendered config context data.
External dependencies
N/A