After reading several articles about how badly it manages ruby memory, I wanted to do a test on a small application that I run with Ruby on Rails and Sidekiq to see if there are improvements in the performance of my application on a t2.micro instance (only 1Gb RAM).

So I got down to work and followed the simple steps to move from a Ruby that uses glibc by default to Ruby with jemalloc

First, update and install jemalloc (instructions for Debian/Ubuntu)

$ sudo apt update
$ sudo apt install libjemalloc-dev

Then, reinstall Ruby with jemalloc as option. On my server, I have Ruby 2.5.1 installed, so the command I executed was the following (works with RVM too):

$ RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.5.1 

To ensure that your Ruby uses jemalloc, run the following command:

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

-lpthread -ljemalloc -ldl -lcrypt -lm 

And the results so far…

Some data from grafana

I expected the RAM used to decrease, but instead, the swap memory decreased

meme

More information

This awesome post

More detailed tutorial

Another tutorial

This post is also available on DEV.