I’d prefer we stick with the official Ruby images as well. Using jemalloc with Ruby isn’t all that complicated:
RUN apt-get install libjemalloc2
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
You can also set MALLOC_CONF
to tune the performance/memory tradeoff. I’ve had good results with the line:
ENV MALLOC_CONF=dirty_decay_ms:1000,narenas:2,background_thread:true
For comparison, the Fullstaq Ruby images are compiled with an outdated jemalloc version (3.6.0, released in 2014) which lacked the decay-based purging feature introduced in version 4.1, which is equivalent to dirty_decay_ms:0,muzzy_decay_ms:0
. (muzzy_decay_ms
defaults to 0 in recent versions so doesn’t need to be specified.) However, setting a small, non-zero decay gives significant performance gains at a very slight cost in memory utilization in my experience. Using the background thread further improves performance slightly, and limiting arenas is also a performance gain for Ruby (something Heroku has extensively tested in the context of glibc malloc).