Repository navigation
[Core] Free unconsumed object reported for deleted generator - #65276
Conversation
Signed-off-by: davik <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request addresses a memory leak where unconsumed objects from a deleted streaming generator are not freed. It introduces a mechanism to immediately and asynchronously free these unconsumed plasma objects on the executor's node when the caller deletes the generator. The changes include adding a FreeObjectOnNodesCallback to the TaskManager, updating HandleReportGeneratorItemReturns to trigger this callback for unconsumed items of deleted streams, and adding corresponding unit and regression tests. The review feedback highlights a misplaced comment regarding the caller_deleted logic that became confusing after the refactoring, suggesting it be moved and merged with the comment at the top of the loop.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 87b9cc0. Configure here.
Signed-off-by: davik <[email protected]>
| if (caller_deleted && !stream_it->second.IsObjectConsumed(object_index)) { | ||
| if (returned_object.in_plasma()) { | ||
| const NodeID worker_node_id = NodeID::FromBinary(request.worker_addr().node_id()); | ||
| if (!worker_node_id.IsNil()) { |
There was a problem hiding this comment.
how can the worker node id ever be nil here, maybe RAY_CHECK?
| "Object %s for a deleted generator can no longer be used. They should be " | ||
| "freed immediately.", | ||
| object_id.Hex()); | ||
| free_object_on_nodes_async_(object_id, locations); |
There was a problem hiding this comment.
hmmm this is a bit unintuitive to me. To clarify, so the executor core worker running the streaming generator serializes the plasma return into it's own local raylet, and once thats done sends a RPC to to the owner via ReportGeneratorItemReturns for that streaming generator ref. If the streaming generator ref has gone out of scope on the owner, it'll then send a free objects RPC back to the raylet that contains the object.
Ideally what would be nice is if the worker running the streaming executor had some form of signal from the owner so that it avoids the plasma copy into it's own local raylet entirely.... but I'm guessing thats a more involved change for a bug fix. Do you think it's worth leaving as a follow up?
There was a problem hiding this comment.
I agree that avoiding the creation would be better. The main thing blocking this is we currently assume the object has been stored before reporting. If we want to avoid adding an extra round of rpc, reporting before storing could break the assumption and cause race conditions when pulling for the object. It's worth leaving as followup as it's not a small change.
| }, | ||
| "CoreWorker.SetDirectTransportMetadata"); | ||
| }, | ||
| /*free_object_on_nodes_async=*/ |
There was a problem hiding this comment.
since this is only used for the streaming generator edge case, maybe make the name a bit more specific?
| ) | ||
| def gen(all_produced): | ||
| for i in range(5): | ||
| yield np.ones(10**7, dtype=np.uint8) * i |
There was a problem hiding this comment.
nit: any reason you're specifically using np vs just yielding a big list?
There was a problem hiding this comment.
no particular reason. I like np better since it's closer to actual workloads.
| def gen(all_produced): | ||
| for i in range(5): | ||
| yield np.ones(10**7, dtype=np.uint8) * i | ||
| ray.get(all_produced.send.remote()) |
There was a problem hiding this comment.
nit: this doesn't guarantee that the ref goes out of scope while you're in the midst of still executing the streaming generator. I think it would be cool to have signal actor pause the loop, maybe after first iteration then proceed to make sure that returns 2...4 are freed
There was a problem hiding this comment.
The generator back pressure config should take care of this issue.
| ASSERT_EQ(store_->Size(), 1); | ||
| } | ||
|
|
||
| TEST_F(TaskManagerTest, TestObjectRefStreamCallerDeletedFreesUnconsumedPlasmaReturns) { |
Signed-off-by: davik <[email protected]>
Signed-off-by: davik <[email protected]>
…ject#65276) ## Description In 2.56 [raylet subscribed to object owners](https://github.com/ray-project/ray/pull/63181/changes#diff-52339e7cd2a22cd1c21b1973ba599995827a4b12fdc42fd06c5709836acd767eL3805) to listen to when the objects should be evicted. However, ray-project#63181 removed this system in favor of sending free object requests to specifically the nodes that hold them instead of broadcasting to all nodes. This change has caused a regression in the following code snippet: ```py @ray.remote( num_cpus=1, _generator_backpressure_num_objects=1, ) def gen(): for i in range(5): yield np.ones(10**7, dtype=np.uint8) * i gen_ref = gen.remote() del gen_ref # the back-pressured objects will remain with the worker that created # even though the generator has been deleted and the object will be accessible ``` In the snippet above, when the streaming generator gets deleted, the items that are back pressured will be produced anyways to ensure the task runs to completion properly. For version 2.56 and before, [these lines](https://github.com/ray-project/ray/pull/63181/changes#diff-52339e7cd2a22cd1c21b1973ba599995827a4b12fdc42fd06c5709836acd767eL3851-L3856) are responsible for garbage collecting the back-pressured items that got created anyways. However, after the targeted free object change. The mechanism is removed, and reported unconsumed objects sticks around even if their generator ref is deleted, leaking the objects in object store. This PR handles this case by checking if we've received an unconsumed object after generator ref has already gone out of scope. If such objects were received, we would instead free them immediately, avoiding the object leak. ## Related issues Fixes leaking generator object that are reported after generator ref goes out of scope. Introduced in ray-project#63181. ## Additional information --------- Signed-off-by: davik <[email protected]> Co-authored-by: davik <[email protected]>

Description
In 2.56 raylet subscribed to object owners to listen to when the objects should be evicted. However, #63181 removed this system in favor of sending free object requests to specifically the nodes that hold them instead of broadcasting to all nodes.
This change has caused a regression in the following code snippet:
In the snippet above, when the streaming generator gets deleted, the items that are back pressured will be produced anyways to ensure the task runs to completion properly. For version 2.56 and before, these lines are responsible for garbage collecting the back-pressured items that got created anyways. However, after the targeted free object change. The mechanism is removed, and reported unconsumed objects sticks around even if their generator ref is deleted, leaking the objects in object store.
This PR handles this case by checking if we've received an unconsumed object after generator ref has already gone out of scope. If such objects were received, we would instead free them immediately, avoiding the object leak.
Related issues
Fixes leaking generator object that are reported after generator ref goes out of scope. Introduced in #63181.
Additional information