This commit is contained in:
LuiKlee
2025-12-13 16:39:25 +08:00
parent 4fe8e29ba5
commit 8f77465bc3
31 changed files with 339 additions and 322 deletions

View File

@@ -10,6 +10,7 @@ from typing import Any
import numpy as np
from src.config.config import model_config
from . import BaseDataModel

View File

@@ -9,11 +9,10 @@
import asyncio
import time
from collections import defaultdict
from collections import OrderedDict, defaultdict
from collections.abc import Awaitable, Callable
from dataclasses import dataclass, field
from typing import Any
from collections import OrderedDict
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

View File

@@ -122,7 +122,7 @@ class BroadcastLogHandler(logging.Handler):
try:
# 导入logger元数据获取函数
from src.common.logger import get_logger_meta
return get_logger_meta(logger_name)
except Exception:
# 如果获取失败,返回空元数据
@@ -138,7 +138,7 @@ class BroadcastLogHandler(logging.Handler):
try:
# 获取logger元数据别名和颜色
logger_meta = self._get_logger_metadata(record.name)
# 转换日志记录为字典
log_dict = {
"timestamp": self.format_time(record),
@@ -146,7 +146,7 @@ class BroadcastLogHandler(logging.Handler):
"logger_name": record.name, # 原始logger名称
"event": record.getMessage(),
}
# 添加别名和颜色(如果存在)
if logger_meta["alias"]:
log_dict["alias"] = logger_meta["alias"]

View File

@@ -34,7 +34,7 @@ def get_accurate_size(obj: Any, seen: set | None = None, max_depth: int = 3, _cu
# 深度限制:防止递归爆炸
if _current_depth >= max_depth:
return sys.getsizeof(obj)
# 对象数量限制:防止内存爆炸
if len(seen) > 10000:
return sys.getsizeof(obj)
@@ -55,7 +55,7 @@ def get_accurate_size(obj: Any, seen: set | None = None, max_depth: int = 3, _cu
if isinstance(obj, dict):
# 限制处理的键值对数量
items = list(obj.items())[:1000] # 最多处理1000个键值对
size += sum(get_accurate_size(k, seen, max_depth, _current_depth + 1) +
size += sum(get_accurate_size(k, seen, max_depth, _current_depth + 1) +
get_accurate_size(v, seen, max_depth, _current_depth + 1)
for k, v in items)
@@ -204,7 +204,7 @@ def estimate_cache_item_size(obj: Any) -> int:
if pickle_size > 0:
# pickle 通常略小于实际内存乘以1.5作为安全系数
return int(pickle_size * 1.5)
# 方法2: 智能估算(深度受限,采样大容器)
try:
smart_size = estimate_size_smart(obj, max_depth=5, sample_large=True)