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.

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.

2 Likes