【问题标题】:Cannot install new versions of jemalloc gem (to work on heroku)无法安装新版本的 jemalloc gem(在 heroku 上工作)
【发布时间】:2019-09-11 11:01:54
【问题描述】:

一段时间以来,我的 Ruby on Rails 应用程序 (ruby 2.3.3, rails 4.2.10) 一直存在严重的内存问题,我想尝试 gem jemalloc 以及 buildpack heroku-buildpack-jemalloc,因为它似乎对其他人有所帮助一大堆。

如果我只是添加:

gem 'jemalloc' 

在我的 Gemfile 中运行 bundle install 它可以工作,但我得到的版本是 1.0.1,它是 ruby​​gems.org 上的最新版本。在(成功)在 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>' 

考虑到 ruby​​gems.org 上的最新版本 1.0.1(我从那里获得所有其他 gem)是从 2015 年开始的,据我所知 gem (https://github.com/jemalloc/jemalloc) 是 5.1.0 (?)现在似乎 ruby​​gems.org 由于某种原因没有最新版本。为什么,我想知道?

我假设这是我对 heroku 的推动不起作用的原因,因为 buildpack 似乎至少需要 jemalloc 的 3.x 版本才能工作,而不是我在 ruby​​gems.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。

【问题讨论】:

    标签: ruby-on-rails ruby heroku jemalloc


    【解决方案1】:

    您引用的链接不是 gem 的 repo,因此您收到以下消息是有道理的:“找不到 gem 'jemalloc'”。

    我认为你不需要宝石。尝试使用此heroku buildpack。确保设置 heroku 环境变量:JEMALLOC_ENABLED = true and JEMALLOC_VERSION = 5.2.0

    【讨论】:

    • 您引用的 heroku buildpack 已弃用,但有另一个链接。我不完全确定为什么 buildpack 突然开始为我工作,因为我最终同时做了几件事,但我很惊讶听到我的参考不是宝石。谢谢。我相信您的回答也会引导其他人走上正确的道路,因此我将其标记为答案。对于其他追逐记忆的人:另一件对我记忆有极大帮助的事情是将 MALLOC_ARENA_MAX=2 放入我的 heroku 配置中。
    • 很高兴这对您有所帮助。我更新了链接以指向较新的 heroku buildpack。
    猜你喜欢
    • 1970-01-01
    • 2023-03-02
    • 1970-01-01
    • 2012-03-26
    • 2019-12-16
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多