Skip to content

Commit 7e2a605

Browse files
authored
Reduce db conn pool size and increase max conns (#630)
1 parent fc39d9e commit 7e2a605

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ node_modules/
66
/playwright/.cache/
77
.env
88
.DS_Store
9+
TODO.md
10+
AGENTS_files

backend/app/db.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
max_tries = 60 * 5 # 5 minutes
2222
wait_seconds = 1
2323

24+
# Each worker process gets its own pool, so keep per-process limits modest:
25+
# with 12 workers (8 backend + 4 backend-dvc), 5 + 5 = 10 per process gives a
26+
# 120-connection worst case, comfortably under the db's max_connections (300).
2427
engine = create_engine(
25-
str(settings.SQLALCHEMY_DATABASE_URI), pool_size=10, max_overflow=10
28+
str(settings.SQLALCHEMY_DATABASE_URI), pool_size=5, max_overflow=5
2629
)
2730

2831
# make sure all SQLModel models are imported (app.models) before initializing DB

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ services:
22
db:
33
image: postgres:16
44
restart: always
5+
# Raise the default max_connections (100) to accommodate per-worker
6+
# connection pools across all backend processes. See backend/app/db.py.
7+
command: ["postgres", "-c", "max_connections=300"]
58
healthcheck:
69
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
710
interval: 10s

0 commit comments

Comments
 (0)