From 00c672340d53a63ff00a12e87ce3b969f75fe7a0 Mon Sep 17 00:00:00 2001 From: Yongqiang YANG <98214048+dataroaring@users.noreply.github.com> Date: Wed, 28 Sep 2022 15:44:18 +0800 Subject: [PATCH] [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 69d36cfaa3..03f7ca36db 100755 --- a/bin/start_be.sh +++ b/bin/start_be.sh @@ -204,6 +204,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 + ## set hdfs conf export LIBHDFS3_CONF="${DORIS_HOME}/conf/hdfs-site.xml"