Ruby + jemalloc: Results for updown.io

Adrien Rey-Jarthon
2 min readMar 31, 2017

--

I recently read this great article about compiling ruby with jemalloc for slightly better performance and smaller memory usage and it got me intrigued. I mean I already knew jemalloc, but I though this kind of optimization (swapping allocation library) was reserved for some very specific use-cases and that the gain would be minimal for a standard Rails app like mine.

But Clément is talking about ~30% memory usage decrease which seems HUGE to me for such an easy change so I tried to look for other benchmarks and comparisons online but couldn't find many (if you know some please let me know).

I already noticed some high memory usage on updown.io's background processes (monitoring daemon and sidekiq workers) which I attributed to the nokogiri library after I measured that it was the one increasing memory so much (and leaking a little bit). I studied alternatives like oga for HTML parsing but couldn't make the switch yet due to string encoding issues.

So after seeing this I though: "why not try jemalloc, see if it can improve the situation, and share my numbers?". Well here there are:

Daemon: -30%
Sidekiq: -45%

The numbers here are the average memory usages measured on 3 servers with jemalloc and 3 servers without (all 6 identically specced), 24h after process start.

Setup

The setup was pretty easy in my case as I was using rbenv, all I had to do was install jemalloc:

$ sudo apt-get install libjemalloc-dev

And reinstall ruby with jemalloc:

$ RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.3.0

Check out the original post for more ways to compile ruby with jemalloc.

--

--

Adrien Rey-Jarthon

I'm a software engineer, founder of http://updown.io. Working mostly with Ruby, Rails & MongoDB.