Why is assets:precompile so slow on Heroku?

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

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?

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!