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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user