caipengbo commented on code in PR #2498:
URL: https://github.com/apache/kvrocks/pull/2498#discussion_r1730621616


##########
src/server/worker.cc:
##########
@@ -446,6 +452,13 @@ Status Worker::Reply(int fd, const std::string &reply) {
   auto iter = conns_.find(fd);
   if (iter != conns_.end()) {
     iter->second->SetLastInteraction();
+    if (iter->second->CheckClientReachOBufLimits(reply.size() + 
evbuffer_get_length(iter->second->Output()))) {

Review Comment:
   This reply may become large during generation, such as the `KEYS` command.



##########
src/server/server.cc:
##########
@@ -2115,3 +2122,40 @@ AuthResult Server::AuthenticateUser(const std::string 
&user_password, std::strin
   *ns = kDefaultNamespace;
   return AuthResult::IS_ADMIN;
 }
+
+void Server::evictionClients() {
+  size_t mem = 0;
+  for (const auto &t : worker_threads_) {
+    mem += t->GetWorker()->GetConnectionsMemoryUsed();
+  }
+  if (mem < config_->max_memory_clients) {
+    return;
+  }
+
+  std::vector<redis::Connection *> conns;
+  for (const auto &t : worker_threads_) {
+    auto worker_conns = t->GetWorker()->GetConnections();
+    for (const auto &iter : worker_conns) {
+      conns.push_back(iter.second);

Review Comment:
   The lock will not work here, and these connections may still be released 
when you access them below.
   
   One of my own practices is to `maxmemory-clients/worker`, estimate the 
`maxmemory` of each worker, and then record (update in real time) the memory of 
each connection in each worker, which can be more timely and without locking.



##########
src/config/config_type.h:
##########
@@ -338,3 +338,119 @@ class IntWithUnitField : public ConfigField {
   T max_;
   IntUnit current_unit_ = IntUnit::None;
 };
+
+struct ClientOutputBufferLimitConfig {
+  uint64_t hard_limit_bytes = 0;
+  uint64_t soft_limit_bytes = 0;
+  uint64_t soft_limit_seconds = 0;
+};
+
+constexpr int CLIENT_TYPE_OBUF_COUNT = 3;
+
+class ClientOutputBufferLimitFiled : public ConfigField {

Review Comment:
   field



-- 
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]

Reply via email to