From 728554d08755b86ac3090504d0121adf6de79520 Mon Sep 17 00:00:00 2001 From: fengyubiao Date: Tue, 11 Apr 2023 21:47:02 +0800 Subject: [PATCH] [fix] [cli] Fix Broker crashed by too much memory usage of pulsar tools (#20031) ### Motivation After #15868, we allow `PULSAR_MEM` & `PULSAR_GC` to be overridden in `pulsar_tool_env.sh`. Many users set `-Xms` to `2G` or larger in `PULSAR_MEM`, this will make the tools(such as `pulsar-admin`) cost a lot of memory, and if users execute `pulsar-admin` or another tool on the machine where the Broker is deployed, the current device will not have enough memory to allocate, resulting in a broker crash. ### Modifications When `PULSAR_MEM` is overridden in `pulsar_tool_env.sh`, delete parameter `-Xms` (cherry picked from commit 4f503fd886cd25670b6344defb8feb1ff2a6e816) --- conf/pulsar_tools_env.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/conf/pulsar_tools_env.sh b/conf/pulsar_tools_env.sh index a356dbb9a28df..9d22b73905df3 100755 --- a/conf/pulsar_tools_env.sh +++ b/conf/pulsar_tools_env.sh @@ -42,6 +42,19 @@ # PULSAR_GLOBAL_ZK_CONF= # Extra options to be passed to the jvm +# Discard parameter "-Xms" of $PULSAR_MEM, which tends to be the Broker's minimum memory, to avoid using too much +# memory by tools. +if [ -n "$PULSAR_MEM" ]; then + PULSAR_MEM_ARR=("${PULSAR_MEM}") + PULSAR_MEM_REWRITE="" + for i in ${PULSAR_MEM_ARR} + do + if [ "${i:0:4}" != "-Xms" ]; then + PULSAR_MEM_REWRITE="$PULSAR_MEM_REWRITE $i"; + fi + done + PULSAR_MEM=${PULSAR_MEM_REWRITE} +fi PULSAR_MEM=${PULSAR_MEM:-"-Xmx128m -XX:MaxDirectMemorySize=128m"} # Garbage collection options