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

yiguolei pushed a commit to branch branch-1.1-lts
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-1.1-lts by this push:
     new 675166711a [improvement](memory) set TCMALLOC_HEAP_LIMIT_MB to control 
memory consumption of tcmalloc (#12981)
675166711a is described below

commit 675166711a84e060365c822260866d89f0d11a01
Author: Yongqiang YANG <98214048+dataroar...@users.noreply.github.com>
AuthorDate: Wed Sep 28 15:44:18 2022 +0800

    [improvement](memory) set TCMALLOC_HEAP_LIMIT_MB to control memory 
consumption of tcmalloc (#12981)
---
 bin/start_be.sh | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/bin/start_be.sh b/bin/start_be.sh
index ca9bdd483f..903f8c5405 100755
--- a/bin/start_be.sh
+++ b/bin/start_be.sh
@@ -117,6 +117,39 @@ fi
 export 
ASAN_OPTIONS=symbolize=1:abort_on_error=1:disable_coredump=0:unmap_shadow_on_exit=1
 export UBSAN_OPTIONS=print_stacktrace=1
 
+## set TCMALLOC_HEAP_LIMIT_MB to limit memory used by tcmalloc
+set_tcmalloc_heap_limit() {
+    total_mem_mb=$(free -m | grep Mem | awk '{print $2}')
+    mem_limit_str=$(grep ^mem_limit "${DORIS_HOME}"/conf/be.conf)
+    digits_unit=${mem_limit_str##*=}
+    digits_unit="${digits_unit#"${digits_unit%%[![:space:]]*}"}"
+    digits_unit="${digits_unit%"${digits_unit##*[![:space:]]}"}"
+    digits=${digits_unit%%[^[:digit:]]*}
+    unit=${digits_unit##*[[:digit:] ]}
+
+    mem_limit_mb=0
+    case ${unit} in
+    t | T) mem_limit_mb=$((digits * 1024 * 1024)) ;;
+    g | G) mem_limit_mb=$((digits * 1024)) ;;
+    m | M) mem_limit_mb=$((digits)) ;;
+    k | K) mem_limit_mb=$((digits / 1024)) ;;
+    %) mem_limit_mb=$((total_mem_mb * digits / 100)) ;;
+    *) mem_limit_mb=$((digits / 1024 / 1024 / 1024)) ;;
+    esac
+
+    if [[ "${mem_limit_mb}" -eq 0 ]]; then
+        mem_limit_mb=$((total_mem_mb * 80 / 100))
+    fi
+
+    if [[ "${mem_limit_mb}" -gt "${total_mem_mb}" ]]; then
+        echo "mem_limit is larger than whole memory of the server. 
${mem_limit_mb} > ${total_mem_mb}."
+        return 1
+    fi
+    export TCMALLOC_HEAP_LIMIT_MB=${mem_limit_mb}
+}
+
+set_tcmalloc_heap_limit || exit 1
+
 if [ ${RUN_DAEMON} -eq 1 ]; then
     nohup $LIMIT ${DORIS_HOME}/lib/doris_be "$@" >> $LOG_DIR/be.out 2>&1 < 
/dev/null &
 else


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to