Repository navigation
Remove node observability information from hot path of core components - #56474
Conversation
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
dayshah
left a comment
There was a problem hiding this comment.
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
That is absolutely something I gotta do. |
|
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 |
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. |
|
Awesome work! For an internal, high performance protocol, we don't need flexibility so I agree with you conclusion.
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"
Agreed. This is a very solid investigation though. Any theories as to why fieldmask is so slow? |
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
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 :) |
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
Signed-off-by: zac <[email protected]>
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.
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:
Core Worker:
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
Experiment 1: FieldMask-Based Filtering
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:
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
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.Note
Introduce GcsNodeAddressAndLiveness with new RPC and pubsub channel, and migrate core/worker/raylet paths from GcsNodeInfo to reduce overhead.
GcsNodeAddressAndLivenessmessage and new RPCGetAllNodeAddressAndLiveness.GCS_NODE_ADDRESS_AND_LIVENESS_CHANNELand publish alongsideGcsNodeInfo.HandleGetAllNodeAddressAndLivenessand conversion utility inGcsNodeManager.grpc_services/gcs_serverand include new channel in publisher/subscriber.NodeInfoAccessor: addAsyncGetAllNodeAddressAndLiveness,GetNodeAddressAndLiveness, new subscription, cache, resubscribe, and no-cache fetch; adjustIsNodeDead.GcsNodeInfousages withGcsNodeAddressAndLivenessfor node lookups/subscriptions incore_worker,core_worker_process,task_manager,normal_task_submitter,object_manager,raylet(including schedulers andNodeManager).ClusterLeaseManagerinternals typedef to use the new type.git_repositoryforgoogle/benchmark.Written by Cursor Bugbot for commit 99c7156. This will update automatically on new commits. Configure here.