SBaronda.com a little place I like to call home.


Jemalloc In Ruby with ruby-build

Mar. 14, 2015

I've been tring to get into the performance groove lately and understand the memory allocations that occur in our Ruby applications. This has lead to look into using jemalloc to reduce fragmentation. There has been many discussions on the positives of using jemalloc over glibc malloc, one of which is Redis

If you've already installed Ruby via ruby-build you can see if you are using jemalloc or not:

ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"

Look for the -ljemlaloc line, if that is present then you have Ruby compiled with jemalloc, if not then you do not.

To get jemalloc setup with Ruby via ruby-build is pretty simple. Make sure you have jemalloc installed on your system and run:

RUBY_CONFIGURE_OPTS="--with-jemalloc" rbenv install 2.2.1

After it finishes compiling you can then run the below snippet to check if it worked or not:

rbenv shell 2.2.1
ruby -r rbconfig -e "puts RbConfig::CONFIG['LIBS']"

Look for the -ljemlaloc line, if that is present then you have Ruby compiled with jemalloc, if not then you do not.

Now you can enjoy reduced memory fragmentation.


comments powered by Disqus