Degradation of GraphQL and Rest API query performance #18120
Open
Description
Deployment Type
Self-hosted
Triage priority
I'm a NetBox Labs customer
NetBox Version
v4.1.6
Python Version
3.11
Steps to Reproduce
- Netbox version >= 4.0.0
- The database contains about 27k ip addresses
- Send the following Graphql query:
query getIpAddresses {
resp:ip_address_list {
id
address
status
description
dns_name
tenant {
id
name
}
assigned_object {
__typename
... on InterfaceType {
id
name
}
... on VMInterfaceType {
id
name
}
}
custom_fields
}
}
After switching to the Strawberry library (netbox v4.0.0), there has been a significant degradation in the performance of API requests, including Graphql.
When executing a request to get custom fields or an assigned objects, Graphql performs additional queries to the database in large numbers.
Expected Behavior
It works in Netbox v3.7.8:
- This query produced 5k database queries (execution time: 14 seconds).
- If you remove assigned_object's and custom_fields from this Graphql query, the execution time does not change (slightly).
Observed Behavior
Netbox v4.0.0 (Strawberry) and after:
- The same query produces 87k database queries (execution time: 7.6 minutes).
- If you remove assigned_object's and custom_fields from this Graphql query, the execution time drops to the expected values (execution time is 8 seconds).
Previously, there was a similar problem on the netbox v3.4 version #11291
However, it was fixed in version v3.5 by writing optimizers.
After switching to Strawberry, the optimizers remained in the old code. And the problem is back.
Originally posted by @TheLastochka in #18107