Skip to content

Commit

Permalink
customize pool_size and max_overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ssadhu-sl committed Jan 3, 2025
1 parent e0b33e9 commit 752f511
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 7 additions & 0 deletions application/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
from sqlalchemy.orm import Session

from application.settings import get_settings
import logging

logger = logging.getLogger(__name__)


# this can be used in fast api path functions using Depends to inject a db session
def get_session() -> Iterator[Session]:
logger.info(
f"Database engine created with pool_size={get_settings().DB_POOL_SIZE}, "
f"max_overflow={get_settings().DB_POOL_MAX_OVERFLOW}"
)
yield from _get_fastapi_sessionmaker().get_db()


Expand Down
10 changes: 2 additions & 8 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,8 @@ def run_migrations_online():
url = config.get_main_option("sqlalchemy.url")
else:
url = get_settings().WRITE_DATABASE_URL
engine = create_engine(
url,
pool_size=get_settings().DB_POOL_SIZE,
max_overflow=get_settings().DB_POOL_MAX_OVERFLOW,
)
logging.info(
f"Connection Pool: pool_size={engine.pool.size()}, max_overflow={engine.pool._max_overflow}"
)

engine = create_engine(url)
connectable = engine

with connectable.connect() as connection:
Expand Down

0 comments on commit 752f511

Please sign in to comment.