feat(metrics): calculate remaining capacity in pg connection pool#2443
Merged
Conversation
6 tasks
Contributor
Author
|
I have made a contribution to the upstream dependency to enable it to provide these metrics in a more concise manner. Vincit/tarn.js#80 |
gjedlicska
approved these changes
Jun 26, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description & motivation
The knex metric for 'free' connections only reports the number of existing created connections which are free prior to being garbage collected.
It does not take into account the additional capacity for creating new connections up to the maximum assigned to the connection pool. Additionally, these created connections can be removed as part of a garbage collection (aka 'reaping') process. As such the existing metric for free connections is unreliable. See #2441 for deeper investigation of the issue.
This PR adds a new metric which calculates the remaining capacity for adding additional new connections, accounting for the demand from existing in-use connections, pending acquisitions of these existing connections, and pending creations of new connections.
This PR also add a new metric for the pending creations of new connections.
Changes:
speckle_server_knex_remaining_capacityspeckle_server_knex_pending_createsAdds the above to the server, webhook service, file import service, and the preview service.
To-do before merge:
Screenshots:
The new metrics are in yellow (remaining capacity), and red (pending creations). The previous metric is in blue and is not accurate (see timestamp at 19:03, for example).

We can see here in this close up that the remaining capacity, yellow, is at zero, despite there not being the maximum of used connections, green. This is because the remaining capacity takes into account pending acquisitions and creations. In this case it is pending creations, see in red which reduce the capacity to zero.

Validation of changes:
See PR #2441 for the validation of changes
Checklist:
References