How to use jemalloc in Ruby web service?

I read in these forums that a Ruby web service comes installed with the jemalloc package, but as far as I can see it’s not actually loaded.

How can we make sure it’s loaded? I believe the LD_PRELOAD environment variable can be used for this, but I’m not exactly sure how.

1 Like

I think I figured it out. Setting LD_PRELOAD to /usr/lib/x86_64-linux-gnu/libjemalloc.so seems to load jemalloc.

Here’s a way to confirm it in the shell:

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so MALLOC_CONF=stats_print:true ruby -e "exit"

It should print out a bunch of jemalloc stats on exit.

4 Likes

Hey Marc, did you get jemalloc to work finally? I added this LD_PRELOAD variable to my env but it doesnt work. When i run to check if jemalloc is activated in my ruby installtion:

ruby -r rbconfig -e “puts RbConfig::CONFIG[‘MAINLIBS’]”

It doesnt display -ljemalloc in the output.