Repository navigation
feat(settings): pool database connections in web processes - #1207
Draft
tintinhamans wants to merge 3 commits into
Draft
tintinhamans wants to merge 3 commits into
tintinhamans wants to merge 3 commits into
Conversation
…corn Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
…the pool Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
Signed-off-by: tintinhamans <5984296+tintinhamans@users.noreply.github.com>
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.
SUMMARY
Follow-up to #1203, and built on it. Under uvicorn
CONN_MAX_AGEcan't reuse connections, so this uses Django's pool for web processes instead. Each uvicorn worker keeps 2 to 4 connections.DATABASE_POOLchanges that, andFalseturns it off.psycopg-poolis LGPL, so I added its source tolicenses/. The license test couldn't match that tarball's name, so I fixed the matcher too.A settings read on the event loop (#1033) blocks the loop while a thread runs the query. Requests return their connections from that loop, so with a pool that read waited on connections that couldn't come back: 30 seconds, then the default. The debug toolbar does this on every response. That thread now connects outside the pool.
5 uvicorn workers, 400 requests through 100 threads, PostgreSQL 18:
CONN_MAX_AGE=60, before #1203ISSUE TYPE
COMPONENT NAME
ASCENDER VERSION