-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] trim size of Reference struct #23853
Conversation
d00647a
to
251eece
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! A couple questions about testing:
- Were you able to confirm that the shuffle benchmark doesn't set the new optional fields?
- Could we add this to the microbenchmark suite and start tracking memory usage in the perf dashboard?
@@ -494,6 +494,50 @@ class ReferenceCounter : public ReferenceCounterInterface, | |||
void ReleaseAllLocalReferences(); | |||
|
|||
private: | |||
struct ContainingReferences { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to NestedReferenceCount
? And document that it is only used for nested refs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This struct does not seem to contain any count? How about NestedReferences
, or any other naming suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fields actually are counts if you take the size of the sets but yeah we can use NestedReferenceInfo
or something, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, renamed to NestedReferenceCount
.
/// Returns the default value of the struct if it is not set. | ||
const BorrowInfo &borrow() const { | ||
if (borrow_info == nullptr) { | ||
static auto *default_info = new BorrowInfo(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
static auto *default_info = new BorrowInfo(); | |
static BorrowInfo default_info; |
Then return &default_info
? But I think it's fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. Using static local
raw pointers to avoid the objects being destructed was a common idiom in my previous company, so people need not think about the implication of destroying default_info
on shutdown. But I can update this if it conflicts with Ray's style.
|
||
/// Callback that will be called when this ObjectID no longer has | ||
/// references. | ||
std::function<void(const ObjectID &)> on_delete; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do it in a different PR, but out of curiosity, did you try testing what would happen if we use the same callback for all objects instead of saving them individually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not tested that yet and can do this in the next PR.
Yes the new optional fields do not show up in the profile. I can add some check failure too. I can add a per-object ref memory benchmark separately. |
…emory cap (#23985) In a1e06f6, memory bound was added for each subscribed entity in the publisher. It adds two extra `std::deque` per subscribed entity, which turns out to cost a lot more memory when there are a large number of `ObjectRef`s: #23853 (comment) This PR avoids the extra memory usage for entities in channels unlikely to grow too large, i.e. all channels except those for logs and error info. Subscribed entity memory usage no longer shows up in the memory profile when there are 1M object refs. Raw data: [profile006.pb.gz](https://github.com/ray-project/ray/files/8508547/profile006.pb.gz)
Why are these changes needed?
During large scale shuffle (number of partitions used >= 1000), driver uses significant amount of memory for storing ObjectRefs. On Intel MacOS, each
Reference
struct currently takes up 592 bytes. We can reduce per-Reference
memory footprint:sizeof(Reference)
from 592 to 400.Reference
struct can be reordered to enhance packing. This reducessizeof(Reference)
from 400 to 368.On Intel MacOS running the shuffle benchmark with 1000 partitions and 10MB partition size, RSS at the end of shuffle drops from ~5GB to ~4.5GB.
Related issue number
#23604
Checks
scripts/format.sh
to lint the changes in this PR.