gaffneyc/heroku-buildpack-jemalloc

Allocator not changing on Heroku

Closed this issue · 2 comments

I have setup a fresh rails app on a Heroku to try out the affects of changing the allocator to jemalloc however adding the buildpack and setting the env var does not seem to have any effect.

Here is the buildpack setup:

=== secure-ravine-91290 Buildpack URLs
1. https://github.com/gaffneyc/heroku-buildpack-jemalloc.git
2. heroku/ruby

Here are the ENV vars:

JEMALLOC_ENABLED:         true
LANG:                     en_US.UTF-8
RACK_ENV:                 production
RAILS_ENV:                production
RAILS_LOG_TO_STDOUT:      enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE: ...
DATABASE_URL: ...

The stack is: heroku-18.

I have been checking with puts RbConfig::CONFIG['LIBS'] and this outputs -lpthread -lgmp -ldl -lcrypt -lm. I believe it should be something more like -lpthread -ljemalloc -ldl -lobjc which would indicate that jemalloc is in use.

Do I need to recompile ruby with support for jemalloc or is there something else I might be doing wrong?

There is only one way that I know of to tell that jemalloc is active. Per this comment you should check to see that LD_PRELOAD includes the jemalloc library. There is no linking that occurs, instead you can think of it as jemalloc monkey patching over the malloc API surface.

One quick point if you're trying to see how jemalloc impacts a Rails app. Jemalloc performs best using multithreaded applications (like Puma or Sidekiq) and you may not see an improvement with Unicorn or similar single threaded servers and services.

I also don't expect you to see any major changes to memory with a small or example Rails project. You really need a live application that is serving real requests (and therefore allocating memory frequently) to be able to properly compare algorithms.

@gaffneyc Thanks for all the information!