一段时间以来,我的 Ruby on Rails 应用程序 ( ruby 2.3.3, rails 4.2.10
) 一直存在严重的内存问题,我想尝试 gemjemalloc
以及 buildpack heroku-buildpack-jemalloc
,因为它似乎对其他人有很大帮助。
如果我只是添加:
gem 'jemalloc'
在我的 Gemfile 中运行bundle install
它,但我得到的是 rubygems.org1.0.1
上的最新版本。在(成功)在 Heroku 上安装 buildpack 之后,我尝试上传我的应用程序,但它失败了
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>'
考虑到 rubygems.org 上的最新版本 1.0.1(我从那里获得所有其他宝石)是从 2015 年开始的,据我所知宝石(https://github.com/jemalloc/jemalloc)是 5.1 .0 (?) 现在似乎 rubygems.org 由于某种原因没有最新版本。为什么,我想知道?
我假设这是我对 heroku 的推动不起作用的原因,因为 buildpack 似乎至少需要 jemalloc 的 3.x 版本才能工作,而不是我可以在 rubygems.org 上找到的旧版本
因此,我尝试使用以下命令直接从 github 下载 gem:
gem 'jemalloc' , :git => "https://github.com/jemalloc/jemalloc.git"
然后运行bundle install
。这导致:
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'
出乎我的意料。我不明白为什么这不起作用。
所以,我只剩下一个 1.0.1 版本(我假设)它不能与我在 Heroku 上需要的 buildpack 一起工作。
如何捆绑较新版本的 jemalloc 以使其正常工作?我错过了什么?
我还发现了有关 jemalloc 包含在 ruby 2.2.0 中的信息,这是否意味着它可能已经在我的应用程序中使用?我没有在我的 Rails 应用程序中对此进行任何配置。
最后,我只对在 Heroku 上的实时生产应用程序中使用 jemalloc 感兴趣,而不是在笔记本电脑上的本地开发版本中使用 jemalloc。