Skip to content

Commit 910e0c7

Browse files
add sqlalchemy client pool configuration options via env vars (#5751)
1 parent dd993fd commit 910e0c7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

reflex/environment.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,18 @@ class EnvironmentVariables:
556556
# Whether to check db connections before using them.
557557
SQLALCHEMY_POOL_PRE_PING: EnvVar[bool] = env_var(True)
558558

559+
# The size of the database connection pool.
560+
SQLALCHEMY_POOL_SIZE: EnvVar[int] = env_var(5)
561+
562+
# The maximum overflow size of the database connection pool.
563+
SQLALCHEMY_MAX_OVERFLOW: EnvVar[int] = env_var(10)
564+
565+
# Recycle connections after this many seconds.
566+
SQLALCHEMY_POOL_RECYCLE: EnvVar[int] = env_var(-1)
567+
568+
# The timeout for acquiring a connection from the pool.
569+
SQLALCHEMY_POOL_TIMEOUT: EnvVar[int] = env_var(30)
570+
559571
# Whether to ignore the redis config error. Some redis servers only allow out-of-band configuration.
560572
REFLEX_IGNORE_REDIS_CONFIG_ERROR: EnvVar[bool] = env_var(False)
561573

reflex/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def get_engine_args(url: str | None = None) -> dict[str, Any]:
9696
"echo": environment.SQLALCHEMY_ECHO.get(),
9797
# Check connections before returning them.
9898
"pool_pre_ping": environment.SQLALCHEMY_POOL_PRE_PING.get(),
99+
"pool_size": environment.SQLALCHEMY_POOL_SIZE.get(),
100+
"max_overflow": environment.SQLALCHEMY_MAX_OVERFLOW.get(),
101+
"pool_recycle": environment.SQLALCHEMY_POOL_RECYCLE.get(),
102+
"pool_timeout": environment.SQLALCHEMY_POOL_TIMEOUT.get(),
99103
}
100104
conf = get_config()
101105
url = url or conf.db_url

0 commit comments

Comments
 (0)