为什么资产:在Heroku上预编译太慢? [英] Why is assets:precompile so slow on Heroku?

查看:138
本文介绍了为什么资产:在Heroku上预编译太慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的部署设置是Heroku预编译资产。我希望它们能够预编译,因此我可以将它们发送到CDN(通过 asset_sync ),我希望在Heroku上完成所以我的回购没有任何编译资产。我使用进行设置,这一直很好。我增加了 turbo-sprockets-rails3 ,以提高速度。它一切正常,然后停下来;我不知道为什么。



现在,当我部署(不包含 public / assets )时, assets:precompile Heroku的Rake任务超时。为了看看它真的需要多长时间,我进入了一个shell( heroku run bash ):

 〜$ time bundle exec rake资产:预编译
AssetSync:找到YAML文件/app/config/asset_sync.yml设置将合并到配置
AssetSync:Syncing。
使用:/ app / public / assets的目录搜索
AssetSync:完成。

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

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

  $ env RAILS_ENV =生产时间bundle exec rake资产:预编译 - 跟踪
**调用资产:预编译(first_time)
**执行资源:预编译
〜/ .rbenv / versions / 1.9.3-p327-perf / bin / ruby​​〜/ .rbenv / versions / 1.9.3-p327-perf / bin / rake资产:预编译:所有RAILS_ENV =生产RAILS_GROUPS = assets --trace
**调用资产:预编译:all(first_time)
**调用资产:cache:clean(first_time)
**调用资产:environment(first_time)
**执行资产:environment
AssetSync:找到YAML文件〜/代码/ Ruby / myproject-rails / config / asset_sync.yml设置将被合并到配置中
**执行资产:cache:clean
**执行资产:预编译:全部
AssetSync:同步。
使用:目录搜索〜/ code / Ruby / myproject-rails / public / assets
上传:assets / application-3a6de939348195e9610f1321df27837a.js
上传:assets / application-3a6de939348195e9610f1321df27837a.js.gz
上传:assets / jquery.min-959a5819c76e1508f5a8655c289c0de8.map
上传:assets / jquery.min.map
上传:assets / rails_admin / rails_admin-76cfbf31a605916a55eee29464ca3e6d.js
上传资源/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js.gz
AssetSync:完成。
179.92真实19.29用户3.98 sys

我在一周前编写了Heroku支持,他们说他们会把它升级到他们的Ruby buildback团队,但我仍然没有听到任何声音。做Stack Overflow上的任何聪明人都有可能的解决方案吗?解决方案

解决方案是使用tell Heroku来使用Ruby 1.9。 3,像我的本地机器。显然,资产编译时1.9.3比Heroku默认的1.9.2快得多。



为了解决这个问题,确保你的 Gemfile

code> starts:

 来源https://rubygems.org
ruby​​1.9.3
#...

更多 Heroku docs on Ruby versions


My deployment set up is to have Heroku precompile assets. I want them precompiled so I can send them to a CDN (via asset_sync) and I want that done on Heroku so I don't have any compiled assets in my repo. I set that up using Heroku's guide and that had been working great. I added turbo-sprockets-rails3 for a speed boost. It had all been working fine and then stopped; I can't figure out why.

Now when I deploy (without public/assets) the assets:precompile Rake task times out on Heroku. To see how long it's really taking, I went into a 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

Twenty minutes! But when I run it locally (2011 iMac), it's only only a few minutes:

$ 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

I wrote Heroku support over a week ago and after some days they said they'd escalate it to their Ruby buildback team, but I still haven't heard anything. Do any of the smart people on Stack Overflow have possible solutions?

解决方案

The solution was to use tell Heroku to use Ruby 1.9.3, like my local machine. Apparently 1.9.3 is much faster at assets compilation than 1.9.2 which Heroku defaults to.

To fix it, make sure your Gemfile starts:

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

More at Heroku docs on Ruby versions.

这篇关于为什么资产:在Heroku上预编译太慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆