Heroku非常缓慢地提供资产
我在我的Rails应用程序中提供资产时遇到了很大的麻烦。在我的VPS(由nginx,而不是Rails直接提供)上加载2KB图像需要42毫秒。 在Heroku上加载它有时可能需要1分钟以上。
奇怪的是,此时应用程序只是通过高压服务的一堆静态页面。
我的所有资产都是在本地预编译的。 我安装了rails_12factor和heroku_rails_deflate gems。
这是我的Sprockets配置:
配置/初始化/ 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 )
配置/环境/ 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 解决 。 感谢所有帮助过的人! 🙂
我在Twitter上找到了修复我类似问题的信息
这似乎与websockets有关。 禁用它似乎可以解决问题。
heroku labs:disable websockets -a myapp -p production
这使它像过去一样工作,虽然日志现在看起来不同:)
感谢Twitter上的@dwaynemac @stephane_tavera。
编辑 :
Heroku将此视为解决问题,但如果再次发生,则应答。
Heroku的
我可以给出的唯一建议是将图像放在第三方服务上, 例如S3
?
Heroku本身托管在亚马逊AWS平台上,因此为资产提供服务不会有任何问题。 我一直使用Heroku(这是一个很好的演示版 ),我们的资产负载尽可能快
–
D B
我在Heroku中找到的一件事是,如果你的数据库连接很糟糕,你将无法快速加载页面。
db
连接是Heroku的Achilles Heel – 除非你使用Heroku自己的postgres
数据库 ,你必须确保你有一个快速的连接
除此之外 – 最好的办法是提供您的日志供我们查看!