[AAP-103723] perf(db): enable CONN_MAX_AGE and CONN_HEALTH_CHECKS on default database #553
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 521 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.374
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #553"
general
weight: 0.35
redhat-chai-bot
Description
- Sets
CONN_MAX_AGE = 60andCONN_HEALTH_CHECKS = TrueonDATABASES["default"]inapps/settings/defaults.py.- Sets
DATABASES__default__CONN_MAX_AGE = 0inapps/settings/test.pyso pytest database teardown/reuse does not encounter lingering connections.- Leaves
DATABASES["awx"]untouched (its raw psycopg3 connection andSELECT 1probe are already managed inapps/tasks/utils.py::get_db_connection()).- Adds unit tests in
tests/unit/test_database_connection_settings.pycovering defaults,awxisolation, andtest.pyoverrides.- Without
CONN_MAX_AGE, Django defaults to0, closing and reopening the PostgreSQL connection on every HTTP request. Each request pays a full TCP/TLS handshake, authentication round-trip, and PostgreSQL backend fork.- Each Gunicorn worker reuses its warm PostgreSQL connection for up to 60 seconds across requests.
-
CONN_HEALTH_CHECKS = Truevalidates reused connections before executing queries and transparently reconnects if the database or network closed the session.- Background paths (
UnifiedTaskSchedulerandrun_with_lock) already callclose_old_connections(), so connection lifetimes remain bounded there as well.Type of Change
Self-Review Checklist
Testing Instructions
Prerequisites
make composeor local test DB)Steps to Test
1. Run lint and format checks:
2. Run settings and validator unit tests:
Expected Results
CONN_MAX_AGE == 60andCONN_HEALTH_CHECKS is Trueindefaults.py,awxunchanged,CONN_MAX_AGE == 0underMETRICS_SERVICE_MODE=test, and all production Dynaconf validators pass).Additional Context
Paired Benchmark Results
Measured on a containerized reference deployment (
x86_64, RHEL 9.6, Python 3.12.16, Django 5.2.19, remote PostgreSQL 15.14) using 3 alternating(baseline, candidate)pairs in separate fresh 1-worker Gunicorn processes, timing 200 sequential HTTPGET /health/requests per run (with identical SHA-256 HTTP response digests across all 6 runs):| Metric | Baseline (
CONN_MAX_AGE=0) | Candidate (CONN_MAX_AGE=60,CONN_HEALTH_CHECKS=True) | Delta ||---|---:|---:|---:|
| Median wall time (200 reqs) |
1.358 s|0.342 s| 3.97× faster (-74.8%) || Median per-request latency |
6.62 ms|1.68 ms| -4.94 ms/req || New PostgreSQL sessions (
pg_stat_database.sessions) |200|0| Eliminated per-request churn |Operational note: With the default
GUNICORN_WORKERS=4, persistent connections hold at most 1 idle connection per active Gunicorn worker for up to 60 seconds (up to +4 connections per web container). Operators can still override viaMETRICS_SERVICE_DATABASES__default__CONN_MAX_AGE.