Skip to content

Commit 8b789ee

Browse files
authored
[FLINK-35192] support jemalloc in image
1 parent eb19133 commit 8b789ee

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ ARG SKIP_OS_UPDATE=true
6464
RUN if [ "$SKIP_OS_UPDATE" = "false" ]; then apt-get update; fi
6565
RUN if [ "$SKIP_OS_UPDATE" = "false" ]; then apt-get upgrade -y; fi
6666

67+
ARG DISABLE_JEMALLOC=false
68+
# Install jemalloc
69+
RUN if [ "$DISABLE_JEMALLOC" = "false" ]; then \
70+
apt-get update; \
71+
apt-get -y install libjemalloc-dev; \
72+
rm -rf /var/lib/apt/lists/*; \
73+
fi
74+
6775
USER flink
6876
ENTRYPOINT ["/docker-entrypoint.sh"]
6977
CMD ["help"]

docker-entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ args=("$@")
2222

2323
cd /flink-kubernetes-operator || exit
2424

25+
maybe_enable_jemalloc() {
26+
if [ "${DISABLE_JEMALLOC:-false}" = "false" ]; then
27+
JEMALLOC_PATH="/usr/lib/$(uname -m)-linux-gnu/libjemalloc.so"
28+
JEMALLOC_FALLBACK="/usr/lib/x86_64-linux-gnu/libjemalloc.so"
29+
if [ -f "$JEMALLOC_PATH" ]; then
30+
export LD_PRELOAD=$LD_PRELOAD:$JEMALLOC_PATH
31+
elif [ -f "$JEMALLOC_FALLBACK" ]; then
32+
export LD_PRELOAD=$LD_PRELOAD:$JEMALLOC_FALLBACK
33+
else
34+
if [ "$JEMALLOC_PATH" = "$JEMALLOC_FALLBACK" ]; then
35+
MSG_PATH=$JEMALLOC_PATH
36+
else
37+
MSG_PATH="$JEMALLOC_PATH and $JEMALLOC_FALLBACK"
38+
fi
39+
echo "WARNING: attempted to load jemalloc from $MSG_PATH but the library couldn't be found. glibc will be used instead."
40+
fi
41+
fi
42+
}
43+
44+
maybe_enable_jemalloc
45+
2546
if [ "$1" = "help" ]; then
2647
printf "Usage: $(basename "$0") (operator|webhook)\n"
2748
printf " Or $(basename "$0") help\n\n"

0 commit comments

Comments
 (0)