Repository navigation
[core] [DO NOT MERGE] (Original FreeObjects) Integrated new NodeManager FreeLocalObjects RPC - #63117
aaronscalene wants to merge 16 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new FreeLocalObjects RPC mechanism that allows object owners to explicitly broadcast deletion requests to all raylets holding copies, moving away from the previous pub-sub based eviction. The changes include a new internal documentation file for the placement group lifecycle, updates to the ReferenceCounter to trigger broadcasts when objects are freed, and the implementation of the RPC handler within the NodeManager. Feedback focuses on improving the robustness and efficiency of the new path, specifically by adding a retry limit to the exponential backoff logic, batching broadcast RPCs to reduce overhead, and addressing potential object leaks resulting from the partial removal of the legacy batching logic in LocalObjectManager.
9a872b8 to
0408656
Compare
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
0408656 to
4f1ef12
Compare
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
There was a problem hiding this comment.
bit of a nit for the PR description, but it sounds like a stream of consciousness right now.
Ideally someone who has no idea what FreeObjects is should be able to:
1.) Understand the problem from reading your PR description
2.) Understand the alternate solutions you proposed and why you selected this one
There's a couple places where it should go into a bit more detail. For example,
The reference goes out of scope and marked by python.
The reference count is not just the python reference count, it also includes the task submission + the number of borrowers. Collectively you can just refer to this as the reference count, but it's not just modified by python's gc but by Ray as well, key difference.
You should also mention why we spray FreeObjects to every single node in the cluster on the raylet. In that the raylet doesn't always subscribe for object locations, hence at the time it receives the pubsub from the owner that the object has gone out of scope it has no idea what the object locations are.
|
|
||
| void CoreWorker::SpreadFreeLocalObjects(const ObjectID &object_id, | ||
| const std::vector<NodeID> &locations) { | ||
| io_service_.post( |
There was a problem hiding this comment.
why do we need to explicitly post onto the io_service here, is this potentially called on the task_execution_io_service?
There was a problem hiding this comment.
We need io_service here because it is called under the ReferenceCounter mutex, which can lead to deadlock in the future. I added a comment to better explain this.
There was a problem hiding this comment.
Sorry I don't follow, isn't this just making a couple RPCs? What would trigger the deadlock/what other lock is getting acquired?
There was a problem hiding this comment.
Sorry, you are 100% right to pushback, I was under an old impression of my implementation. Based on the previous benchmark, SpreadFreeLocalObjects runs on an average 0.08 ms, so it seems alright to just leave this within the thread.
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
Signed-off-by: aaron.li <[email protected]>
done |
| bool lineage_pinning_enabled = false, | ||
| std::function<bool(const NodeID &node_id)> is_node_dead = nullptr, | ||
| std::function<void(const ObjectID &object_id, const std::vector<NodeID> &locations)> | ||
| spread_free_local_objects = nullptr) |
There was a problem hiding this comment.
Why should is_node_dead or spread_free_local_objects ever be nullptr? Default parameters should only exist if they make sense, I feel like here it doesn't make sense.
There was a problem hiding this comment.
I agree with this, changed accordingly.
| publisher_.get(), | ||
| subscriber_.get(), | ||
| /*is_node_dead=*/[](const NodeID &) { return false; }, | ||
| fake_owned_object_count_gauge_, |
There was a problem hiding this comment.
can you revert the parameter ordering change since we decided to keep the is_node_dead callback?
| } | ||
| if (!locations_set.empty()) { | ||
| std::vector<NodeID> locations(locations_set.begin(), locations_set.end()); | ||
| spread_free_local_objects_(it->first, locations); |
There was a problem hiding this comment.
I pass locations by reference, so this should not help? I think std::move would incur additional overhead stack cost as opposed to just passing by reference, albeit negligible.
| // Decrement counter for old state | ||
| UpdateOwnedObjectCounters(object_id, it->second, /*decrement=*/true); | ||
| if (!is_node_dead_(node_id)) { | ||
| if (!is_node_dead_ || !is_node_dead_(node_id)) { |
There was a problem hiding this comment.
nit: we really should just remove the default parameter for !is_node_dead_ just makes the code confusing
| // up the local_objects_ entry once the spilled copy has been | ||
| // freed. | ||
| spilled_object_pending_delete_.push(object_id); | ||
| if (it != local_objects_.end() && !it->second.is_freed_) { |
There was a problem hiding this comment.
why'd you just remove the early return and nest everything? I think it hurts readability and there's not much point to it?
There was a problem hiding this comment.
Originally, only primary copies need to fall through this path to be freed, while secondary objects are freed through HandleFreeObjects. Now, we want primary / spilled objects to have their metadata cleared, while secondary objects should still be queued up to be deleted. Thus, if it is a primary copy, we want to free the primary copy objects. Otherwise, secondary copies are queued up to be deleted.
|
Looking good! Can you collapse this PR with 2/n as well and start running it through CI? |
Signed-off-by: aaron.li <[email protected]>
|
|
||
| void CoreWorker::SpreadFreeLocalObjects(const ObjectID &object_id, | ||
| const std::vector<NodeID> &locations) { | ||
| io_service_.post( |
There was a problem hiding this comment.
Sorry, you are 100% right to pushback, I was under an old impression of my implementation. Based on the previous benchmark, SpreadFreeLocalObjects runs on an average 0.08 ms, so it seems alright to just leave this within the thread.
| // up the local_objects_ entry once the spilled copy has been | ||
| // freed. | ||
| spilled_object_pending_delete_.push(object_id); | ||
| if (it != local_objects_.end() && !it->second.is_freed_) { |
There was a problem hiding this comment.
Originally, only primary copies need to fall through this path to be freed, while secondary objects are freed through HandleFreeObjects. Now, we want primary / spilled objects to have their metadata cleared, while secondary objects should still be queued up to be deleted. Thus, if it is a primary copy, we want to free the primary copy objects. Otherwise, secondary copies are queued up to be deleted.
| publisher_.get(), | ||
| subscriber_.get(), | ||
| /*is_node_dead=*/[](const NodeID &) { return false; }, | ||
| fake_owned_object_count_gauge_, |
| } | ||
| if (!locations_set.empty()) { | ||
| std::vector<NodeID> locations(locations_set.begin(), locations_set.end()); | ||
| spread_free_local_objects_(it->first, locations); |
There was a problem hiding this comment.
I pass locations by reference, so this should not help? I think std::move would incur additional overhead stack cost as opposed to just passing by reference, albeit negligible.
| bool lineage_pinning_enabled = false, | ||
| std::function<bool(const NodeID &node_id)> is_node_dead = nullptr, | ||
| std::function<void(const ObjectID &object_id, const std::vector<NodeID> &locations)> | ||
| spread_free_local_objects = nullptr) |
There was a problem hiding this comment.
I agree with this, changed accordingly.
Signed-off-by: aaron.li <[email protected]>
aaronscalene
left a comment
There was a problem hiding this comment.
reviewed with PR
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit e308c88. Configure here.
| if (!locations_set.empty()) { | ||
| std::vector<NodeID> locations(locations_set.begin(), locations_set.end()); | ||
| spread_free_local_objects_(it->first, locations); | ||
| } |
There was a problem hiding this comment.
External I/O performed while holding ReferenceCounter mutex
Medium Severity
spread_free_local_objects_ is invoked inside OnObjectOutOfScopeOrFreed, which requires mutex_ to be held exclusively. The callback resolves into CoreWorker::SpreadFreeLocalObjects, which calls GetNodeAddressAndLiveness (acquires node_cache_address_and_liveness_mutex_), GetOrConnectByAddress (may create gRPC channels), and sends RPCs — all while blocking every other thread that needs the ReferenceCounter mutex. This creates lock-ordering risks and can stall reference-counting operations for the duration of multiple network lookups.
Reviewed by Cursor Bugbot for commit e308c88. Configure here.
There was a problem hiding this comment.
Should be fine, as mentioned in comment above that the time for SpreadFreeLocalObjects seemed minimal overall in benchmarking.
… free mechanism (#63218) ## Motivation Within this multi-step PR process, our goal is to change our current **FreeObjects** implementation to an owner driven process. Current design of FreeObjects involves spraying the entire cluster with FreeObjects RPCs. This introduces many caveats: bloating observability with FreeObjects RPC counts, sending excessive RPCs, and worse mental model from owner-driven reference counting. This is a continuation from #63117. Due to the race condition detailed in the testing section of the PR, we decided to merge both changes for a complete PR. Our current design for **FreeObjects** involves the following steps: 1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference. 2. The owner finds out, and sends a pubsub message (initialized when pinning the primary copy) to the primary copy raylet. 3. The primary copy raylet frees its primary copy, and then broadcasts free secondary copies to all nodes within the cluster. (This is batched and sent periodically). The reason the primary copy raylet needs to broadcast secondary copies is because it doesn't store object locations for its primary copy, this is only stored on the owner. Thus, in order to ensure all secondary copies are freed, there is a need to broadcast to all nodes. ## Design As noted above, the owner stores the locations of all copies of the objects, where `pinned_at_node_id_` represents the primary copy location and the `locations` vector demonstrates all secondary object locations. We now move towards a new design **FreeObjects**. We will get rid of the pubsub between owner -> primary copy raylet. Instead: 1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference. 2. The owner sends RPCs to primary and secondary copy holders to free their objects. (Since it has all of its locations) However, this doesn't easily solve our issue since the pubsub also has an `owner_dead_callback`, which fires when the owner has died. This will help clean up the primary object and ensure there are no memory leaks in this case. To continue supporting this functionality, if the owner dies, this information is propagated by the GCS, and thus each raylet just listens to the GCS events and updates their states accordingly. Originally, the design was that: - the pubsub connection fails / ends for some unexpected reason - the owner is thought to be dead, so the primary copy raylet then frees its primary copy and queues up **FreeObjects** to broadcast to all secondary copies The new design: - The GCS already publishes WorkerFailure and NodeRemoved announcements to all raylets. This is so that raylets know to release worker leases of dead nodes / workers - With this new design, the raylets will listen and additionally clear any objects that had their owner on the failed worker / node - Something to consider is how exactly GCS gets these notifications, and if there would be any slowness in these notifications. 1.) When the worker process dies (but the node remains alive), the raylet picks up the worker death relatively quickly via the broken IPC connection and sends the worker death up to the GCS, and GCS broadcasts it. 2.) On node death, similar story. However, in old implementation, the long poll connection would be sitting the retryable grpc client queue waiting for either the connection to come back up or the GCS to get a worker death notification. Hence all in all, there really shouldn't be a significant change in behavior. ## Description This PR covers the first and second part of the **FreeObjects** change. The first part is strictly adding functionality for the owner to be in charge of freeing objects. We make the first step away from this design such that the owner calls a new **FreeLocalObjects** RPC to all primary and secondary copy locations when **OnObjectsOutOfScopeOrFreed**. The second part amends the functionality of the current owner dead pubsub callback to be moved from an eager pubsub death callback to a more passive listener callback. ## Considerations ### NodeManager RPC vs. ObjectManager RPC For this PR, I considered either 1) Adding a new RPC to **NodeManager** or 2) Adding new route that calls into existing **ObjectManager** FreeObjects. Ultimately, I decided to go with 1). A design consideration here is that workers currently only call into raylets' **NodeManager**, so part of this is to keep with existing implementation. Another reason is that our new **HandleFreeLocalObjects** would be responsible for 2 things: 1) if primary copy, delete metadata from **LocalObjectManager** (manages spilled and primary copies) and 2) if any copy, queue up within **FreeObjects**. Thus, **NodeManager** currently has functionality that calls into **LocalObjectManager**. Furthermore, I find that directly interfacing with **ObjectManager** is not as intuitive, and creating a new path just for **ObjectManager** does not seem ideal. ### Moving Around ReferenceCounter Variables For this PR, I decided to follow similar formats in the codebase, and have all the lambdas within the constructor shifted to the end. In this case, they can be considered optional arguments and can be defaulted to null if not specified. This leads to easier testing implementations. A tricky part is to ensure these functions generate no-op if they are not specified. ### Only Owner Frees An important consideration is that now that we are sending from the worker side, only if the object is freed is owned by the current worker should the worker send RPC requests to the object locations. Otherwise, the worker should just keep quiet. ### Dead Code Deleted in Future For this PR, I kept **FreeObjects**'s `local_only=false` case still alive, even though this case is essentially never called again. In the future, I will delete this dead code. ### Testing Changes and ReferenceCounter Changes For this PR, there were many testing changes that are needed because of this new path that is different from the first one. For now, many of these tests are just hardcoded to match correct behavior, but in the future some unnecessary tests might be deleted or shuffled around to match the new implementation. ### Pass Over All Objects This new design introduces a pass over all objects within the current node every announcement. However, failed nodes and worker announcements should not be too common and if the object is not owned by the failed worker / node it would be a no-op; thus this should not lead to any latency issues. ### Owner is Less Eager This new design will be a less eager free, especially for the primary copy of the node. This is definitely an important part to consider, however since it is similar a pubsub for node information, the latency should not be that big of a deal. Furthermore, the pubsub interface already keeps track of network failures etc. to some extent, and if there are further failures / GCS failures there are probably worse problems to deal with. ### LocalObjectManager local_objects_ vs. ObjectManager local_objects_ An important distinction is needed between both classes' local objects, where we need to aggregate and free any objects within both classes. LocalObjectManager in this case keeps track of primary copies as well as spilled copies. ObjectManager keeps track of anything in plasma such as primary copies / secondary copies. Thus, we need to get the union of both objects to get the objects that we want to free. ## Testing Ran python tests and C++ tests adjacent to these changes to ensure no regressions. Future e2e testing in #63181 We will fix this race condition in the immediate next PR, which uses the GCS to broadcast deaths and have the raylets free accordingly. --------- Signed-off-by: aaron.li <[email protected]> Signed-off-by: aaronscalene <[email protected]>
… free mechanism (ray-project#63218) ## Motivation Within this multi-step PR process, our goal is to change our current **FreeObjects** implementation to an owner driven process. Current design of FreeObjects involves spraying the entire cluster with FreeObjects RPCs. This introduces many caveats: bloating observability with FreeObjects RPC counts, sending excessive RPCs, and worse mental model from owner-driven reference counting. This is a continuation from ray-project#63117. Due to the race condition detailed in the testing section of the PR, we decided to merge both changes for a complete PR. Our current design for **FreeObjects** involves the following steps: 1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference. 2. The owner finds out, and sends a pubsub message (initialized when pinning the primary copy) to the primary copy raylet. 3. The primary copy raylet frees its primary copy, and then broadcasts free secondary copies to all nodes within the cluster. (This is batched and sent periodically). The reason the primary copy raylet needs to broadcast secondary copies is because it doesn't store object locations for its primary copy, this is only stored on the owner. Thus, in order to ensure all secondary copies are freed, there is a need to broadcast to all nodes. ## Design As noted above, the owner stores the locations of all copies of the objects, where `pinned_at_node_id_` represents the primary copy location and the `locations` vector demonstrates all secondary object locations. We now move towards a new design **FreeObjects**. We will get rid of the pubsub between owner -> primary copy raylet. Instead: 1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference. 2. The owner sends RPCs to primary and secondary copy holders to free their objects. (Since it has all of its locations) However, this doesn't easily solve our issue since the pubsub also has an `owner_dead_callback`, which fires when the owner has died. This will help clean up the primary object and ensure there are no memory leaks in this case. To continue supporting this functionality, if the owner dies, this information is propagated by the GCS, and thus each raylet just listens to the GCS events and updates their states accordingly. Originally, the design was that: - the pubsub connection fails / ends for some unexpected reason - the owner is thought to be dead, so the primary copy raylet then frees its primary copy and queues up **FreeObjects** to broadcast to all secondary copies The new design: - The GCS already publishes WorkerFailure and NodeRemoved announcements to all raylets. This is so that raylets know to release worker leases of dead nodes / workers - With this new design, the raylets will listen and additionally clear any objects that had their owner on the failed worker / node - Something to consider is how exactly GCS gets these notifications, and if there would be any slowness in these notifications. 1.) When the worker process dies (but the node remains alive), the raylet picks up the worker death relatively quickly via the broken IPC connection and sends the worker death up to the GCS, and GCS broadcasts it. 2.) On node death, similar story. However, in old implementation, the long poll connection would be sitting the retryable grpc client queue waiting for either the connection to come back up or the GCS to get a worker death notification. Hence all in all, there really shouldn't be a significant change in behavior. ## Description This PR covers the first and second part of the **FreeObjects** change. The first part is strictly adding functionality for the owner to be in charge of freeing objects. We make the first step away from this design such that the owner calls a new **FreeLocalObjects** RPC to all primary and secondary copy locations when **OnObjectsOutOfScopeOrFreed**. The second part amends the functionality of the current owner dead pubsub callback to be moved from an eager pubsub death callback to a more passive listener callback. ## Considerations ### NodeManager RPC vs. ObjectManager RPC For this PR, I considered either 1) Adding a new RPC to **NodeManager** or 2) Adding new route that calls into existing **ObjectManager** FreeObjects. Ultimately, I decided to go with 1). A design consideration here is that workers currently only call into raylets' **NodeManager**, so part of this is to keep with existing implementation. Another reason is that our new **HandleFreeLocalObjects** would be responsible for 2 things: 1) if primary copy, delete metadata from **LocalObjectManager** (manages spilled and primary copies) and 2) if any copy, queue up within **FreeObjects**. Thus, **NodeManager** currently has functionality that calls into **LocalObjectManager**. Furthermore, I find that directly interfacing with **ObjectManager** is not as intuitive, and creating a new path just for **ObjectManager** does not seem ideal. ### Moving Around ReferenceCounter Variables For this PR, I decided to follow similar formats in the codebase, and have all the lambdas within the constructor shifted to the end. In this case, they can be considered optional arguments and can be defaulted to null if not specified. This leads to easier testing implementations. A tricky part is to ensure these functions generate no-op if they are not specified. ### Only Owner Frees An important consideration is that now that we are sending from the worker side, only if the object is freed is owned by the current worker should the worker send RPC requests to the object locations. Otherwise, the worker should just keep quiet. ### Dead Code Deleted in Future For this PR, I kept **FreeObjects**'s `local_only=false` case still alive, even though this case is essentially never called again. In the future, I will delete this dead code. ### Testing Changes and ReferenceCounter Changes For this PR, there were many testing changes that are needed because of this new path that is different from the first one. For now, many of these tests are just hardcoded to match correct behavior, but in the future some unnecessary tests might be deleted or shuffled around to match the new implementation. ### Pass Over All Objects This new design introduces a pass over all objects within the current node every announcement. However, failed nodes and worker announcements should not be too common and if the object is not owned by the failed worker / node it would be a no-op; thus this should not lead to any latency issues. ### Owner is Less Eager This new design will be a less eager free, especially for the primary copy of the node. This is definitely an important part to consider, however since it is similar a pubsub for node information, the latency should not be that big of a deal. Furthermore, the pubsub interface already keeps track of network failures etc. to some extent, and if there are further failures / GCS failures there are probably worse problems to deal with. ### LocalObjectManager local_objects_ vs. ObjectManager local_objects_ An important distinction is needed between both classes' local objects, where we need to aggregate and free any objects within both classes. LocalObjectManager in this case keeps track of primary copies as well as spilled copies. ObjectManager keeps track of anything in plasma such as primary copies / secondary copies. Thus, we need to get the union of both objects to get the objects that we want to free. ## Testing Ran python tests and C++ tests adjacent to these changes to ensure no regressions. Future e2e testing in ray-project#63181 We will fix this race condition in the immediate next PR, which uses the GCS to broadcast deaths and have the raylets free accordingly. --------- Signed-off-by: aaron.li <[email protected]> Signed-off-by: aaronscalene <[email protected]>
… free mechanism (ray-project#63218) ## Motivation Within this multi-step PR process, our goal is to change our current **FreeObjects** implementation to an owner driven process. Current design of FreeObjects involves spraying the entire cluster with FreeObjects RPCs. This introduces many caveats: bloating observability with FreeObjects RPC counts, sending excessive RPCs, and worse mental model from owner-driven reference counting. This is a continuation from ray-project#63117. Due to the race condition detailed in the testing section of the PR, we decided to merge both changes for a complete PR. Our current design for **FreeObjects** involves the following steps: 1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference. 2. The owner finds out, and sends a pubsub message (initialized when pinning the primary copy) to the primary copy raylet. 3. The primary copy raylet frees its primary copy, and then broadcasts free secondary copies to all nodes within the cluster. (This is batched and sent periodically). The reason the primary copy raylet needs to broadcast secondary copies is because it doesn't store object locations for its primary copy, this is only stored on the owner. Thus, in order to ensure all secondary copies are freed, there is a need to broadcast to all nodes. ## Design As noted above, the owner stores the locations of all copies of the objects, where `pinned_at_node_id_` represents the primary copy location and the `locations` vector demonstrates all secondary object locations. We now move towards a new design **FreeObjects**. We will get rid of the pubsub between owner -> primary copy raylet. Instead: 1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference. 2. The owner sends RPCs to primary and secondary copy holders to free their objects. (Since it has all of its locations) However, this doesn't easily solve our issue since the pubsub also has an `owner_dead_callback`, which fires when the owner has died. This will help clean up the primary object and ensure there are no memory leaks in this case. To continue supporting this functionality, if the owner dies, this information is propagated by the GCS, and thus each raylet just listens to the GCS events and updates their states accordingly. Originally, the design was that: - the pubsub connection fails / ends for some unexpected reason - the owner is thought to be dead, so the primary copy raylet then frees its primary copy and queues up **FreeObjects** to broadcast to all secondary copies The new design: - The GCS already publishes WorkerFailure and NodeRemoved announcements to all raylets. This is so that raylets know to release worker leases of dead nodes / workers - With this new design, the raylets will listen and additionally clear any objects that had their owner on the failed worker / node - Something to consider is how exactly GCS gets these notifications, and if there would be any slowness in these notifications. 1.) When the worker process dies (but the node remains alive), the raylet picks up the worker death relatively quickly via the broken IPC connection and sends the worker death up to the GCS, and GCS broadcasts it. 2.) On node death, similar story. However, in old implementation, the long poll connection would be sitting the retryable grpc client queue waiting for either the connection to come back up or the GCS to get a worker death notification. Hence all in all, there really shouldn't be a significant change in behavior. ## Description This PR covers the first and second part of the **FreeObjects** change. The first part is strictly adding functionality for the owner to be in charge of freeing objects. We make the first step away from this design such that the owner calls a new **FreeLocalObjects** RPC to all primary and secondary copy locations when **OnObjectsOutOfScopeOrFreed**. The second part amends the functionality of the current owner dead pubsub callback to be moved from an eager pubsub death callback to a more passive listener callback. ## Considerations ### NodeManager RPC vs. ObjectManager RPC For this PR, I considered either 1) Adding a new RPC to **NodeManager** or 2) Adding new route that calls into existing **ObjectManager** FreeObjects. Ultimately, I decided to go with 1). A design consideration here is that workers currently only call into raylets' **NodeManager**, so part of this is to keep with existing implementation. Another reason is that our new **HandleFreeLocalObjects** would be responsible for 2 things: 1) if primary copy, delete metadata from **LocalObjectManager** (manages spilled and primary copies) and 2) if any copy, queue up within **FreeObjects**. Thus, **NodeManager** currently has functionality that calls into **LocalObjectManager**. Furthermore, I find that directly interfacing with **ObjectManager** is not as intuitive, and creating a new path just for **ObjectManager** does not seem ideal. ### Moving Around ReferenceCounter Variables For this PR, I decided to follow similar formats in the codebase, and have all the lambdas within the constructor shifted to the end. In this case, they can be considered optional arguments and can be defaulted to null if not specified. This leads to easier testing implementations. A tricky part is to ensure these functions generate no-op if they are not specified. ### Only Owner Frees An important consideration is that now that we are sending from the worker side, only if the object is freed is owned by the current worker should the worker send RPC requests to the object locations. Otherwise, the worker should just keep quiet. ### Dead Code Deleted in Future For this PR, I kept **FreeObjects**'s `local_only=false` case still alive, even though this case is essentially never called again. In the future, I will delete this dead code. ### Testing Changes and ReferenceCounter Changes For this PR, there were many testing changes that are needed because of this new path that is different from the first one. For now, many of these tests are just hardcoded to match correct behavior, but in the future some unnecessary tests might be deleted or shuffled around to match the new implementation. ### Pass Over All Objects This new design introduces a pass over all objects within the current node every announcement. However, failed nodes and worker announcements should not be too common and if the object is not owned by the failed worker / node it would be a no-op; thus this should not lead to any latency issues. ### Owner is Less Eager This new design will be a less eager free, especially for the primary copy of the node. This is definitely an important part to consider, however since it is similar a pubsub for node information, the latency should not be that big of a deal. Furthermore, the pubsub interface already keeps track of network failures etc. to some extent, and if there are further failures / GCS failures there are probably worse problems to deal with. ### LocalObjectManager local_objects_ vs. ObjectManager local_objects_ An important distinction is needed between both classes' local objects, where we need to aggregate and free any objects within both classes. LocalObjectManager in this case keeps track of primary copies as well as spilled copies. ObjectManager keeps track of anything in plasma such as primary copies / secondary copies. Thus, we need to get the union of both objects to get the objects that we want to free. ## Testing Ran python tests and C++ tests adjacent to these changes to ensure no regressions. Future e2e testing in ray-project#63181 We will fix this race condition in the immediate next PR, which uses the GCS to broadcast deaths and have the raylets free accordingly. --------- Signed-off-by: aaron.li <[email protected]> Signed-off-by: aaronscalene <[email protected]>
… free mechanism (ray-project#63218) ## Motivation Within this multi-step PR process, our goal is to change our current **FreeObjects** implementation to an owner driven process. Current design of FreeObjects involves spraying the entire cluster with FreeObjects RPCs. This introduces many caveats: bloating observability with FreeObjects RPC counts, sending excessive RPCs, and worse mental model from owner-driven reference counting. This is a continuation from ray-project#63117. Due to the race condition detailed in the testing section of the PR, we decided to merge both changes for a complete PR. Our current design for **FreeObjects** involves the following steps: 1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference. 2. The owner finds out, and sends a pubsub message (initialized when pinning the primary copy) to the primary copy raylet. 3. The primary copy raylet frees its primary copy, and then broadcasts free secondary copies to all nodes within the cluster. (This is batched and sent periodically). The reason the primary copy raylet needs to broadcast secondary copies is because it doesn't store object locations for its primary copy, this is only stored on the owner. Thus, in order to ensure all secondary copies are freed, there is a need to broadcast to all nodes. ## Design As noted above, the owner stores the locations of all copies of the objects, where `pinned_at_node_id_` represents the primary copy location and the `locations` vector demonstrates all secondary object locations. We now move towards a new design **FreeObjects**. We will get rid of the pubsub between owner -> primary copy raylet. Instead: 1. The reference goes out of scope. The reference here represents both the owner's python references, as well as other borrower references throughout the cluster, which is tracked through the owner reference. 2. The owner sends RPCs to primary and secondary copy holders to free their objects. (Since it has all of its locations) However, this doesn't easily solve our issue since the pubsub also has an `owner_dead_callback`, which fires when the owner has died. This will help clean up the primary object and ensure there are no memory leaks in this case. To continue supporting this functionality, if the owner dies, this information is propagated by the GCS, and thus each raylet just listens to the GCS events and updates their states accordingly. Originally, the design was that: - the pubsub connection fails / ends for some unexpected reason - the owner is thought to be dead, so the primary copy raylet then frees its primary copy and queues up **FreeObjects** to broadcast to all secondary copies The new design: - The GCS already publishes WorkerFailure and NodeRemoved announcements to all raylets. This is so that raylets know to release worker leases of dead nodes / workers - With this new design, the raylets will listen and additionally clear any objects that had their owner on the failed worker / node - Something to consider is how exactly GCS gets these notifications, and if there would be any slowness in these notifications. 1.) When the worker process dies (but the node remains alive), the raylet picks up the worker death relatively quickly via the broken IPC connection and sends the worker death up to the GCS, and GCS broadcasts it. 2.) On node death, similar story. However, in old implementation, the long poll connection would be sitting the retryable grpc client queue waiting for either the connection to come back up or the GCS to get a worker death notification. Hence all in all, there really shouldn't be a significant change in behavior. ## Description This PR covers the first and second part of the **FreeObjects** change. The first part is strictly adding functionality for the owner to be in charge of freeing objects. We make the first step away from this design such that the owner calls a new **FreeLocalObjects** RPC to all primary and secondary copy locations when **OnObjectsOutOfScopeOrFreed**. The second part amends the functionality of the current owner dead pubsub callback to be moved from an eager pubsub death callback to a more passive listener callback. ## Considerations ### NodeManager RPC vs. ObjectManager RPC For this PR, I considered either 1) Adding a new RPC to **NodeManager** or 2) Adding new route that calls into existing **ObjectManager** FreeObjects. Ultimately, I decided to go with 1). A design consideration here is that workers currently only call into raylets' **NodeManager**, so part of this is to keep with existing implementation. Another reason is that our new **HandleFreeLocalObjects** would be responsible for 2 things: 1) if primary copy, delete metadata from **LocalObjectManager** (manages spilled and primary copies) and 2) if any copy, queue up within **FreeObjects**. Thus, **NodeManager** currently has functionality that calls into **LocalObjectManager**. Furthermore, I find that directly interfacing with **ObjectManager** is not as intuitive, and creating a new path just for **ObjectManager** does not seem ideal. ### Moving Around ReferenceCounter Variables For this PR, I decided to follow similar formats in the codebase, and have all the lambdas within the constructor shifted to the end. In this case, they can be considered optional arguments and can be defaulted to null if not specified. This leads to easier testing implementations. A tricky part is to ensure these functions generate no-op if they are not specified. ### Only Owner Frees An important consideration is that now that we are sending from the worker side, only if the object is freed is owned by the current worker should the worker send RPC requests to the object locations. Otherwise, the worker should just keep quiet. ### Dead Code Deleted in Future For this PR, I kept **FreeObjects**'s `local_only=false` case still alive, even though this case is essentially never called again. In the future, I will delete this dead code. ### Testing Changes and ReferenceCounter Changes For this PR, there were many testing changes that are needed because of this new path that is different from the first one. For now, many of these tests are just hardcoded to match correct behavior, but in the future some unnecessary tests might be deleted or shuffled around to match the new implementation. ### Pass Over All Objects This new design introduces a pass over all objects within the current node every announcement. However, failed nodes and worker announcements should not be too common and if the object is not owned by the failed worker / node it would be a no-op; thus this should not lead to any latency issues. ### Owner is Less Eager This new design will be a less eager free, especially for the primary copy of the node. This is definitely an important part to consider, however since it is similar a pubsub for node information, the latency should not be that big of a deal. Furthermore, the pubsub interface already keeps track of network failures etc. to some extent, and if there are further failures / GCS failures there are probably worse problems to deal with. ### LocalObjectManager local_objects_ vs. ObjectManager local_objects_ An important distinction is needed between both classes' local objects, where we need to aggregate and free any objects within both classes. LocalObjectManager in this case keeps track of primary copies as well as spilled copies. ObjectManager keeps track of anything in plasma such as primary copies / secondary copies. Thus, we need to get the union of both objects to get the objects that we want to free. ## Testing Ran python tests and C++ tests adjacent to these changes to ensure no regressions. Future e2e testing in ray-project#63181 We will fix this race condition in the immediate next PR, which uses the GCS to broadcast deaths and have the raylets free accordingly. --------- Signed-off-by: aaron.li <[email protected]> Signed-off-by: aaronscalene <[email protected]> Signed-off-by: 400Ping <[email protected]>


Motivation
Within this multi-step PR process, our goal is to change our current FreeObjects implementation to an owner driven process. Current design of FreeObjects involves spraying the entire cluster with FreeObjects RPCs. This introduces many caveats: bloating observability with FreeObjects RPC counts, sending excessive RPCs, and worse mental model from owner-driven reference counting.
Our current design for FreeObjects involves the following steps:
Design
As noted above, the owner stores the locations of all copies of the objects, where
pinned_at_node_id_represents the primary copy location and thelocationsvector demonstrates all secondary object locations.We now move towards a new design FreeObjects. We will get rid of the pubsub between owner -> primary copy raylet. Instead:
However, this doesn't easily solve our issue since the pubsub also has an
owner_dead_callback, which fires when the owner has died. This will help clean up the primary object and ensure there are no memory leaks in this case. To continue supporting this functionality, if the owner dies, this information is propagated by the GCS, and thus each raylet just listens to the GCS events and updates their states accordingly.Description
This PR covers the first part of the FreeObjects change. This first part is strictly adding functionality for the owner to be in charge of freeing objects. We make the first step away from this design such that the owner calls a new FreeLocalObjects RPC to all primary and secondary copy locations when OnObjectsOutOfScopeOrFreed.
Considerations
NodeManager RPC vs. ObjectManager RPC
For this PR, I considered either 1) Adding a new RPC to NodeManager or 2) Adding new route that calls into existing ObjectManager FreeObjects. Ultimately, I decided to go with 1). A design consideration here is that workers currently only call into raylets' NodeManager, so part of this is to keep with existing implementation. Another reason is that our new HandleFreeLocalObjects would be responsible for 2 things: 1) if primary copy, delete metadata from LocalObjectManager (manages spilled and primary copies) and 2) if any copy, queue up within FreeObjects. Thus, NodeManager currently has functionality that calls into LocalObjectManager. Furthermore, I find that directly interfacing with ObjectManager is not as intuitive, and creating a new path just for ObjectManager does not seem ideal.
Moving Around ReferenceCounter Variables
For this PR, I decided to follow similar formats in the codebase, and have all the lambdas within the constructor shifted to the end. In this case, they can be considered optional arguments and can be defaulted to null if not specified. This leads to easier testing implementations. A tricky part is to ensure these functions generate no-op if they are not specified.
Only Owner Frees
An important consideration is that now that we are sending from the worker side, only if the object is freed is owned by the current worker should the worker send RPC requests to the object locations. Otherwise, the worker should just keep quiet.
Dead Code Deleted in Future
For this PR, I kept FreeObjects's
local_only=falsecase still alive, even though this case is essentially never called again. In the future, I will delete this dead code.Testing Changes and ReferenceCounter Changes
For this PR, there were many testing changes that are needed because of this new path that is different from the first one. For now, many of these tests are just hardcoded to match correct behavior, but in the future some unnecessary tests might be deleted or shuffled around to match the new implementation.
Testing
Ran python tests and C++ tests adjacent to these changes to ensure no regressions. Future e2e testing in #63181
Introduces Race Condition
Note that this PR actually introduces a race condition. Since this is currently still a half step to removing the pubsub, there is a race in the following example.
We will fix this race condition in the immediate next PR, which uses the GCS to broadcast deaths and have the raylets free accordingly.