main:采用异步 Redis 客户端优化指标管理模块
变更内容: - 将 `redis` 客户端替换为 `redis.asyncio` 实现。 - 系统中同步方法调整为异步方法,提升事件循环效率。 - 在 `MetricsManager` 中添加异步初始化及关闭逻辑,避免阻塞问题。 - 更新便捷函数以支持异步上下文,并添加同步模式的兼容方法。 - 调整 Worker、JobManager、API 路由等模块,适配异步指标操作。 - 扩展单元测试,覆盖新增的异步方法及 Redis 操作逻辑。 - 简化 Dockerfile,取消开发依赖安装命令。
This commit is contained in:
@@ -32,7 +32,7 @@ class BaseAlgorithm(ABC):
|
||||
Returns:
|
||||
Dict[str, Any]: 包含结果和元数据的字典
|
||||
"""
|
||||
from ..core.metrics_unified import incr, observe
|
||||
from ..core.metrics_unified import incr_sync, observe_sync
|
||||
|
||||
start_time = time.time()
|
||||
status = "success"
|
||||
@@ -71,5 +71,7 @@ class BaseAlgorithm(ABC):
|
||||
finally:
|
||||
# 记录算法执行指标
|
||||
elapsed_time = time.time() - start_time
|
||||
incr("algorithm_executions_total", {"algorithm": self.name, "status": status})
|
||||
observe("algorithm_execution_duration_seconds", {"algorithm": self.name}, elapsed_time)
|
||||
incr_sync("algorithm_executions_total", {"algorithm": self.name, "status": status})
|
||||
observe_sync(
|
||||
"algorithm_execution_duration_seconds", {"algorithm": self.name}, elapsed_time
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user