Improve Interface API Endpoint speed. #8030

Closed
opened 2025-12-29 20:31:29 +01:00 by adam · 2 comments
Owner

Originally created by @jiuka on GitHub (May 10, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.5.1

Feature type

Change to existing functionality

Proposed functionality

Adding l2vpn_terminations and vdcs to the prefetch_related in the InterfaceViewSet reduced amount of DB queries in our setup from 3185 down to 1183 for requesting 1000 Interfaces. And Reduces the request time from ~7s to ~4s.

Many of the remaining queries come from the link_peers and connected_endpoints field. If possible those fiels should be prefetched as well, however I could not find out how this can be achived. (To test the impact of those fields I removed them from the Serializer to test and gotthe queries to request the same 1000 interfaces down to 57)

Use case

The Ansible netbox.netbox.nb_inventory plugin needs to fetch all interfaces if interfaces informations should be included. This is relativly slow and by far the slowest part of the inventory fetching process.

Database changes

No response

External dependencies

No response

Originally created by @jiuka on GitHub (May 10, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.5.1 ### Feature type Change to existing functionality ### Proposed functionality Adding `l2vpn_terminations` and `vdcs` to the [prefetch_related](https://github.com/netbox-community/netbox/blob/develop/netbox/dcim/api/views.py#L494) in the InterfaceViewSet reduced amount of DB queries in our setup from 3185 down to 1183 for requesting 1000 Interfaces. And Reduces the request time from ~7s to ~4s. Many of the remaining queries come from the `link_peers` and `connected_endpoints` field. If possible those fiels should be prefetched as well, however I could not find out how this can be achived. (To test the impact of those fields I removed them from the Serializer to test and gotthe queries to request the same 1000 interfaces down to 57) ### Use case The Ansible [netbox.netbox.nb_inventory](https://github.com/netbox-community/ansible_modules/blob/devel/plugins/inventory/nb_inventory.py) plugin needs to fetch all interfaces if interfaces informations should be included. This is relativly slow and by far the slowest part of the inventory fetching process. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 20:31:29 +01:00
adam closed this issue 2025-12-29 20:31:29 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (May 10, 2023):

As a slight aside there's a related issue with the Interface table in the UI that I never got around to reporting. When adding the L2VPN column to the table, response time suffers heavily for the same reason the API does. I also believe there was an issue open recently about prefetching in the API, I think Arthur opened it, but not sure what came of it.

Edit:
Here's the issue: https://github.com/netbox-community/netbox/issues/11540

@kkthxbye-code commented on GitHub (May 10, 2023): As a slight aside there's a related issue with the Interface table in the UI that I never got around to reporting. When adding the L2VPN column to the table, response time suffers heavily for the same reason the API does. I also believe there was an issue open recently about prefetching in the API, I think Arthur opened it, but not sure what came of it. Edit: Here's the issue: https://github.com/netbox-community/netbox/issues/11540
Author
Owner

@DanSheps commented on GitHub (May 10, 2023):

I think we should definitely add the prefetch for the l2vpn.

The cable one is a little more difficult but I think it might still be possible to prefetch as well, I am just not sure what other implications that might have (might decrease speed but might balloon the memory requirements for example by prefetching all of that).

@DanSheps commented on GitHub (May 10, 2023): I think we should definitely add the prefetch for the l2vpn. The cable one is a little more difficult but I think it might still be possible to prefetch as well, I am just not sure what other implications that might have (might decrease speed but might balloon the memory requirements for example by prefetching all of that).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8030