feat(statistic): 延迟统计任务启动时间和运行间隔以优化性能
fix(engine): 禁用 SQLAlchemy 查询编译缓存以防止 tuple 膨胀 fix(message_repository): 优化日志输出格式以提高可读性
This commit is contained in:
@@ -121,7 +121,7 @@ class StatisticOutputTask(AsyncTask):
|
|||||||
|
|
||||||
def __init__(self, record_file_path: str = "mofox_bot_statistics.html"):
|
def __init__(self, record_file_path: str = "mofox_bot_statistics.html"):
|
||||||
# 延迟300秒启动,运行间隔300秒
|
# 延迟300秒启动,运行间隔300秒
|
||||||
super().__init__(task_name="Statistics Data Output Task", wait_before_start=0, run_interval=300)
|
super().__init__(task_name="Statistics Data Output Task", wait_before_start=600, run_interval=900)
|
||||||
|
|
||||||
self.name_mapping: dict[str, tuple[str, float]] = {}
|
self.name_mapping: dict[str, tuple[str, float]] = {}
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ def _build_sqlite_config(config) -> tuple[str, dict]:
|
|||||||
"check_same_thread": False,
|
"check_same_thread": False,
|
||||||
"timeout": 60,
|
"timeout": 60,
|
||||||
},
|
},
|
||||||
|
# ⚠️ 禁用 SQLAlchemy 查询编译缓存以阻断可能的 tuple 膨胀
|
||||||
|
# 观察到长时间运行后 tuple 数量飙升,先通过关闭缓存止血
|
||||||
|
"query_cache_size": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(f"SQLite配置: {db_path}")
|
logger.debug(f"SQLite配置: {db_path}")
|
||||||
@@ -162,6 +165,8 @@ def _build_postgresql_config(config) -> tuple[str, dict]:
|
|||||||
"pool_timeout": config.connection_timeout,
|
"pool_timeout": config.connection_timeout,
|
||||||
"pool_recycle": 3600,
|
"pool_recycle": 3600,
|
||||||
"pool_pre_ping": True,
|
"pool_pre_ping": True,
|
||||||
|
# ⚠️ 禁用 SQLAlchemy 查询编译缓存以阻断可能的 tuple 膨胀
|
||||||
|
"query_cache_size": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if connect_args:
|
if connect_args:
|
||||||
|
|||||||
@@ -112,16 +112,13 @@ async def find_messages(
|
|||||||
if limit <= 0:
|
if limit <= 0:
|
||||||
capped_limit = SAFE_FETCH_LIMIT
|
capped_limit = SAFE_FETCH_LIMIT
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"find_messages 未指定 limit,自动限制为 %s 行以避免内存占用过高",
|
f"find_messages 未指定 limit,自动限制为 {capped_limit} 行以避免内存占用过高",
|
||||||
capped_limit,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
capped_limit = max(1, int(limit))
|
capped_limit = max(1, int(limit))
|
||||||
if capped_limit > SAFE_FETCH_LIMIT:
|
if capped_limit > SAFE_FETCH_LIMIT:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"find_messages 请求的 limit=%s 超过安全上限,已限制为 %s",
|
f"find_messages 请求的 limit={limit} 超过安全上限,已限制为 {SAFE_FETCH_LIMIT}",
|
||||||
limit,
|
|
||||||
SAFE_FETCH_LIMIT,
|
|
||||||
)
|
)
|
||||||
capped_limit = SAFE_FETCH_LIMIT
|
capped_limit = SAFE_FETCH_LIMIT
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user