I have been having serious memory issues on my Ruby on Rails application (ruby 2.3.3, rails 4.2.10
) for a while now and I want to try the gem jemalloc
as well as the buildpack heroku-buildpack-jemalloc
as it seems to have helped others a whole lot.
If I just add:
gem 'jemalloc'
in my Gemfile and run bundle install
it works but I get the version 1.0.1
which is the latest version on rubygems.org. After (successfully) installing the buildpack on Heroku I try to upload my app but it fails with
remote: !
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! rake aborted!
remote: ! LoadError: /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/jemalloc-1.0.1/lib/jemalloc.so: undefined symbol: Init_jemalloc - /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/jemalloc-1.0.1/lib/jemalloc.so
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:82:in `require'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:82:in `block (2 levels) in require'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:77:in `each'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:77:in `block in require'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:66:in `each'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/runtime.rb:66:in `require'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler.rb:108:in `require'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/config/application.rb:7:in `<top (required)>'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/Rakefile:4:in `require'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/Rakefile:4:in `<top (required)>'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load_rakefile'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:703:in `raw_load_rakefile'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:104:in `block in load_rakefile'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:103:in `load_rakefile'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:82:in `block in run'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/lib/rake/application.rb:80:in `run'
remote: ! /tmp/build_c49fb2d1484e39d9a1e11c3b732d5119/vendor/bundle/ruby/2.3.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
remote: ! vendor/bundle/bin/rake:17:in `load'
remote: ! vendor/bundle/bin/rake:17:in `<main>'
Considering the latest version, 1.0.1, on rubygems.org (from where I get all my other gems) is from 2015 and as far as I understand the gem (https://github.com/jemalloc/jemalloc) is at 5.1.0 (?) now it seems like rubygems.org doesn't have the latest version for some reason. Why, I wonder?
I am assuming this is the reason my push to heroku won't work as the buildpack seems to need at least version 3.x of jemalloc to work and not the ancient one I can find on rubygems.org
So, I tried to download the gem directly from github using:
gem 'jemalloc' , :git => "https://github.com/jemalloc/jemalloc.git"
and then run bundle install
. This results in:
Fetching https://github.com/jemalloc/jemalloc.git
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Could not find gem 'jemalloc' in https://github.com/jemalloc/jemalloc.git (at master@ea6b3e9).
The source does not contain any versions of 'jemalloc'
to my surprise. I cannot understand why this doesn't work.
So, I am left with a version 1.0.1 that (I assume) won't work with the buildpack I need on Heroku.
How do I bundle a newer version of jemalloc to make this work? What am I missing?
I also found information about jemalloc being included into ruby 2.2.0, does that mean it may already in use in my application? I have made no configurations in my Rails app about that.
Lastly, I am only interested in using jemalloc in my live production app on Heroku, and not on my development version locally on my laptop.
The link you reference is not a repo for a gem, so it makes sense that you are getting the message: "Could not find gem 'jemalloc'".
I don't think you need a gem. Try using this heroku buildpack. Make sure to set the heroku env variables: JEMALLOC_ENABLED = true and JEMALLOC_VERSION = 5.2.0