gaffneyc/heroku-buildpack-jemalloc

Issue with LD_PRELOAD

Closed this issue · 5 comments

Thanks for Maintaining this buildpack
I got a question, this variable LD_PRELOAD, being set here

export LD_PRELOAD="/app/vendor/jemalloc/lib/libjemalloc.so $LD_PRELOAD"

adds an extra space at the end of the file name, so when I check File.exists?( ENV['LD_PRELOAD'] ), it fails
However, when I check File.exists?( ENV['LD_PRELOAD'].strip ), it works
checking: ENV['LD_PRELOAD']
=> "/app/vendor/jemalloc/lib/libjemalloc.so "

so I was wondering, why is it like that?, and should it be conditioned if $LD_PRELOAD doesn't exist to be the string without this extra space?

also, might this affect Jemalloc being used in Ruby 2.4.10/Rails 4.2.8/Heroku 18?

I only used the variable JEMALLOC_ENABLED as true, and the buildpack was: https://github.com/gaffneyc/heroku-buildpack-jemalloc.git, which I assume pulls the latest

finally, is there anyway to verify that Jemalloc is working as it should?
I removed JEMALLOC_ENABLED, consiquently LD_PRELOAD was removed, and I added jemalloc.sh before the bundle call in my Procfile for both puma and sidekiq worker

A trailing spacing in LD_PRELOAD shouldn't cause jemalloc not to be loaded. Because of how jemalloc is loaded (by essentially monkey patching malloc calls) there isn't a good way to test that it's loaded from a live app.

The best way to check if it's working can be found here: #5 (comment)

@gaffneyc Thanks for you quick reply!
I tried MALLOC_CONF=stats_print:true ruby -e "exit", it exited immediately, I probably have something wrong with my config

that's what I've in proc file
web: jemalloc.sh bundle exec puma -p ${PORT:-3000} -e ${RACK_ENV:-development}
sidekiq_worker: jemalloc.sh bundle exec sidekiq -C config/sidekiq.yml

and no related variables at all in heroku configs
except for JEMALLOC_VERSION = 5.2.1
image

any recommendations/suspects?
Thanks again

Try starting a console on Heroku

heroku run bash -a [your app]

Then run this script on the launched dyno

echo $LD_PRELOAD
echo $JEMALLOC_ENABLED
MALLOC_CONF=stats_print:true ruby -e "exit"

It should print out a bunch of stats then exit immediately. If it exits without output then you know that jemalloc isn't being loaded for some reason.

It also looks like you're using jemalloc.sh in your Procfile which should set up jemalloc even if JEMALLOC_ENABLED is not set. If you don't see output from MALLOC_CONF=stats_print:true ruby -e "exit" then you should try MALLOC_CONF=stats_print:true jemalloc.sh ruby -e "exit" since that is equivalent to what is in your Procfile

thanks @gaffneyc
I tried this, MALLOC_CONF=stats_print:true jemalloc.sh ruby -e "exit" and it worked for the dynos I had using jemalloc.sh

I want to remove he jemalloc.sh, and use the env vars
should I set JEMALLOC_ENABLED to true
and LD_PRELOAD to "/app/vendor/jemalloc/lib/libjemalloc.so"

You should only set JEMALLOC_ENABLED=true since it automates setting LD_PRELOAD when the dyno starts. It may work if you set both but I don't know the behavior when a library is included multiple times in LD_PRELOAD.