Heroku serves assets very slowly

霸气de小男生 提交于 2019-12-11 09:59:30

问题


I'm having huge trouble serving assets in my Rails application .Loading a 2KB image on my VPS (served directly by nginx, not Rails) takes me 42ms. Loading it on Heroku might take more than 1 minute sometimes.

The strange fact is that at this point the application is just a bunch of static pages served through High Voltage.

All my assets are precompiled locally. I have the rails_12factor and heroku_rails_deflate gems installed.

Here's my Sprockets configuration:

config/initializers/assets.rb

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += %w( pages/home.js )

config/environments/production.rb

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true

# Compress JavaScripts and CSS.
config.assets.compress = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Generate digests for assets URLs.
config.assets.digest = true

Do you have any ideas?

Here's an excerpt from my logs:

14-07-11T23:48:54.917535+00:00 heroku[router]: at=info method=GET path="/assets/pages/home-dca14429ad8cf7d73be6230207124ab1.js" host=v2-interconn.herokuapp.com request_id=aefbec46-f505-45b9-b368-1ad5f7924c70 fwd="188.10.253.161" dyno=web.1 connect=1 service=3 status=200 bytes=916
2014-07-11T23:48:54.911470+00:00 heroku[router]: at=info method=GET path="/assets/application-a6b582f07af35ba97eef7b73812c37b9.js" host=v2-interconn.herokuapp.com request_id=3cf43d9f-e35b-4f62-8cbc-47121e07375b fwd="188.10.253.161" dyno=web.1 connect=0 service=8 status=200 bytes=917
2014-07-11T23:48:54.940930+00:00 heroku[router]: at=info method=GET path="/assets/ballicons/letter-0223f57c4a985183df154ed1219f260e.svg" host=v2-interconn.herokuapp.com request_id=6c7a7b12-683e-42e7-9975-6ee58b17821e fwd="188.10.253.161" dyno=web.1 connect=1 service=2 status=200 bytes=940
2014-07-11T23:48:55.064240+00:00 heroku[router]: at=info method=GET path="/assets/ballicons/laptop-5ac5cd546c687e0bbba1e4043c5f62f8.svg" host=v2-interconn.herokuapp.com request_id=9a659d8b-8998-4f02-b8b3-edd1a6cfb34c fwd="188.10.253.161" dyno=web.1 connect=3 service=3 status=200 bytes=940

Edit

The issue has been resolved by Heroku. Thanks to all who helped! :)


回答1:


I found information on Twitter that fixed my similar issue

this seems to be related to websockets. Disabling it seems to cure the issues.

heroku labs:disable websockets -a myapp -p production

this makes it work as it used to, though the logs now look different :)

thanks to @dwaynemac @stephane_tavera on twitter.

EDIT:

Heroku shows this as a resolve issue, but answer applies in case it happens again.

https://status.heroku.com/incidents/649#update-2163




回答2:


Heroku

The only recommendation I could give would be to perhaps put the image on a third party service, such as S3?

Heroku itself is hosted on the Amazon AWS platform, so serving the assets will not be of any issue. All the times I've used Heroku (a good demo being here), our assets load as fast as we need them

--

DB

The one thing I've found with Heroku is if your DB connection sucks, you'll have no chance of loading your pages quickly.

The db connection is the Achilles Heel of Heroku - unless you use Heroku's own postgres db, you'll have to make sure you have a fast connection

Other than that - the best thing to do is provide your logs for us to look through!



来源:https://stackoverflow.com/questions/24708085/heroku-serves-assets-very-slowly

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