fix: Postgres store 自愈连接池 + 启用 PG checkpointer + 分析查询超时按服务端适配
- async_provider: AsyncPostgresStore 改用连接池(check_connection 校验), 避免单条长连接在服务重启/空闲超时后永久失效;池大小可经 DEER_FLOW_PG_POOL_MIN/MAX 环境变量调整 - admin_users: 排行榜分析查询的每语句超时按服务端区分 (MySQL>=5.7.4 max_execution_time / MariaDB max_statement_time / MySQL<=5.6 跳过 / PostgreSQL statement_timeout) - config.yaml: checkpointer.use_postgres 置为 true Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
50d70a5050
commit
40206dc94d
3 files changed
+66
-7
No files matched your search
+38
-2
@@ -28,6 +28,42 @@ from deerflow.runtime.store.provider import POSTGRES_CONN_REQUIRED, POSTGRES_STO
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _pool_size_env(name: str, default: int) -> int:
|
||||
import os
|
||||
|
||||
raw = os.getenv(name, "").strip()
|
||||
if not raw:
|
||||
return default
|
||||
try:
|
||||
return max(0, int(raw))
|
||||
except ValueError:
|
||||
logger.warning("Invalid %s=%r; using default %d", name, raw, default)
|
||||
return default
|
||||
|
||||
|
||||
def _postgres_pool_config() -> dict:
|
||||
"""Pool config for the Postgres store.
|
||||
|
||||
A single long-lived connection (the default ``from_conn_string`` behavior)
|
||||
dies permanently on a server restart / idle timeout / network blip — every
|
||||
later store call then fails with "server closed the connection
|
||||
unexpectedly". A pool with ``check=check_connection`` validates each
|
||||
connection on checkout and replaces dead ones, so the runtime self-heals.
|
||||
Extra keys (``check``/``max_idle``/``max_lifetime``) are passed straight
|
||||
through to ``AsyncConnectionPool`` by ``from_conn_string``.
|
||||
"""
|
||||
from psycopg_pool import AsyncConnectionPool
|
||||
|
||||
return {
|
||||
"min_size": _pool_size_env("DEER_FLOW_PG_POOL_MIN", 1),
|
||||
"max_size": _pool_size_env("DEER_FLOW_PG_POOL_MAX", 10),
|
||||
"check": AsyncConnectionPool.check_connection,
|
||||
"max_idle": 300.0,
|
||||
"max_lifetime": 3600.0,
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Internal backend factory
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -71,9 +107,9 @@ async def _async_store(config) -> AsyncIterator[BaseStore]:
|
||||
if not config.connection_string:
|
||||
raise ValueError(POSTGRES_CONN_REQUIRED)
|
||||
|
||||
async with AsyncPostgresStore.from_conn_string(config.connection_string) as store:
|
||||
async with AsyncPostgresStore.from_conn_string(config.connection_string, pool_config=_postgres_pool_config()) as store:
|
||||
await store.setup()
|
||||
logger.info("Store: using AsyncPostgresStore")
|
||||
logger.info("Store: using AsyncPostgresStore (pooled, self-healing)")
|
||||
yield store
|
||||
return
|
||||
|
||||
|
||||
Reference in new issue
Block a user