[Serve] Fix sort bug and optimize ClusterNodeInfoCache.update()#60843
Merged
Conversation
Signed-off-by: abrar <abrar@anyscale.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces several valuable improvements to ClusterNodeInfoCache.update(). It correctly fixes a sorting bug, and significantly optimizes performance by reducing redundant GCS RPCs and avoiding unconditional cache rebuilds. The implementation is clear and robust, with good error handling for GCS communication failures. I have one minor suggestion to make a part of the new logic more concise and Pythonic.
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
harshit-anyscale
approved these changes
Feb 9, 2026
ans9868
pushed a commit
to ans9868/ray
that referenced
this pull request
Feb 18, 2026
…project#60843) `ClusterNodeInfoCache.update()` had three issues: 1. **Sort bug (correctness):** `sorted(alive_nodes)` returns a new sorted list that was immediately discarded. The cached `alive_nodes` were stored in arbitrary dict-iteration order, violating the documented invariant of deterministic NodeID ordering. Fixed by using `alive_nodes.sort()`. 2. **Redundant GCS RPC:** `ray._private.state.available_resources_per_node()` goes through the legacy `GlobalStateAccessor` path, which opens a second connection to GCS and performs a full protobuf serialize/deserialize round-trip per node — every tick. Replaced with `self._gcs_client.get_all_resource_usage()` which reuses the existing `GcsClient` and extracts `resources_available` from the `ResourcesData` batch. 3. **Unconditional cache rebuild:** Node labels and `resources_total` are static per-node properties that don't change while a node stays alive, yet they were rebuilt from scratch every tick. Added change detection via a `frozenset` of alive node IDs — labels and total resources are only rebuilt when cluster membership actually changes. Related to ray-project#60680 --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: Adel Nour <ans9868@nyu.edu>
Aydin-ab
pushed a commit
to kunling-anyscale/ray
that referenced
this pull request
Feb 20, 2026
…project#60843) `ClusterNodeInfoCache.update()` had three issues: 1. **Sort bug (correctness):** `sorted(alive_nodes)` returns a new sorted list that was immediately discarded. The cached `alive_nodes` were stored in arbitrary dict-iteration order, violating the documented invariant of deterministic NodeID ordering. Fixed by using `alive_nodes.sort()`. 2. **Redundant GCS RPC:** `ray._private.state.available_resources_per_node()` goes through the legacy `GlobalStateAccessor` path, which opens a second connection to GCS and performs a full protobuf serialize/deserialize round-trip per node — every tick. Replaced with `self._gcs_client.get_all_resource_usage()` which reuses the existing `GcsClient` and extracts `resources_available` from the `ResourcesData` batch. 3. **Unconditional cache rebuild:** Node labels and `resources_total` are static per-node properties that don't change while a node stays alive, yet they were rebuilt from scratch every tick. Added change detection via a `frozenset` of alive node IDs — labels and total resources are only rebuilt when cluster membership actually changes. Related to ray-project#60680 --------- Signed-off-by: abrar <abrar@anyscale.com>
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.
ClusterNodeInfoCache.update()had three issues:Sort bug (correctness):
sorted(alive_nodes)returns a new sorted list that was immediately discarded. The cachedalive_nodeswere stored in arbitrary dict-iteration order, violating the documented invariant of deterministic NodeID ordering. Fixed by usingalive_nodes.sort().Redundant GCS RPC:
ray._private.state.available_resources_per_node()goes through the legacyGlobalStateAccessorpath, which opens a second connection to GCS and performs a full protobuf serialize/deserialize round-trip per node — every tick. Replaced withself._gcs_client.get_all_resource_usage()which reuses the existingGcsClientand extractsresources_availablefrom theResourcesDatabatch.Unconditional cache rebuild: Node labels and
resources_totalare static per-node properties that don't change while a node stays alive, yet they were rebuilt from scratch every tick. Added change detection via afrozensetof alive node IDs — labels and total resources are only rebuilt when cluster membership actually changes.Related to #60680