fix: pool DB connections to prevent Supabase client exhaustion#61
Open
madhavcodez wants to merge 1 commit intomainfrom
Open
fix: pool DB connections to prevent Supabase client exhaustion#61madhavcodez wants to merge 1 commit intomainfrom
madhavcodez wants to merge 1 commit intomainfrom
Conversation
Configure the SQLAlchemy engine with pool_size=5, max_overflow=5, pool_pre_ping=True, and pool_recycle=300. Without pooling, every request opened a fresh connection, causing OperationalError: too many clients under modest traffic on Supabase's shared connection cap. Closes #60
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
What this does
Adds connection pooling to the SQLAlchemy engine so the backend reuses a small set of warm database connections instead of opening a fresh one for every single request.
Why
Without pooling, hammering the map (pan + /locations + /image-pairs fires many requests per second) would exhaust the Supabase free-tier connection cap and the backend would start returning
OperationalError: too many clients. Five workers + five overflow + pre-ping + 5-minute recycle keeps usage safely under the shared cap while surviving Supabase's idle drops.Plain-English settings
pool_size=5— keep 5 warm connections ready to reusemax_overflow=5— allow up to 5 extra short-lived connections during spikespool_pre_ping=True— test a connection withSELECT 1before using it, in case Supabase dropped it while idlepool_recycle=300— throw away any connection older than 5 minutes to avoid stale TCP stateHow to verify
Pan the map hard for 30 seconds. Backend logs stay clean; no
too many clientserrors.Closes #60