fix(pd): balance prefill nodes on decayed recent load to avoid cache-affinity starvation - #1433
Open
sufubao wants to merge 1 commit into
Open
fix(pd): balance prefill nodes on decayed recent load to avoid cache-affinity starvation#1433sufubao wants to merge 1 commit into
sufubao wants to merge 1 commit into
Conversation
…affinity starvation The cache-aware prefill selector's 1.2x balance guard compared cumulative-since-start dispatched chars, so a prefill node that was busy early (now idle) kept a high cumulative value and the guard never fired while cache affinity routed all new traffic to the other node, starving the idle node. Repro: 40 identical prompts -> 40/0 split, guard fired 0 times. Switch the guard (and the min-dispatched fallback) to a half-life-decayed recent dispatched signal, so an idle node's load decays to 0 and the guard redirects traffic back to it. Default half-life 60s, configurable via CacheAwareConfig.balance_half_life_secs. After the fix, the same workload splits 22/18 with the guard firing 11 times. Added unit tests for the decay math, the starvation redirect, and that balanced load still keeps cache affinity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
LoadBalancedCacheAwareSelector的 1.2× 均衡门闩用的是PD_Client_Obj.dispatched_prompt_chars,即自启动起单调累计的派发字符数。在多 prefill 节点 + cache 亲和场景下存在单点饥饿:max/min < 1.2永远成立,从不触发,空闲节点被饿死。复现
m39、Qwen3.5-4B、2P1D 拓扑,40 个相同 prompt 串行打:
GSM8K 200q(高 cache 命中)也只能贴着 1.2× 边缘跑(1.197×),门闩 18/200 次,靠的是另一侧累计值恰好较低,并非设计正确。
修复
均衡门闩和
_select_worker_min_dispatched兜底都改用按半衰期衰减的「近期」派发量recent_dispatched_chars:time.monotonic()做 lazy 衰减,每次选点前衰减一次,无后台线程;CacheAwareConfig.balance_half_life_secs调;dispatched_prompt_chars保留(仅作统计),门闩已完全切到 recent。涉及文件:
pd_io_struct.py:PD_Client_Obj增加recent_dispatched_chars/last_decay_ts。cache_aware.py:新增_decay_recent,门闩与兜底改用 recent。pd_selector.py:派发时累加 recent。manager.py:节点注册重置时一并清零 recent。验证
同样的 starvation 场景,修复后:
新增单测
unit_tests/server/test_cache_aware_balance.py(无需 GPU):3/3 通过,black + flake8 通过。
说明
半衰期目前只在
CacheAwareConfig可调,未接 CLI flag;如需要可后续加--pd_balance_half_life_secs。