PragmaTwice commented on code in PR #2513:
URL: https://github.com/apache/kvrocks/pull/2513#discussion_r1749158237
##########
src/server/redis_connection.cc:
##########
@@ -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();
+ }
Review Comment:
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..
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]