diff --git a/reflex/environment.py b/reflex/environment.py index 6f6c1ccf655..9cef0565cae 100644 --- a/reflex/environment.py +++ b/reflex/environment.py @@ -556,6 +556,18 @@ class EnvironmentVariables: # Whether to check db connections before using them. SQLALCHEMY_POOL_PRE_PING: EnvVar[bool] = env_var(True) + # The size of the database connection pool. + SQLALCHEMY_POOL_SIZE: EnvVar[int] = env_var(5) + + # The maximum overflow size of the database connection pool. + SQLALCHEMY_MAX_OVERFLOW: EnvVar[int] = env_var(10) + + # Recycle connections after this many seconds. + SQLALCHEMY_POOL_RECYCLE: EnvVar[int] = env_var(-1) + + # The timeout for acquiring a connection from the pool. + SQLALCHEMY_POOL_TIMEOUT: EnvVar[int] = env_var(30) + # Whether to ignore the redis config error. Some redis servers only allow out-of-band configuration. REFLEX_IGNORE_REDIS_CONFIG_ERROR: EnvVar[bool] = env_var(False) diff --git a/reflex/model.py b/reflex/model.py index f7a9ed0ecc5..66ff9cc0ba9 100644 --- a/reflex/model.py +++ b/reflex/model.py @@ -96,6 +96,10 @@ def get_engine_args(url: str | None = None) -> dict[str, Any]: "echo": environment.SQLALCHEMY_ECHO.get(), # Check connections before returning them. "pool_pre_ping": environment.SQLALCHEMY_POOL_PRE_PING.get(), + "pool_size": environment.SQLALCHEMY_POOL_SIZE.get(), + "max_overflow": environment.SQLALCHEMY_MAX_OVERFLOW.get(), + "pool_recycle": environment.SQLALCHEMY_POOL_RECYCLE.get(), + "pool_timeout": environment.SQLALCHEMY_POOL_TIMEOUT.get(), } conf = get_config() url = url or conf.db_url