fix: add DB connection pooling and reduce MySQL pool defaults#57
Merged
fix: add DB connection pooling and reduce MySQL pool defaults#57
Conversation
MySQL: reduce default pool from min=10/max=100 to min=0/max=10, matching Go database/sql behavior of not pre-creating connections. Respects user-provided pool_min/pool_max URL params and ASHERAH_POOL_SIZE env var. PostgreSQL: add connection pooling where previously every query opened a new TCP+TLS connection. Pool tracks max_open=10 and max_idle=2 (matching Go database/sql MaxIdleConns default). Connections returned to pool on scope exit via Drop, with stale connection detection via is_closed().
With min=0 pool connections, Pool::new() no longer pre-creates connections, so connect() succeeds even with a bad URL. The error now surfaces on first use, matching the Postgres test pattern.
3 tasks
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
database/sqlbehavior of not pre-creating connections. Existing user-providedpool_min/pool_maxURL params are respected. Configurable viaASHERAH_POOL_SIZEenv var.max_open=10andmax_idle=2(matching Go'sdatabase/sqlMaxIdleConnsdefault). Connections returned to pool on scope exit viaDrop, with stale connection detection viais_closed(). Returns error if pool exhausted.Fixes "1040: Too many connections" errors seen in Test with Aurora MySQL when multiple services/processes share the same database.
Test plan
cargo test -p asherah --features mysql,postgrestests passcargo clippyclean with-D warnings