-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: Memory stats #2162
feat: Memory stats #2162
Conversation
It looks like tracking the Here are some numbers during the start and the middle of an active (full sync) replication, after a
As you'll see, there is a 2mb diff related to replication which is not accounted for in the |
I would not worry about 2mb data differrence. I would start worrying about 200MB. |
As discussed offline, I also added tracking for channels, which is a major factor in growth and shrinking of serialization operations. |
I'd like to merge this now, and work on some stress tests to show potential misses in our memory coverage. |
|
||
#pragma once | ||
|
||
#include "core/fibers.h" |
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 used core fibers because I migrated from boost fibers. let's just reference the correct include file directly
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.
That would mean using util::fb2::SimpleChannel
instead of dfly
, I thought that was the purpose of that file?
src/server/memory_cmd.cc
Outdated
|
||
// RSS | ||
stats.push_back("rss_bytes"); | ||
stats.push_back(absl::StrCat(rss_mem_current.load())); |
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 prefer that we pass memory_order_relaxed
src/server/memory_cmd.cc
Outdated
stats.push_back("serialization"); | ||
stats.push_back(absl::StrCat(serialization_memory)); | ||
|
||
return (*cntx_)->SendSimpleStrArr(stats); |
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.
nice that you used a formatted output. nit: you can specify this as MAP to get even better representation for resp3 enabled clients.
src/core/size_tracking_channel.h
Outdated
// Here and below, we must accept a T instead of building it from variadic args, as we need to | ||
// know its size in case it is added. | ||
void Push(T t) noexcept { | ||
size_ += t.size(); | ||
queue_.Push(std::move(t)); | ||
} |
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.
- For RDB serialization we use multiple snapshots that write into a single channel, so it's not safe to access an non-atomic size
- If you add this, please also update the code around, so it doesn't become convoluted where there a multiple ways to do the same... For example
RdbSaver::Impl::GetTotalBuffersSize
uses stats for approximating the high bound of this very channel capacity that you added
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.
Also about (2), it will now be the case that because we have two separate memory tracking systems, info memory and memory stats will return different results 🤷🏻♂️🤷🏻♂️
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.
Re/ 1: good comment, will fix, thanks!
Re/ 2: I'm not sure what you mean, if I update GetTotalBufferSize()
to use the to-be-added GetTotalChannelCapacity()
method, why would memory stats have different results? Or did you mean something else?
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.
No, I just meant that if you don't unify the tracking approaches eventually, they'll not only have duplicated code, but will also diverge in values 🙂
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.
Any reason not to modify GetTotalBufferSize()
to use GetTotalChannelCapacity()
? Current implementation returns how many total bytes inserted, without ever decreasing that number, it might be hugely over estimating..
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.
No, there is no reason not to modify it
PS: It does decrease the number, pulled_bytes grows, so it shouldn't reach zero at the very end 🤔
size_t total_bytes = pushed_bytes.load(memory_order_relaxed) + serializer_bytes.load(memory_order_relaxed) - pulled_bytes;
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.
right, I missed that.
Anyway, I unified the logic, thanks for pointing that out.
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.
👍🏻
auto cb = [this, &channel_bytes, &serializer_bytes](ShardId sid) { | ||
auto& snapshot = shard_snapshots_[sid]; | ||
pushed_bytes.fetch_add(snapshot->pushed_bytes(), memory_order_relaxed); | ||
channel_bytes.fetch_add(snapshot->GetTotalChannelCapacity(), memory_order_relaxed); | ||
serializer_bytes.store(snapshot->GetTotalBufferCapacity(), memory_order_relaxed); |
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.
Nit: I think we can do it without hops now (if the state doesn't change in-between) 🤔 But I think it doesn't matter for a monitoring command
Add
MEMORY STATS
command that prints some useful memory related information, including RSS, db memory size, connection count & buffer size, replication count & buffer size, serialization buffer size.