This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 49e90d15e [CLI] Set rpc_max_message_size to accommodate huge response 
payloads
49e90d15e is described below

commit 49e90d15eaaa38dcee2752d06e4f44d1f231fd94
Author: Ashwani Raina <[email protected]>
AuthorDate: Wed Oct 4 16:23:03 2023 +0530

    [CLI] Set rpc_max_message_size to accommodate huge response payloads
    
    It has been observed that for certain Kudu CLI commands response
    payload size is too big to fit in the current default RPC message size
    limit of 50MiB. This patch adds logic to set the value of RPC message
    max size for Kudu CLI based on maximum available memory or maximum
    possible RPC message size limit of 2GiB. This would help accommodate
    that extra heavy response payload.
    
    Along with increasing default value of rpc_max_message_size, default
    value of tablet_transaction_memory_limit_mb is also set to at least same
    value as rpc_max_message_size to pass the group validation check.
    
    This change of default flag values is only applicable to Kudu CLI tool.
    
    Change-Id: Ic27b494bc1fde46c2a095c7291fc840a98429068
    Reviewed-on: http://gerrit.cloudera.org:8080/20535
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <[email protected]>
---
 src/kudu/tools/tool_main.cc     | 36 ++++++++++++++++++++++++++++++++++++
 src/kudu/util/process_memory.cc | 16 ++++++++++++----
 src/kudu/util/process_memory.h  |  3 +++
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/src/kudu/tools/tool_main.cc b/src/kudu/tools/tool_main.cc
index 755cd16fa..dc9055efa 100644
--- a/src/kudu/tools/tool_main.cc
+++ b/src/kudu/tools/tool_main.cc
@@ -16,9 +16,11 @@
 // under the License.
 
 #include <algorithm>
+#include <cstdint>
 #include <cstdlib>
 #include <deque>
 #include <iostream>
+#include <limits>
 #include <memory>
 #include <optional>
 #include <string>
@@ -34,6 +36,7 @@
 #include "kudu/tools/tool_action.h"
 #include "kudu/util/flags.h"
 #include "kudu/util/path_util.h"
+#include "kudu/util/process_memory.h"
 #include "kudu/util/status.h"
 
 DECLARE_bool(help);
@@ -51,6 +54,7 @@ using std::string;
 using std::unique_ptr;
 using std::unordered_map;
 using std::vector;
+using std::to_string;
 using strings::Substitute;
 
 namespace kudu {
@@ -248,6 +252,19 @@ static bool ParseCommandLineFlags(const char* prog_name) {
   return show_help;
 }
 
+// Return minimum of the two - Maximum memory available and Maximum RPC size
+// allowed. The return value is in bytes.
+static int64_t GetRPCMaxMessageSizeBytes() {
+  int64_t rpc_max_message_size = std::numeric_limits<int32_t>::max();
+
+  // Current consumption by this process is of the order of a few hundred KBs
+  // which is negligible as compared to HardLimit which is usually in GBs, so
+  // it is ok to ignore current consumption when computing maximum memory
+  // available.
+  int64_t max_memory_available = kudu::process_memory::MaxMemoryAvailable();
+  return std::min(rpc_max_message_size, max_memory_available);
+}
+
 int main(int argc, char** argv) {
   // Disable redaction by default so that user data printed to the console 
will be shown
   // in full.
@@ -258,6 +275,25 @@ int main(int argc, char** argv) {
   CHECK_NE("",  google::SetCommandLineOptionWithMode(
       "logtostderr", "true", google::SET_FLAGS_DEFAULT));
 
+  // Set default RPC max message size to minimum of the two i.e. max memory
+  // available and maximum size allowed for an RPC message. This is to
+  // accommodate huge response payloads.
+  const int64_t kDefaultRPCMaxMessageSizeBytes = GetRPCMaxMessageSizeBytes();
+  CHECK_NE("",  google::SetCommandLineOptionWithMode(
+      "rpc_max_message_size",
+      to_string(kDefaultRPCMaxMessageSizeBytes).c_str(),
+      google::SET_FLAGS_DEFAULT));
+
+  // Set default maximum txn memory limit to at least same value as default
+  // rpc_max_message_size (set above) to pass 'group validation check' for
+  // tablet_transaction_memory_limit_mb and rpc_max_message_size.
+  const int64_t kDefaultTabletTxnMemLimitMB =
+    (kDefaultRPCMaxMessageSizeBytes + ((1024 * 1024) - 1)) / (1024 * 1024);
+  CHECK_NE("",  google::SetCommandLineOptionWithMode(
+      "tablet_transaction_memory_limit_mb",
+      to_string(kDefaultTabletTxnMemLimitMB).c_str(),
+      google::SET_FLAGS_DEFAULT));
+
   // Hide the regular gflags help unless --helpfull is used.
   //
   // Inspired by 
https://github.com/gflags/gflags/issues/43#issuecomment-168280647.
diff --git a/src/kudu/util/process_memory.cc b/src/kudu/util/process_memory.cc
index 68bf74830..a100e4a61 100644
--- a/src/kudu/util/process_memory.cc
+++ b/src/kudu/util/process_memory.cc
@@ -18,6 +18,7 @@
 #include <cstddef>
 #include <memory>
 #include <ostream>
+#include <type_traits>
 
 #include <gflags/gflags.h>
 #include <glog/logging.h>
@@ -169,10 +170,7 @@ void DoInitLimits() {
   int64_t limit = FLAGS_memory_limit_hard_bytes;
   if (limit == 0) {
     // If no limit is provided, we'll use 80% of system RAM.
-    int64_t total_ram;
-    CHECK_OK(Env::Default()->GetTotalRAMBytes(&total_ram));
-    limit = total_ram * 4;
-    limit /= 5;
+    limit = MaxMemoryAvailable();
   }
   g_hard_limit = limit;
   g_soft_limit = FLAGS_memory_limit_soft_percentage * g_hard_limit / 100;
@@ -215,6 +213,16 @@ int64_t CurrentConsumption() {
 #endif
 }
 
+int64_t MaxMemoryAvailable() {
+  int64_t total_ram;
+  CHECK_OK(Env::Default()->GetTotalRAMBytes(&total_ram));
+  // We will use 80% of system RAM to align with default hard limit.
+  total_ram = total_ram * 4;
+  total_ram /= 5;
+
+  return total_ram;
+}
+
 int64_t HardLimit() {
   InitLimits();
   return g_hard_limit;
diff --git a/src/kudu/util/process_memory.h b/src/kudu/util/process_memory.h
index fffe36339..048b8186b 100644
--- a/src/kudu/util/process_memory.h
+++ b/src/kudu/util/process_memory.h
@@ -41,6 +41,9 @@ void MaybeGCAfterRelease(int64_t released_bytes);
 // Return the total current memory consumption of the process.
 int64_t CurrentConsumption();
 
+// Return the maximum memory available for consumption.
+int64_t MaxMemoryAvailable();
+
 // Return the configured hard limit for the process.
 int64_t HardLimit();
 

Reply via email to