Skip to content

Pre-render and cache config context data #21025

@jeremystretch

Description

@jeremystretch

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

  1. The creation, modification, or deletion of a ConfigContext object
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity: highExpected to require a large amont of time and effort to implement relative to other tasksneeds milestoneAwaiting prioritization for inclusion with a future NetBox releasenetboxstatus: backlogAwaiting selection for worktype: featureIntroduction of new functionality to the application

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions