-
Notifications
You must be signed in to change notification settings - Fork 467
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: support maxmemory-clients config #2513
Closed
AntiTopQuark
wants to merge
28
commits into
apache:unstable
from
AntiTopQuark:limit_maxmemory_clients
Closed
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
67db430
feat: support maxmemory-clients
AntiTopQuark 03e44c4
update
AntiTopQuark 1e5aba7
update
AntiTopQuark d388a23
update
AntiTopQuark 5649f62
ci: add Debian environment to CI workflow (#2510)
c8ef bc4a195
feat(config): add `txn_context_enabled` to allow to enable the transa…
PokIsemaine 8b41ab6
fix(test): remove meaningless `list-max-ziplist-size` (#2517)
PokIsemaine b2665a4
fix(replication): potential deadlock when switching master frequentl…
git-hulk 75f6177
fix(typo): `filed -> field` (#2519)
AntiTopQuark a3bf6eb
feat: support maxmemory-clients
AntiTopQuark fac72fb
update
AntiTopQuark eb96c7b
Merge branch 'unstable' into limit_maxmemory_clients
AntiTopQuark 2781747
fix data race error
AntiTopQuark a2c264a
Merge branch 'unstable' into limit_maxmemory_clients
AntiTopQuark ed6b30d
update unit case
AntiTopQuark 63378b2
update
AntiTopQuark e711754
update
AntiTopQuark 5c48461
Merge branch 'unstable' into limit_maxmemory_clients
AntiTopQuark 4f19056
update
AntiTopQuark 7aa400e
update
AntiTopQuark 3feb149
u
AntiTopQuark 10dffe1
update code style
AntiTopQuark 90e79d9
update code style
AntiTopQuark 93dc21a
update code style
AntiTopQuark 5bfd3ce
Merge branch 'unstable' into limit_maxmemory_clients
AntiTopQuark 104f354
Merge branch 'unstable' into limit_maxmemory_clients
AntiTopQuark 40454db
Merge branch 'unstable' into limit_maxmemory_clients
AntiTopQuark 0aa864d
Merge branch 'unstable' into limit_maxmemory_clients
AntiTopQuark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,8 @@ Connection::Connection(bufferevent *bev, Worker *owner) | |
int64_t now = util::GetTimeStamp(); | ||
create_time_ = now; | ||
last_interaction_ = now; | ||
output_buffer_.clear(); | ||
slave_output_buffer_.clear(); | ||
} | ||
|
||
Connection::~Connection() { | ||
|
@@ -368,8 +370,9 @@ static bool IsCmdForIndexing(const CommandAttributes *attr) { | |
} | ||
|
||
void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) { | ||
GetOutputBuffer().clear(); | ||
const Config *config = srv_->GetConfig(); | ||
std::string reply; | ||
std::string &reply = GetOutputBuffer(); | ||
std::string password = config->requirepass; | ||
|
||
while (!to_process_cmds->empty()) { | ||
|
@@ -559,4 +562,37 @@ void Connection::ResetMultiExec() { | |
DisableFlag(Connection::kMultiExec); | ||
} | ||
|
||
size_t Connection::GetConnectionMemoryUsed() const { | ||
size_t total_memory = sizeof(*this); // 包含所有成员变量的静态内存大小 | ||
|
||
total_memory += name_.capacity(); | ||
total_memory += ns_.capacity(); | ||
total_memory += ip_.capacity(); | ||
total_memory += announce_ip_.capacity(); | ||
total_memory += addr_.capacity(); | ||
total_memory += last_cmd_.capacity(); | ||
total_memory += output_buffer_.capacity(); | ||
total_memory += slave_output_buffer_.capacity(); | ||
total_memory += evbuffer_get_length(Output()) + evbuffer_get_length(Input()); | ||
|
||
for (const auto &channel : subscribe_channels_) { | ||
total_memory += channel.capacity(); | ||
} | ||
for (const auto &pattern : subscribe_patterns_) { | ||
total_memory += pattern.capacity(); | ||
} | ||
for (const auto &channel : subscribe_shard_channels_) { | ||
total_memory += channel.capacity(); | ||
} | ||
for (const auto &cmd : multi_cmds_) { | ||
total_memory += cmd.capacity(); | ||
} | ||
|
||
if (saved_current_command_) { | ||
total_memory += saved_current_command_->GetMemoryUsage(); | ||
} | ||
Comment on lines
+568
to
+593
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code seems hard to maintain and also not like a precise estimation of memory usage. I'm wondering if it's really necessary to limit the connection memory usage.. |
||
|
||
return total_memory; | ||
} | ||
|
||
} // namespace redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please dont include chinese comments.
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.
done