Skip to content

Commit 7f000bf

Browse files
authored
chore: reduce default db pool sizes (#908)
1 parent 6e2ac2f commit 7f000bf

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

components/renku_data_services/db_config/config.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DBConfig:
2020
port: str = "5432"
2121
db_name: str = "renku"
2222
_async_engine: ClassVar[AsyncEngine | None] = field(default=None, repr=False, init=False)
23+
pool_size: int = 4
2324

2425
@classmethod
2526
def from_env(cls) -> "DBConfig":
@@ -29,13 +30,20 @@ def from_env(cls) -> "DBConfig":
2930
pg_user = os.environ.get("DB_USER")
3031
pg_port = os.environ.get("DB_PORT")
3132
db_name = os.environ.get("DB_NAME")
33+
pool_size = int(os.environ.get("DB_POOL_SIZE", "4"))
3234
pg_password = os.environ.get("DB_PASSWORD")
3335
if pg_password is None:
3436
raise errors.ConfigurationError(
3537
message="Please provide a database password in the 'DB_PASSWORD' environment variable."
3638
)
37-
kwargs = {"host": pg_host, "password": pg_password, "port": pg_port, "db_name": db_name, "user": pg_user}
38-
config = cls(**{k: v for (k, v) in kwargs.items() if v is not None})
39+
config = cls(
40+
password=pg_password,
41+
host=pg_host or "localhost",
42+
user=pg_user or "renku",
43+
port=pg_port or "5432",
44+
db_name=db_name or "renku",
45+
pool_size=pool_size,
46+
)
3947
return config
4048

4149
def conn_url(self, async_client: bool = True) -> str:
@@ -50,7 +58,7 @@ def async_session_maker(self) -> Callable[..., AsyncSession]:
5058
if not DBConfig._async_engine:
5159
DBConfig._async_engine = create_async_engine(
5260
self.conn_url(),
53-
pool_size=10,
61+
pool_size=self.pool_size,
5462
max_overflow=0,
5563
)
5664
return async_sessionmaker(DBConfig._async_engine, expire_on_commit=False)

projects/renku_data_service/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ COPY --from=builder /usr/bin/rclone /usr/bin
4646
USER $USER_UID:$USER_GID
4747
WORKDIR /app
4848
COPY --from=builder /app/env ./env
49+
ENV DB_POOL_SIZE=10
4950
ENTRYPOINT ["tini", "-g", "--", "env/bin/python", "-m", "renku_data_services.data_api.main"]

0 commit comments

Comments
 (0)