-
Notifications
You must be signed in to change notification settings - Fork 876
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(server): Better connection memory tracking #2205
Conversation
src/server/CMakeLists.txt
Outdated
@@ -28,7 +28,7 @@ if (NOT APPLE) | |||
endif() | |||
|
|||
add_library(dragonfly_lib engine_shard_set.cc channel_store.cc command_registry.cc | |||
config_registry.cc conn_context.cc debugcmd.cc dflycmd.cc | |||
config_registry.cc conn_context.cc debugcmd.cc dflycmd.cc allocation_sampler.cc |
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 we can split this PR to few PRs?
for example I believe AllocationSampler can be in a seprate PR
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.
Good idea! Done.
@@ -98,8 +100,8 @@ class RedisParser { | |||
absl::InlinedVector<std::pair<uint32_t, RespVec*>, 4> parse_stack_; | |||
std::vector<std::unique_ptr<RespVec>> stash_; | |||
|
|||
using BlobPtr = std::unique_ptr<uint8_t[]>; | |||
std::vector<BlobPtr> buf_stash_; | |||
using Blob = std::vector<uint8_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.
can you extract this change as well to a new PR?
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.
it is part of this PR though, because that's the only way we can do tracking (we have no way of getting the array size)
// We add a hardcoded 9k value to accomodate for the part of the Fiber stack that is in use. | ||
// The allocated stack is actually larger (~130k), but only a small fraction of that (9k | ||
// according to our checks) is actually part of the RSS. | ||
mem += 9'000; |
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.
Don't we account for the dispatch fiber here as well?
So shouldn't it be:
mem += 9k; // unconditional main fiber
if (dispatch_fb_.IsJoinable())
mem += 9k
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's a nice observation.
An actual test of creating many connections show an average of 9kb per connection.
All of these connections send a PING
, and then later randomly (and slowly) created string keys.
I imagine that PING
creates a dispatch fiber, and as such, it should already be included in the 9kb. In other words, maybe it should be
constexpr size_t kMinimalFiberStackKb = 4'500;
mem += kMinimalFiberStackKb;
if (dispatch_db_.IsJoinable())
mem += kMinimalFiberStackKb;
However, I would like to check this with and without issuing a PING
to make sure it works as expected. Stay tuned :)
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.
To clarify, I also created a simple test to make sure that using a Fiber's stack actually increases RSS (in addition to creating that stack). But the 9k part comes from experimenting with the actual connection fibers (as it depends how much of the stack is used)
No description provided.