diff --git a/backend/druks/database.py b/backend/druks/database.py index 0c4bbc7d..aa37929d 100644 --- a/backend/druks/database.py +++ b/backend/druks/database.py @@ -81,8 +81,19 @@ def create_engine_from_url(database_url: str): # at the lifecycle boundary (the API session dependency, the worker session # wrapper) so a failed unit of work rolls back instead of leaving partial # writes. Model methods ``flush()``; the boundary commits. Low pool_timeout - # because a checkout wait blocks the event loop. - return create_engine(database_url, pool_pre_ping=True, pool_timeout=5) + # because a checkout wait blocks the event loop. The pool serves every + # concurrent run's steps plus request handling at once: a modest steady + # pool, with overflow doing the burst work — overflow connections open on + # demand and close on return, so the ceiling is high while idle cost is + # not. Ceiling 50 keeps the appliance (with DBOS's two engines at 20 each) + # inside Postgres's default 100 connections. + return create_engine( + database_url, + pool_pre_ping=True, + pool_timeout=5, + pool_size=20, + max_overflow=30, + ) def get_session(engine) -> Session: