Commit 25182fc
[serve] Cache per-tick replica id walks behind a container membership fingerprint
The per-tick id walks (alive-actor-ids, active-node-ids, running-ids, the autoscaler
id-set rebuild) recompute identical results on every steady-state tick. Memoize each on
a ReplicaStateContainer membership fingerprint, and disarm while STARTING or RECOVERING
replicas exist, since their actor_id/actor_node_id materialize in place without touching
the container.
The fingerprint is the summed per-replica hash of the container's {replica id -> state}
content rather than a mutation counter, because the health and migration passes pop a
whole bucket and re-add every replica to the state it came from. A counter reads that
churn as a membership change, and one node draining anywhere in the cluster is enough to
trigger it: at 4 replicas it bumps 5 times per otherwise-idle tick, which invalidates all
three memos and re-runs the O(N) rank-consistency pass on every tick. Gang deployments
health-check through that same pop-and-re-add path on every tick, so for them a counter
never holds at all. Summing per-replica terms makes pop-and-re-add cancel exactly, while
a real arrival, departure or state transition still changes it.
The same key replaces the id-set key of the rank-consistency gate, which keeps that gate
O(1) per tick without losing the content-based semantics that let it hold under churn. It
changes strictly more often than the id set it replaces -- it includes state -- so the
gate can never skip a pass the id set would have run. It is paired with the exact replica
count, because unlike an id-set comparison it is a hash: memberships of the same size
collide with probability ~2^-64, and while a stale memo self-corrects on the next real
change, a skipped rank pass would not.
Caching disarms while STARTING, UPDATING or RECOVERING replicas exist: the startup check
calls check_ready() for all three, and that rewrites actor_id/node_id in place without a
membership change.
One delta from the gate as it stands in the base PR: the empty-membership early return
now caches before returning.
Manager-level getters return frozensets so the memo cannot be mutated by callers (with
set() at the one mutating caller), and AutoscalingContext.running_replicas is copied to a
list at the public boundary. The autoscaler's identity skip is safe because
_running_replicas and _cached_running_replica_strs are only ever written together and both
start empty, so the pair cannot desync -- note that re-registering a deployment reuses the
existing DeploymentAutoscalingState rather than presenting a new list object.
Signed-off-by: john.taylor <john.taylor@anyscale.com>
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 05770ef commit 25182fc
4 files changed
Lines changed: 473 additions & 41 deletions
File tree
- python/ray/serve
- _private
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
7 | 18 | | |
8 | 19 | | |
9 | 20 | | |
| |||
93 | 104 | | |
94 | 105 | | |
95 | 106 | | |
96 | | - | |
| 107 | + | |
97 | 108 | | |
98 | 109 | | |
99 | 110 | | |
| |||
208 | 219 | | |
209 | 220 | | |
210 | 221 | | |
211 | | - | |
| 222 | + | |
212 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
213 | 228 | | |
214 | 229 | | |
215 | 230 | | |
| |||
395 | 410 | | |
396 | 411 | | |
397 | 412 | | |
398 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
399 | 416 | | |
400 | 417 | | |
401 | 418 | | |
| |||
1013 | 1030 | | |
1014 | 1031 | | |
1015 | 1032 | | |
1016 | | - | |
| 1033 | + | |
1017 | 1034 | | |
1018 | 1035 | | |
1019 | 1036 | | |
| |||
1183 | 1200 | | |
1184 | 1201 | | |
1185 | 1202 | | |
1186 | | - | |
| 1203 | + | |
1187 | 1204 | | |
1188 | 1205 | | |
1189 | 1206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
537 | 539 | | |
538 | 540 | | |
539 | 541 | | |
| |||
0 commit comments