Skip to content

Commit 87160f3

Browse files
authored
add polardb pool config (#702)
1 parent 38b495e commit 87160f3

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/memos/api/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ def get_polardb_config(user_id: str | None = None) -> dict[str, Any]:
590590
"user": os.getenv("POLAR_DB_USER", "root"),
591591
"password": os.getenv("POLAR_DB_PASSWORD", "123456"),
592592
"db_name": db_name,
593+
"maxconn": int(os.getenv("POLARDB_POOL_MAX_CONN", "100")),
593594
"user_name": user_name,
594595
"use_multi_db": use_multi_db,
595596
"auto_create": True,

src/memos/configs/graph_db.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ class PolarDBGraphDBConfig(BaseConfig):
198198
),
199199
)
200200
embedding_dimension: int = Field(default=1024, description="Dimension of vector embedding")
201+
maxconn: int = Field(
202+
default=100,
203+
description="Maximum number of connections in the connection pool",
204+
)
201205

202206
@model_validator(mode="after")
203207
def validate_config(self):

src/memos/graph_dbs/polardb.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,27 @@ def __init__(self, config: PolarDBGraphDBConfig):
136136
port = config.get("port")
137137
user = config.get("user")
138138
password = config.get("password")
139+
maxconn = config.get("maxconn", 100) # De
139140
else:
140141
self.db_name = config.db_name
141142
self.user_name = config.user_name
142143
host = config.host
143144
port = config.port
144145
user = config.user
145146
password = config.password
147+
maxconn = config.maxconn if hasattr(config, "maxconn") else 100
146148
"""
147149
# Create connection
148150
self.connection = psycopg2.connect(
149151
host=host, port=port, user=user, password=password, dbname=self.db_name,minconn=10, maxconn=2000
150152
)
151153
"""
154+
logger.info(f" db_name: {self.db_name} current maxconn is:'{maxconn}'")
152155

153156
# Create connection pool
154157
self.connection_pool = psycopg2.pool.ThreadedConnectionPool(
155158
minconn=5,
156-
maxconn=100,
159+
maxconn=maxconn,
157160
host=host,
158161
port=port,
159162
user=user,
@@ -216,6 +219,7 @@ def _get_connection(self):
216219
Raises:
217220
RuntimeError: If connection pool is closed or exhausted after retries
218221
"""
222+
logger.info(f" db_name: {self.db_name} pool maxconn is:'{self.connection_pool.maxconn}'")
219223
if self._pool_closed:
220224
raise RuntimeError("Connection pool has been closed")
221225

0 commit comments

Comments
 (0)