Skip to content

Remove node observability information from hot path of core components - #56474

Merged
dayshah merged 50 commits into
ray-project:masterfrom
ZacAttack:field-mask-prototype
Oct 15, 2025
Merged

dayshah merged 50 commits into
ray-project:masterfrom
ZacAttack:field-mask-prototype

Conversation

@ZacAttack

@ZacAttack ZacAttack commented Sep 12, 2025 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Problem

Currently, there are many processes within Ray that call HandleGetAllNodeInfo. HandleGetAllNodeInfo is the function within GCS which returns the list of all nodes (dead or alive) which match some selector criteria. The node list is composed with instances of the proto GcsNodeInfo. This proto however is quite large and contains a lot of repeated information that isn’t used by all, or even very many of the processes within Ray. This leads to unnecessary overhead for the sender and receiver of this payload in most cases.

Solution

We can add a new api which supplies a constrained amount of information for those processes which only need a few fields. We'll call this new api GetAllNodeAddressLight for now (but... will probably give it a new name prior to merging as this sounds too much like a low calorie beverage).

There are a few ways we can implement this. They include:

Read Time Computation

Generally speaking we can compute the result based on the complete metadata GCS keeps internally at read time. This adds read time compute complexity, but has the benefit of not eating up extra memory and introducing more complexity in metadata book keeping.

Write Time Computation (cache)

The opposite (sorta?) approach from the above is to at write time update a separate cache of precomputed projection of fields. This has the benefit of keeping the lookup faster by removing compute out of the lookup, and instead spin the cpu’s once at time of node insertion/update (as opposed to spending it for every lookup).

Field Mask vs. Copy:

Protobuff supports a feature called “Field Masking” and it’s meant to be an in-built way to screen out and select certain fields within a protobuff object. It sounded useful, so I figured we’d give it a shot. The alternative is to instead create a new object and programmatically (and very explicitly) select the specific fields we want to carry over to the new object.

Why not make field selection part of the api?

I am deliberately steering clear of this for a few reasons. One option was to include the field mask as a selector option to the current api. I dislike this for a few reasons. Let’s list them!

  • Leaking GRPCism’s to the interface (when using field mask): A common usage of field mask is to pass it as part of the request object and then apply it to the result. Gcs_client api’s are internal to ray, but they’re external across its components. We should be as defensive as possible to external dependencies in these interfaces as failure to do so makes swapping things in and out all that much more difficult.

  • Adding flexibility to a high performance codepath is a potential invitation to rot: We didn’t get to a bloated definition here overnight. It got here as one field after another was nickel and dimed over the years. I would prefer to intentionally make it difficult to add things here and invite as much scrutiny as possible if only to disincentivize sneaking in extra cost.

  • Having an explicit type with fields protects against cache pollution snafu’s: The GCS client today uses a list of accessors which populate a set of in memory cache’s that contain objects of explicit proto types. Using an on the fly calculated projection or select could make reasoning about this cache more difficult. Using explicit types seems more clear. Conceivably we could store the projection along with cached entries in the client but this seems like a complexity that isn’t worth paying in my opinion.

Which fields do we keep in the Light version of the api?

This is an area admittedly I’m still working on as I haven’t done the client integration just yet. We should pick this carefully. We don’t want to screen out so much that the new api is only narrowly useful BUT we don’t want to give so much leeway that we still pollute other paths. My initial suggestion is to have these fields in a newer “light” api.

message GcsNodeInfoLight {
 // The ID of node.
 bytes node_id = 1;


 // The IP address of the node manager.
 string node_manager_address = 2;


 // The port at which the node manager is listening for TCP
 // connections from other node managers.
 int32 node_manager_port = 3;


 // The port at which the object manager is listening for TCP
 // connections from other object managers.
 int32 object_manager_port = 4;


 // Current state of this node.
 GcsNodeInfo.GcsNodeState state = 5;


 // The death info of this node.
 NodeDeathInfo death_info = 6;
}

I have selected these fields based on the notion that Raylet and coreworker need them, and they are the processes with the highest cardinality in the cluster. My cursory glance through tells me that the mapping for what uses what fields are as follows:

Raylet:

  • node_id
  • node_manager_address
  • node_manager_port
  • State
  • object_manager_port

Core Worker:

  • same information as needed by raylet
  • death_info ← used in order to discount pre-emption from task retry count, might be removable with a little refactoring

Benchmarking and Prototyping

I deliberately have picked on labels as my source of bloat and chaos. Truthfully there are maybe other sources of interesting variance to pick on, but this was tempting as it’s a map of strings.

Experiment Setup

  • Test Configurations: 10-5000 nodes with 0-50 labels per node (100 characters each)
  • Measurement: Average microseconds per operation and total response bytes
  • Iterations: 100 iterations per test case (just to average out variance as best as possible)
  • What was tested: Micro benchmark on GcsNodeManager unit test style (no network transmission, so take some of these numbers with a grain of salt when considering production implications)

Experiment 1: FieldMask-Based Filtering

  • HandleGetAllNodeInfo: Returns complete GcsNodeInfo objects
  • HandleGetAllNodeInfoLight: Uses google::protobuf::util::FieldMaskUtil::MergeMessageTo() to filter out expensive fields at query time
  • HandleGetAllNodeInfoLightCached: Pre-computes filtered GcsNodeInfo objects using FieldMask and caches them

Results (100 nodes, 50 labels each):
HandleGetAllNodeInfo: 1630 us/op, 703,712 bytes
HandleGetAllNodeInfoLight: 425 us/op, 15,780 bytes (74% faster, 98% smaller)
HandleGetAllNodeInfoLightCached: 98 us/op, 15,780 bytes (94% faster, 98% smaller)

So we got decent speed up, and perhaps unsurprisingly the read off the cache is the fastest. However, what’s concerning is the difference between the cached vs. non-cached benchmarks. It’s a pretty big difference (more then 4x slower!), thus implying that applying the field mask is pretty expensive.

Experiment 2: Just copy into a new object without field masking

So let’s nix that thing.

Results (100 nodes, 50 labels each):

HandleGetAllNodeInfo: 1531 us/op, 703,712 bytes
HandleGetAllNodeInfoLight: 93 us/op, 15,780 bytes (94% faster, 98% smaller)
HandleGetAllNodeInfoLightCached: 93 us/op, 15,780 bytes (94% faster, 98% smaller)

Ok. Now we’re talking. The cached version and non cached version are now pretty much the same speed. Implying that we can just forget about using field mask AND forget about even bothering with the overhead of the cache since the overhead is pretty minimal. Running more trials for all cases we get the following results:

Approach 10 nodes, 50 labels 100 nodes, 50 labels 1000 nodes, 20 labels
FieldMask Experiment
Full API 130 us, 68KB 1630 us, 687KB 7127 us, 2.8MB
Light (FieldMask) 71 us, 1.6KB 425 us, 15KB 5039 us, 159KB
LightCached 9 us, 1.6KB 98 us, 15KB 1458 us, 159KB
Type-Safe Experiment
Full API 126 us, 68KB 1531 us, 687KB 8786 us, 2.9MB
Light (Direct) 8 us, 1.6KB 93 us, 15KB 1175 us, 159KB
LightCached 8 us, 1.6KB 93 us, 15KB 1237 us, 159KB

So based on this, it seems like going for the direct type with no cache gives us the best tradeoffs.

Other Interesting numbers

I backed out the changes which used the field mask and mid clean up realized that we might have seen something interesting with cluster sizes as large as 10-30k. So running those numbers with the preferred approach (not cached, no field mask) I get the following results:

=== Benchmark: 10000 nodes, 5 labels per node ===
HandleGetAllNodeInfo: 43746 us/op, total bytes: 9827357
HandleGetAllNodeInfoLight: 4468 us/op, total bytes: 567839

=== Benchmark: 30000 nodes, 5 labels per node ===
HandleGetAllNodeInfo: 151633 us/op, total bytes: 29632107
HandleGetAllNodeInfoLight: 21036 us/op, total bytes: 1735214

Considering in a ray cluster each node will need to make something like N*(W+1) number of calls where N is the number of nodes and W is the number of workers per node, if all requests were served on a single thread, it'll take somewhere north of an hour to process all these requests with the old version of the api, where as the lighter version is closer to 10 minutes. That's a pretty decent time reduction when you consider spinning up a cluster of that size!

What's next

We'll look at this API internally and see if there's anything else worth calling out. In particular we should pay careful attention to the field selection. For now I'm thinking it might be prudent to split this work between (at least) two PR's, one for the server and one for the client. I'm also disinclined to commit the benchmark code here to main branch, but will probably need to add proper unit tests for the new node manager API.

Related issue number

Checks


Note

Introduce GcsNodeAddressAndLiveness with new RPC and pubsub channel, and migrate core/worker/raylet paths from GcsNodeInfo to reduce overhead.

  • GCS / Protobuf:
    • Add GcsNodeAddressAndLiveness message and new RPC GetAllNodeAddressAndLiveness.
    • Add pubsub channel GCS_NODE_ADDRESS_AND_LIVENESS_CHANNEL and publish alongside GcsNodeInfo.
    • Implement HandleGetAllNodeAddressAndLiveness and conversion utility in GcsNodeManager.
  • GCS Server/Client:
    • Wire new RPC in grpc_services/gcs_server and include new channel in publisher/subscriber.
    • NodeInfoAccessor: add AsyncGetAllNodeAddressAndLiveness, GetNodeAddressAndLiveness, new subscription, cache, resubscribe, and no-cache fetch; adjust IsNodeDead.
  • Core/Raylet:
    • Replace GcsNodeInfo usages with GcsNodeAddressAndLiveness for node lookups/subscriptions in core_worker, core_worker_process, task_manager, normal_task_submitter, object_manager, raylet (including schedulers and NodeManager).
    • Update ClusterLeaseManager internals typedef to use the new type.
  • Tests/Mocks:
    • Update mocks and tests to use new methods/types and expectations across core worker, raylet, GCS, and object manager tests.
  • Build:
    • Add Bazel git_repository for google/benchmark.

Written by Cursor Bugbot for commit 99c7156. This will update automatically on new commits. Configure here.

Comment thread src/ray/gcs/gcs_node_manager.cc Resolved
Comment thread src/ray/protobuf/gcs_service.proto Resolved
@ZacAttack
ZacAttack marked this pull request as ready for review September 16, 2025 23:25
@ZacAttack
ZacAttack requested a review from a team as a code owner September 16, 2025 23:25

@dayshah dayshah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am anti-field masking, having a light version of the api sounds a lot cleaner / easier to read.

Also should this also come with a light node info pubsub since this proto obj is tied to the pubsub and at least half of the GetAllNodeInfo requesters are just the initial subscribe requesters

@ZacAttack

Copy link
Copy Markdown
Contributor Author

Also should this also come with a light node info pubsub since this proto obj is tied to the pubsub and at least half of the GetAllNodeInfo requesters are just the initial subscribe requesters

That is absolutely something I gotta do.

@can-anyscale

Copy link
Copy Markdown
Contributor

Very nice, I’d also prefer introducing another proto instead of masking, since it seems less complex. If we do have a need for masking, perhaps enumerate what are needed and do it via some explicit list of APIs (e.g., HandleGetAllDeathNodeInfo, HandleGetAllNodeIds, etc.) rather than a generic masking APIs (as you pointed out seem like a complex API to maintain vs. our current need). As a minor nit, maybe renaming the existing GcsNodeInfo to GcsNodeInfoHeavy or GcsNodeInfoFull, so that the lighter version becomes the default.

@ray-gardener ray-gardener Bot added the core Issues that should be addressed in Ray Core label Sep 17, 2025
@edoakes

edoakes commented Sep 17, 2025

Copy link
Copy Markdown
Collaborator

I'm also disinclined to commit the benchmark code here to main branch

Why's this @ZacAttack? I think we should check in some kind of benchmark for this as a first cut at C++ performance testing

@ZacAttack

Copy link
Copy Markdown
Contributor Author

I'm also disinclined to commit the benchmark code here to main branch

Why's this @ZacAttack? I think we should check in some kind of benchmark for this as a first cut at C++ performance testing

So... The way I thought about this is is that a benchmark or a test is useful in so far as it helps you drive a decision. For tests, the decision they help you drive is weather or not a commit is ok to take or not. For this work stream my thinking is that the benchmark was useful for making an implementation decision empirically as well as justifying the work by putting numbers behind the gains. After this decision has been made/work is done, is this benchmark still useful? I think it could be made to be useful with a little work (making sure this new api doesn't slow down? Generate estimates on time to spin up large clusters??) but if we're not going to do that work then I think it just because a source of noise.

I don't hold this opinion though strongly, if you think there's good enough justification to keep it I'm all ears.

@israbbani

israbbani commented Sep 17, 2025 •

Copy link
Copy Markdown
Contributor

Awesome work! For an internal, high performance protocol, we don't need flexibility so I agree with you conclusion.

GetAllNodeInfoLight

I'd prefer calling it exactly what it is if it's a stable API. GetAllNodeAddressesAndPorts or whatever. Tells the story and makes it harder to justify adding more stuff to it. Kind of in the same spirit as: "Adding flexibility to a high performance codepath is a potential invitation to rot"

I'm also disinclined to commit the benchmark code here to main branch.

Agreed. This is a very solid investigation though.

Any theories as to why fieldmask is so slow?

@edoakes

edoakes commented Sep 18, 2025

Copy link
Copy Markdown
Collaborator

After this decision has been made/work is done, is this benchmark still useful? I think it could be made to be useful with a little work (making sure this new api doesn't slow down? Generate estimates on time to spin up large clusters??) but if we're not going to do that work then I think it just because a source of noise.

My thinking was to keep it as a regression test to avoid future bloat that slows down the path substantially. But that can probably also be enforced with our eyes :)

@ZacAttack ZacAttack added the go add ONLY when ready to merge, run all tests label Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants