Skip to content

Instantly share code, notes, and snippets.

@doolin
Forked from jjb/file.md
Created March 13, 2023 12:00
Show Gist options
  • Save doolin/e26040bb96cbeff67b7bbacc45d83679 to your computer and use it in GitHub Desktop.
Save doolin/e26040bb96cbeff67b7bbacc45d83679 to your computer and use it in GitHub Desktop.
Using Jemalloc 5 with Ruby.md

This is a very quick gist I'm throwing together to get this info and discussion onto google in one place.

For years, people have been using jemalloc with ruby. There are various benchmarks and discussions. Some people say Jemalloc 5 doesn't work as well as Jemalloc 3.

Then, one day, hope appeared on the horizon. Someone offered a config for Jemalloc 5.

The recipe would be something like this (shown with official docker ruby image). I didn't try this yet, don't know if it will build!

FROM ruby:3.1.2-bullseye

RUN apt-get update ; \
    apt-get install -y --no-install-recommends libjemalloc2 ;

ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2

# tradeoff between memory and performance
ENV MALLOC_CONF='narenas:2,background_thread:true,thp:never,dirty_decay_ms:1000,muzzy_decay_ms:0'

# more heavily memory-optimized, like jemalloc 3.6
# ENV MALLOC_CONF='narenas:2,background_thread:true,thp:never,dirty_decay_ms:0,muzzy_decay_ms:0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment