【问题标题】:Heroku serves assets very slowlyHeroku 非常缓慢地提供资产
【发布时间】:2014-09-02 16:34:01
【问题描述】:

我在我的 Rails 应用程序中提供资产时遇到了很大的麻烦。在我的 VPS 上加载一个 2KB 的图像(由 nginx 直接提供,而不是 Rails 提供)需要 42 毫秒。在 Heroku 上加载它有时可能需要超过 1 分钟。

奇怪的事实是,此时应用程序只是一堆通过高压提供的静态页面。

我所有的资产都是在本地预编译的。我安装了 rails_12factor 和 heroku_rails_deflate gem。

这是我的 Sprockets 配置:

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

你有什么想法吗?

这是我的日志摘录:

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

编辑

问题是 Heroku 的 resolved。感谢所有帮助过的人! :)

【问题讨论】:

  • 这很糟糕,你需要修复它。您确定您的 heroku 应用程序正在生产模式下运行吗?检查heroku config,也许它正在登台环境中运行?也许您还在使用 webrick 服务器?
  • Heroku 正在生产中运行,我使用 Thin 作为 Web 服务器。
  • 支持帮不了你?他们应该对自己的系统有更多的了解
  • 我已经开了一张票。希望他们至少对可能发生的事情有所了解。
  • 可能和我类似的post here有关

标签: ruby-on-rails heroku assets sprockets


【解决方案1】:

Heroku

我能给出的唯一建议是将图像放在第三方服务上,such as S3

Heroku 本身托管在 Amazon AWS 平台上,因此不会为资产提供服务 任何问题。我一直使用 Heroku(good demo being here),我们的资产加载速度与我们需要的一样快

--

数据库

我在 Heroku 中发现的一件事是,如果您的数据库连接很糟糕,您将没有机会快速加载您的页面。

db 连接是 Heroku 的致命弱点 - 除非您使用 Heroku 自己的 postgres db,否则您必须确保连接速度很快

除此之外 - 最好的办法是提供您的日志供我们查看!

【讨论】:

  • 我正在使用 Heroku 的数据库,并且日志没有显示任何奇怪的东西。我已为问题添加了摘录。
【解决方案2】:

我在 Twitter 上找到了解决我类似问题的信息

这似乎与 websockets 有关。禁用它似乎可以解决问题。

heroku labs:disable websockets -a myapp -p production

这使它像以前一样工作,虽然现在的日志看起来不同了:)

感谢推特上的@dwaynemac @stephane_tavera。

编辑

Heroku 将此显示为已解决的问题,但如果再次发生,则答案适用。

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

【讨论】:

  • 现在工作得很好。显然这是一个暂时的问题。谢谢! :)
  • 很高兴看到你把它修好了!!
猜你喜欢
  • 2017-01-14
  • 1970-01-01
  • 2015-09-02
  • 1970-01-01
  • 1970-01-01
  • 2018-11-24
  • 2012-04-18
  • 2010-10-24
  • 1970-01-01
相关资源
最近更新 更多