docker: switch Ruby memory allocator to Jemalloc.
Switch the Ruby memory allocator from Glibc malloc to Jemalloc. Jemalloc supposedly uses less memory than Glibc malloc because it's better at handling memory fragmentation. It also has detailed internal statistics to help monitor allocator behavior. We use the LD_PRELOAD method of loading Jemalloc instead of building it into Ruby so that we can switch allocators at runtime.
This commit is contained in:
@@ -3,10 +3,6 @@ FROM ubuntu:21.04 AS base
|
||||
WORKDIR /danbooru
|
||||
ENV PATH="/root/.asdf/bin:/root/.asdf/shims:$PATH:/usr/lib/postgresql/14/bin"
|
||||
|
||||
# Reduces memory usage at the cost of higher thread contention.
|
||||
# https://bugs.ruby-lang.org/issues/14718
|
||||
ENV MALLOC_ARENA_MAX=2
|
||||
|
||||
COPY config/docker/build-base-image.sh .
|
||||
|
||||
RUN \
|
||||
@@ -64,6 +60,8 @@ RUN \
|
||||
|
||||
FROM base as production
|
||||
|
||||
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
|
||||
|
||||
COPY --from=development /root /root
|
||||
COPY --from=development /danbooru /danbooru
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ DANBOORU_RUNTIME_DEPS="
|
||||
ca-certificates mkvtoolnix rclone libpq5 openssl libgmpxx4ldbl
|
||||
zlib1g libfftw3-3 libwebp6 libwebpmux3 libwebpdemux2 liborc-0.4.0 liblcms2-2
|
||||
libpng16-16 libexpat1 libglib2.0 libgif7 libexif12 libheif1 libvpx6
|
||||
libseccomp2 libseccomp-dev
|
||||
libseccomp2 libseccomp-dev libjemalloc2
|
||||
"
|
||||
COMMON_RUNTIME_DEPS="
|
||||
$DANBOORU_RUNTIME_DEPS $EXIFTOOL_RUNTIME_DEPS tini busybox less ncdu
|
||||
|
||||
Reference in New Issue
Block a user