Add CONN_MAX_AGE variable to suggested configuration #2975

Closed
opened 2025-12-29 18:24:17 +01:00 by adam · 4 comments
Owner

Originally created by @tyler-8 on GitHub (Oct 24, 2019).

Originally assigned to: @tyler-8 on GitHub.

Change Type

[X] Addition
[ ] Correction
[ ] Deprecation
[ ] Cleanup (formatting, typos, etc.)

Proposed Changes

The Django variable CONN_MAX_AGE is an non-invasive way to improve application performance by keeping the database connection open longer than a single request. This can improve performance quite a bit in applications like Netbox that rely heavily on reading and writing from the database.

The official Django optimization guide offers it up as a simple tweak to make. Further details on the setting in the database docs.

I've been using the setting in Netbox for a couple weeks now and in other in-house Django apps (for far longer) and have not encountered any side-effects. A user in the #netbox Slack also shared this

Our latency per request was lowered quite a bit and RPS went up substantially. IMO a very nice default to have in the example config.

I'm happy to submit the PR for review. My recommended starting value would be somewhere between 2-5 minutes.

Originally created by @tyler-8 on GitHub (Oct 24, 2019). Originally assigned to: @tyler-8 on GitHub. <!-- Please indicate the nature of the change by placing an X in one of the boxes below. --> ### Change Type [X] Addition [ ] Correction [ ] Deprecation [ ] Cleanup (formatting, typos, etc.) <!-- Describe the proposed change(s). --> ### Proposed Changes The Django variable `CONN_MAX_AGE` is an non-invasive way to improve application performance by keeping the database connection open longer than a single request. This can improve performance quite a bit in applications like Netbox that rely heavily on reading and writing from the database. The official Django [optimization guide](https://docs.djangoproject.com/en/2.2/topics/performance/#other-database-related-tips) offers it up as a simple tweak to make. Further details on the setting in the [database docs](https://docs.djangoproject.com/en/2.2/ref/databases/#persistent-connections). I've been using the setting in Netbox for a couple weeks now and in other in-house Django apps (for far longer) and have not encountered any side-effects. A user in the #netbox Slack also shared this > Our latency per request was lowered quite a bit and RPS went up substantially. IMO a very nice default to have in the example config. I'm happy to submit the PR for review. My recommended starting value would be somewhere between 2-5 minutes.
adam added the status: acceptedtype: documentation labels 2025-12-29 18:24:17 +01:00
adam closed this issue 2025-12-29 18:24:17 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 25, 2019):

@tyler-8 This was submitted using the documentation template but given that it would require a modification to code it's really a feature request. Could you rewrite it to follow the FR template please?

@jeremystretch commented on GitHub (Oct 25, 2019): @tyler-8 This was submitted using the documentation template but given that it would require a modification to code it's really a feature request. Could you rewrite it to follow the [FR template](https://raw.githubusercontent.com/netbox-community/netbox/develop/.github/ISSUE_TEMPLATE/feature_request.md) please?
Author
Owner

@tyler-8 commented on GitHub (Oct 25, 2019):

I'm happy to resubmit but unclear where this would require a code change. My original thought is that this really is just documentation. For clarification, the place for CONN_MAX_AGE is inside the DATABASE dictionary that users must configure themselves during installation:

DATABASE = {
    'NAME': 'netbox',               # Database name
    'USER': 'netbox',               # PostgreSQL username
    'PASSWORD': 'J5brHrAXFLQSif0K', # PostgreSQL password
    'HOST': 'localhost',            # Database server
    'PORT': '',                     # Database port (leave blank for default)
}

The places I envisioned it going were in these sections of the documentation:

I suppose the other area would be in the example configuration file: https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/configuration.example.py#L14

Other than the above example configuration file that ships with Netbox there wouldn't be any changes to code.

@tyler-8 commented on GitHub (Oct 25, 2019): I'm happy to resubmit but unclear where this would require a code change. My original thought is that this really is just documentation. For clarification, the place for `CONN_MAX_AGE` is inside the `DATABASE` dictionary that users must configure themselves during installation: ``` DATABASE = { 'NAME': 'netbox', # Database name 'USER': 'netbox', # PostgreSQL username 'PASSWORD': 'J5brHrAXFLQSif0K', # PostgreSQL password 'HOST': 'localhost', # Database server 'PORT': '', # Database port (leave blank for default) } ``` The places I envisioned it going were in these sections of the documentation: - https://github.com/netbox-community/netbox/blob/develop/docs/configuration/required-settings.md#database - https://github.com/netbox-community/netbox/blob/develop/docs/installation/2-netbox.md#database I suppose the other area would be in the example configuration file: https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/configuration.example.py#L14 Other than the above example configuration file that ships with Netbox there wouldn't be any changes to code.
Author
Owner

@jeremystretch commented on GitHub (Oct 25, 2019):

Ok, my mistake. This is fine as-is.

@jeremystretch commented on GitHub (Oct 25, 2019): Ok, my mistake. This is fine as-is.
Author
Owner

@tyler-8 commented on GitHub (Oct 25, 2019):

The takeaway here is I should have included all those details in the original issue :)

@tyler-8 commented on GitHub (Oct 25, 2019): The takeaway here is I should have included all those details in the original issue :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2975