为什么资产:在Heroku上预编译速度如此之慢?

时间:2013-01-21 22:31:08

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

我的部署设置是使用Heroku预编译资产。我希望他们预编译,以便我可以将它们发送到CDN(通过asset_sync),我希望在Heroku上完成,所以我的回购中没有任何编译资产。我使用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上的任何聪明人都有可能的解决方案吗?

1 个答案:

答案 0 :(得分:4)

解决方案是使用tell 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