feat(gateway): worker 池主备分组派发,主全挂才用备机
- pool.py: WorkerState 增加 primary 标记;acquire_worker 分级派发—— 主组有在线只在主组内挑空闲(全忙排队,不退备组),主组全部下线才用备机 - config.py: 新增可选 primary_workers 配置(须为 workers 子集,自动过滤+告警); 不配置/空列表 = 全部视为主 worker,兼容旧行为 - config.json(不入 git): 3 台 GPU worker 设为主,max_global_concurrency 1→3 - app.py: /health 增加 workers_primary_total / workers_primary_healthy - tests: 新增 4 条主备派发单测(主优先/主全挂用备/主全忙不走备/无配置兼容) - docs(实现说明): 补充 primary_workers 配置说明,改配置需重启网关生效
This commit is contained in:
@@ -15,6 +15,7 @@ CONFIG_PATH = Path(__file__).resolve().parent / "config.json"
|
||||
DEFAULTS = {
|
||||
"public_base_url": "https://hair.xiangsilian.com",
|
||||
"static_dir": "static/annotations",
|
||||
"primary_workers": [], # 主 worker 地址列表(须为 workers 的子集);空 = 全部视为主 worker
|
||||
"health_check": {
|
||||
"path": "/health",
|
||||
"interval_seconds": 8,
|
||||
@@ -83,6 +84,15 @@ def load_config() -> dict:
|
||||
if not isinstance(w, str) or not w:
|
||||
raise ValueError(f"配置错误: workers[{i}] 必须是非空字符串")
|
||||
|
||||
primary_workers: List[str] = cfg.get("primary_workers", [])
|
||||
for i, w in enumerate(primary_workers):
|
||||
if not isinstance(w, str) or not w:
|
||||
raise ValueError(f"配置错误: primary_workers[{i}] 必须是非空字符串")
|
||||
for w in primary_workers:
|
||||
if w not in workers:
|
||||
logger.warning("⚠ primary_workers 中的 %s 不在 workers 列表里,将被忽略", w)
|
||||
cfg["primary_workers"] = [w for w in primary_workers if w in workers]
|
||||
|
||||
password: str = cfg.get("shared_password", "")
|
||||
if not password or password == "REPLACE_ME_ROTATE_PERIODICALLY":
|
||||
logger.warning(
|
||||
|
||||
Reference in New Issue
Block a user