File tree Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,14 @@ DB_PASSWORD = 'mysqlroot'
4242DB_DATABASE = ' dash-fastapi'
4343# 是否开启sqlalchemy日志
4444DB_ECHO = true
45+ # 允许溢出连接池大小的最大连接数
46+ DB_MAX_OVERFLOW = 10
47+ # 连接池大小,0表示连接数无限制
48+ DB_POOL_SIZE = 50
49+ # 连接回收时间(单位:秒)
50+ DB_POOL_RECYCLE = 3600
51+ # 连接池中没有线程可用时,最多等待的时间(单位:秒)
52+ DB_POOL_TIMEOUT = 30
4553
4654# -------- Redis配置 --------
4755# Redis主机
Original file line number Diff line number Diff line change @@ -42,6 +42,14 @@ DB_PASSWORD = 'mysqlroot'
4242DB_DATABASE = ' dash-fastapi'
4343# 是否开启sqlalchemy日志
4444DB_ECHO = true
45+ # 允许溢出连接池大小的最大连接数
46+ DB_MAX_OVERFLOW = 10
47+ # 连接池大小,0表示连接数无限制
48+ DB_POOL_SIZE = 50
49+ # 连接回收时间(单位:秒)
50+ DB_POOL_RECYCLE = 3600
51+ # 连接池中没有线程可用时,最多等待的时间(单位:秒)
52+ DB_POOL_TIMEOUT = 30
4553
4654# -------- Redis配置 --------
4755# Redis主机
Original file line number Diff line number Diff line change 88 f"{ DataBaseConfig .db_host } :{ DataBaseConfig .db_port } /{ DataBaseConfig .db_database } "
99
1010engine = create_engine (
11- SQLALCHEMY_DATABASE_URL , echo = DataBaseConfig .db_echo
11+ SQLALCHEMY_DATABASE_URL ,
12+ echo = DataBaseConfig .db_echo ,
13+ max_overflow = DataBaseConfig .db_max_overflow ,
14+ pool_size = DataBaseConfig .db_pool_size ,
15+ pool_recycle = DataBaseConfig .db_pool_recycle ,
16+ pool_timeout = DataBaseConfig .db_pool_timeout
1217)
1318SessionLocal = sessionmaker (autocommit = False , autoflush = False , bind = engine )
1419Base = declarative_base ()
Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ class DataBaseSettings(BaseSettings):
4141 db_password : str = 'mysqlroot'
4242 db_database : str = 'dash-fastapi'
4343 db_echo : bool = True
44+ db_max_overflow : int = 10
45+ db_pool_size : int = 50
46+ db_pool_recycle : int = 3600
47+ db_pool_timeout : int = 30
4448
4549
4650class RedisSettings (BaseSettings ):
You can’t perform that action at this time.
0 commit comments