Commit 4c014c9fe3a04610dcc0f5ae8a2ca83813e6ca2e
1 parent
8b1a0d22
raylight: 修复 /health 排队计数误把已取消任务算进 queued
Q.qsize() 是底层 PriorityQueue 的原始元素数,取消一条排队中的任务只是把 JOBS 里的 status 标成 cancelled,不会把它从队列摘除,worker 要等真正 Q.get() 到它才跳过丢弃。堆量取消场景下 queued 数字会明显偏高(比如 "排队 253")。改成跟 running 同口径,直接数 JOBS 里 status=='queued' 的 条目。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SBpJTe8WfuYkKwjMaRSDg6
Showing
2 changed files
with
14 additions
and
4 deletions
raylight/scripts/server.py
| @@ -568,7 +568,12 @@ def _comfyui_alive() -> bool: | @@ -568,7 +568,12 @@ def _comfyui_alive() -> bool: | ||
| 568 | 568 | ||
| 569 | @app.get("/health") | 569 | @app.get("/health") |
| 570 | def health(): | 570 | def health(): |
| 571 | + # queued 统计真正 status=='queued' 的任务,不用 Q.qsize()——取消一条排队中的任务只是把 | ||
| 572 | + # JOBS 里那条的 status 标成 cancelled,不会把它从 Q 摘除,worker 要等真正 Q.get() 到它才 | ||
| 573 | + # 会跳过丢弃(见 worker() 里的注释);qsize() 在那之前会把这些已取消的僵尸 entry 也算 | ||
| 574 | + # 进去,堆量取消时数字会明显偏高,跟 running 的统计口径(数 JOBS 状态)保持一致才准确。 | ||
| 571 | running = sum(1 for j in JOBS.values() if j.status == "running") | 575 | running = sum(1 for j in JOBS.values() if j.status == "running") |
| 576 | + queued = sum(1 for j in JOBS.values() if j.status == "queued") | ||
| 572 | comfy_alive = _comfyui_alive() | 577 | comfy_alive = _comfyui_alive() |
| 573 | ready = 1 if (STATE["model"] == "ready" and comfy_alive) else 0 | 578 | ready = 1 if (STATE["model"] == "ready" and comfy_alive) else 0 |
| 574 | model_state = STATE["model"] if comfy_alive else "comfyui_unreachable" | 579 | model_state = STATE["model"] if comfy_alive else "comfyui_unreachable" |
| @@ -578,14 +583,14 @@ def health(): | @@ -578,14 +583,14 @@ def health(): | ||
| 578 | "gpu": "0,1,2,3", | 583 | "gpu": "0,1,2,3", |
| 579 | "partition": "raylight-fsdp", # 不再是路由依据,纯展示——4卡是一个集群,没有单卡分区概念了 | 584 | "partition": "raylight-fsdp", # 不再是路由依据,纯展示——4卡是一个集群,没有单卡分区概念了 |
| 580 | "offload": "fsdp", | 585 | "offload": "fsdp", |
| 581 | - "queued": Q.qsize(), | 586 | + "queued": queued, |
| 582 | "running": running, | 587 | "running": running, |
| 583 | "backend": BACKEND_URL, | 588 | "backend": BACKEND_URL, |
| 584 | } | 589 | } |
| 585 | return { | 590 | return { |
| 586 | "status": "ok" if ready else "unavailable", | 591 | "status": "ok" if ready else "unavailable", |
| 587 | "ready": ready, "total": 1, | 592 | "ready": ready, "total": 1, |
| 588 | - "queued": Q.qsize(), "running": running, | 593 | + "queued": queued, "running": running, |
| 589 | "backends": [backend], | 594 | "backends": [backend], |
| 590 | "gpus": _gpu_status(), | 595 | "gpus": _gpu_status(), |
| 591 | } | 596 | } |
raylight/server.py
| @@ -568,7 +568,12 @@ def _comfyui_alive() -> bool: | @@ -568,7 +568,12 @@ def _comfyui_alive() -> bool: | ||
| 568 | 568 | ||
| 569 | @app.get("/health") | 569 | @app.get("/health") |
| 570 | def health(): | 570 | def health(): |
| 571 | + # queued 统计真正 status=='queued' 的任务,不用 Q.qsize()——取消一条排队中的任务只是把 | ||
| 572 | + # JOBS 里那条的 status 标成 cancelled,不会把它从 Q 摘除,worker 要等真正 Q.get() 到它才 | ||
| 573 | + # 会跳过丢弃(见 worker() 里的注释);qsize() 在那之前会把这些已取消的僵尸 entry 也算 | ||
| 574 | + # 进去,堆量取消时数字会明显偏高,跟 running 的统计口径(数 JOBS 状态)保持一致才准确。 | ||
| 571 | running = sum(1 for j in JOBS.values() if j.status == "running") | 575 | running = sum(1 for j in JOBS.values() if j.status == "running") |
| 576 | + queued = sum(1 for j in JOBS.values() if j.status == "queued") | ||
| 572 | comfy_alive = _comfyui_alive() | 577 | comfy_alive = _comfyui_alive() |
| 573 | ready = 1 if (STATE["model"] == "ready" and comfy_alive) else 0 | 578 | ready = 1 if (STATE["model"] == "ready" and comfy_alive) else 0 |
| 574 | model_state = STATE["model"] if comfy_alive else "comfyui_unreachable" | 579 | model_state = STATE["model"] if comfy_alive else "comfyui_unreachable" |
| @@ -578,14 +583,14 @@ def health(): | @@ -578,14 +583,14 @@ def health(): | ||
| 578 | "gpu": "0,1,2,3", | 583 | "gpu": "0,1,2,3", |
| 579 | "partition": "raylight-fsdp", # 不再是路由依据,纯展示——4卡是一个集群,没有单卡分区概念了 | 584 | "partition": "raylight-fsdp", # 不再是路由依据,纯展示——4卡是一个集群,没有单卡分区概念了 |
| 580 | "offload": "fsdp", | 585 | "offload": "fsdp", |
| 581 | - "queued": Q.qsize(), | 586 | + "queued": queued, |
| 582 | "running": running, | 587 | "running": running, |
| 583 | "backend": BACKEND_URL, | 588 | "backend": BACKEND_URL, |
| 584 | } | 589 | } |
| 585 | return { | 590 | return { |
| 586 | "status": "ok" if ready else "unavailable", | 591 | "status": "ok" if ready else "unavailable", |
| 587 | "ready": ready, "total": 1, | 592 | "ready": ready, "total": 1, |
| 588 | - "queued": Q.qsize(), "running": running, | 593 | + "queued": queued, "running": running, |
| 589 | "backends": [backend], | 594 | "backends": [backend], |
| 590 | "gpus": _gpu_status(), | 595 | "gpus": _gpu_status(), |
| 591 | } | 596 | } |