Skip to content

Make DB connection-pool size configurable via env - #10

Merged
sls701 merged 1 commit into
mainfrom
chore/configurable-db-pool
Jun 5, 2026
Merged

sls701 merged 1 commit into
mainfrom
chore/configurable-db-pool

Conversation

@Vilin97

@Vilin97 Vilin97 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Why

The per-process connection pool was hard-coded to min=5 / max=40. Each running instance opens up to max connections per dbname, and on App Runner the service scales to MaxSize instances, so worst-case connections to the Aurora cluster are:

MaxSize × pool_max × (#dbnames)

There was no way to tune this against the cluster's max_connections (or cap it when fronting with RDS Proxy) without a code change.

Change

  • RDS_POOL_MIN / RDS_POOL_MAX / RDS_STATEMENT_TIMEOUT_MS are now env-configurable via a small _env_int helper.
  • Defaults are unchanged (5 / 40 / 10000) — no behavior change unless the env vars are set.
  • min is clamped to max on misconfiguration; invalid/clamped values are logged as warnings so a bad deploy is diagnosable instead of silently falling back.
  • Documents the Aurora connection-budget math inline.

Review

Multi-agent adversarial review found no bugs (the _env_int edge cases — blank/non-numeric/negative/zero/min>max — all resolve to a valid (minconn, maxconn)).

Independent of the other PRs. The env vars are referenced by the docs/apprunner-scaling-runbook PR.

The per-process pool was hard-coded to min=5/max=40. Each running instance
opens up to max connections per dbname, and on App Runner the service scales
to MaxSize instances, so total connections to the Aurora cluster can be
MaxSize × pool_max × (#dbnames). Expose RDS_POOL_MIN / RDS_POOL_MAX /
RDS_STATEMENT_TIMEOUT_MS so this can be tuned against the cluster's
max_connections (or capped when fronting with RDS Proxy) without a code
change. Defaults are unchanged; min is clamped to max on misconfig.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds environment-variable configurability for the per-process RDS connection pool bounds and statement timeout in the API layer, allowing operational tuning of Aurora/RDS Proxy connection budgets without code changes.

Changes:

  • Introduces a small _env_int helper to parse positive integers from env vars with warning logs on invalid values.
  • Makes _POOL_MIN, _POOL_MAX, and _STATEMENT_TIMEOUT_MS configurable via RDS_POOL_MIN, RDS_POOL_MAX, and RDS_STATEMENT_TIMEOUT_MS while keeping existing defaults (5 / 40 / 10000).
  • Clamps RDS_POOL_MIN down to RDS_POOL_MAX when misconfigured and documents the connection-budget math inline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sls701
sls701 merged commit 8afb34d into main Jun 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants