Degradation of GraphQL and Rest API query performance #10522

Closed
opened 2025-12-29 21:32:35 +01:00 by adam · 3 comments
Owner

Originally created by @TheLastochka on GitHub (Nov 29, 2024).

Deployment Type

Self-hosted

Triage priority

I'm a NetBox Labs customer

NetBox Version

v4.1.6

Python Version

3.11

Steps to Reproduce

  1. Netbox version >= 4.0.0
  2. The database contains about 27k ip addresses
  3. 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:

  1. This query produced 5k database queries (execution time: 14 seconds).
  2. 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:

  1. The same query produces 87k database queries (execution time: 7.6 minutes).
  2. 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 https://github.com/netbox-community/netbox/issues/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 https://github.com/netbox-community/netbox/discussions/18107

Originally created by @TheLastochka on GitHub (Nov 29, 2024). ### Deployment Type Self-hosted ### Triage priority I'm a NetBox Labs customer ### NetBox Version v4.1.6 ### Python Version 3.11 ### Steps to Reproduce 1. Netbox version >= 4.0.0 2. The database contains about 27k ip addresses 3. 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: 1. This query produced 5k database queries (execution time: 14 seconds). 2. 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: 1. The same query produces 87k database queries (execution time: 7.6 minutes). 2. 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 https://github.com/netbox-community/netbox/issues/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 https://github.com/netbox-community/netbox/discussions/18107_
adam closed this issue 2025-12-29 21:32:35 +01:00
Author
Owner

@arthanson commented on GitHub (Dec 5, 2024):

Hacked a quick script to generate ip addresses and was able to replicate, probably needs select_related in the GraphQL queries. There is a query optimizer built into Strawberry, not sure why it isn't optimizing these.

@arthanson commented on GitHub (Dec 5, 2024): Hacked a quick script to generate ip addresses and was able to replicate, probably needs select_related in the GraphQL queries. There is a query optimizer built into Strawberry, not sure why it isn't optimizing these.
Author
Owner

@github-actions[bot] commented on GitHub (Apr 24, 2025):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Apr 24, 2025): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/main/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (May 25, 2025):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (May 25, 2025): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10522