【问题标题】:Why is assets:precompile so slow on Heroku?为什么 assets:precompile 在 Heroku 上这么慢?
【发布时间】:2013-01-21 22:31:07
【问题描述】:

我的部署设置是让 Heroku 预编译资产。我希望它们被预编译,这样我就可以将它们发送到 CDN(通过asset_sync),我希望在 Heroku 上完成,所以我的 repo 中没有任何已编译的资产。我使用Heroku's guide 进行了设置,效果很好。我添加了turbo-sprockets-rails3 以提高速度。它一直运行良好,然后停止了;我不知道为什么。

现在,当我部署(没有public/assets)时,assets:precompile Rake 任务在 Heroku 上超时。为了了解它真正需要多长时间,我进入了一个 shell (heroku run bash):

~ $ time bundle exec rake assets:precompile
AssetSync: YAML file found /app/config/asset_sync.yml settings will be merged into the configuration
AssetSync: Syncing.
Using: Directory Search of /app/public/assets
AssetSync: Done.

real    19m29.575s
user    17m43.690s
sys 0m28.480s

二十分钟!但是当我在本地(2011 iMac)运行它时,只需几分钟:

$ env RAILS_ENV=production time bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
~/.rbenv/versions/1.9.3-p327-perf/bin/ruby ~/.rbenv/versions/1.9.3-p327-perf/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Invoke assets:cache:clean (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
AssetSync: YAML file found ~/Code/Ruby/myproject-rails/config/asset_sync.yml settings will be merged into the configuration
** Execute assets:cache:clean
** Execute assets:precompile:all
AssetSync: Syncing.
Using: Directory Search of ~/Code/Ruby/myproject-rails/public/assets
Uploading: assets/application-3a6de939348195e9610f1321df27837a.js
Uploading: assets/application-3a6de939348195e9610f1321df27837a.js.gz
Uploading: assets/jquery.min-959a5819c76e1508f5a8655c289c0de8.map
Uploading: assets/jquery.min.map
Uploading: assets/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js
Uploading: assets/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js.gz
AssetSync: Done.
      179.92 real        19.29 user         3.98 sys

我一个多星期前写了 Heroku 支持,几天后他们说他们会把它升级到他们的 Ruby 构建团队,但我仍然没有听到任何消息。 Stack Overflow 上的聪明人有没有可能的解决方案?

【问题讨论】:

    标签: heroku ruby-on-rails-3.2 asset-pipeline


    【解决方案1】:

    解决方案是告诉 Heroku 使用 Ruby 1.9.3,就像我的本地机器一样。显然 1.9.3 在资产编译方面比 Heroku 默认使用的 1.9.2 快得多。

    要修复它,请确保您的 Gemfile 启动:

    source "https://rubygems.org"
    ruby "1.9.3"
    # ...
    

    更多信息请访问Heroku docs on Ruby versions

    【讨论】:

    • 我的 assets:precompile 在我的本地机器上使用 1.9.3 从 19 分钟缩短到不到 1 分钟。格拉西亚斯。
    猜你喜欢
    • 2016-04-19
    • 2010-10-29
    • 2010-11-12
    • 2011-12-06
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    相关资源
    最近更新 更多