Rails - 不稳定的超时错误可能与资产编译有关

时间:2015-01-22 03:35:42

标签: ruby-on-rails angularjs ruby-on-rails-4 rack bower

  

代码转储的抢先道歉。我已经对这个问题做了一段时间(并且做了大量的谷歌搜索)并且只是有一个相当模糊的想法是什么是不相关的,以及如何解决问题。所以我认为我可以获得尽可能多的信息。 请告诉我是否还有其他可能有帮助的内容。谢谢!

我正在启动Rails和Angular应用程序,并且大多数仍处于开发模式。我使用的是Heroku,但我也不知道这些问题是否也很严重,因为我大部分时间都在编码并在当地碰到它们(在生产中几乎没有用过)。 (刚才提到过,因为大多数类似的问题似乎都是Heroku特有的)。

我间歇性地碰到的错误就是这个:

 Rack::Timeout::RequestTimeoutError: Request ran for longer than 5 seconds.

及其分身:

 ActionView::Template::Error: Request ran for longer than 5 seconds.

当它被引发时,它指向不同的文件作为直接的罪魁祸首 - 但始终是Java / CoffeeScript或CSS / SASS文件。偶尔在本地服务器上重新加载浏览器将永远旋转,而不是引发上述错误。通常,刷新工作正常,但偶尔我必须重新启动服务器以解冻"解冻"它。

  

我可以尝试将Rack :: Timeout增加到更大的值,但是我觉得这可能会处理潜在的许多症状之一,而不是潜在的问题。

我确信这与某种类型的资产预编译错误有关 - 这是我不熟悉的,因为这是我从头开始的第一个认真的应用程序,特别是结合了Angular和Rails。

  

我很难找到Rails和Angular的非常流畅的组合 - 建议绝对值得赞赏。

我设法通过在弄乱我的清单SASS文件时运行并重新运行某些功能规范来查明错误。每次我通过评论一些application.sass来更改@import文件,(部分)功能规格都会失败,但如果我重新运行它们,它们会一次又一次地传递,直到我评论或出一条不同的路线。特定的行似乎不相关,但是,如果我错了,请查看我的application.sass文件:

@charset "utf-8"

@import "bootstrap-sprockets"
@import "bootstrap"

@import "bourbon"
@import "base/grid-settings"
@import "neat"
@import "base/base"

@import "leaflet"

@import "skeleton/base"
@import "skeleton/layout"
@import "skeleton/skeleton"

@import "sections/header"
@import "sections/footer"
@import "sections/user"
@import "sections/map"
@import "sections/tabs"

@import "sections/baseapp"

@import "markercluster/MarkerCluster"
@import "markercluster/MarkerCluster.Default"

@import "icons"

@import "font-awesome-sprockets"
@import "font-awesome"

因为我认为我的杂乱资产解决方案可能会受到责备,所以我会在下面粘贴大部分相关代码。基本上,我使用 NPM package.json)作为服务器端JS的东西,比如Jasmine用于测试, Bower 用于客户端的东西,如Angular和传单(用于地图)。为了在Rails应用程序中提供Bower JS,我在Gemfile中使用 Rails Assets 。 (虽然我不知道为什么我需要bower.json的东西,如果我这样做的话)。因此,这些清单文件的相关部分如下所示:

的package.json

{
  "name": "whatever",
  "dependencies": {
    "rosie": "0.2.0",    
    "bower": "1.2.8",
    "jasmine": "2.1.1",
    "phantomjs": "1.9.13",
    "sinon": "1.12.2",
    "jasmine-sinon": "0.4.0",
    "requirejs": "2.1.15"
  },
  "devDependencies": {
    "grunt": "~0.4.4"
  }
}

bower.json

{
  "name": "whatever",
  "version": "0.1.0",
  "authors": [
    "Whatever"
  ],
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_compnents",
    "test",
    "tests"
  ],
  "dependencies": {
    "angular": "latest",
    "angular-resource": "latest",
    "angular-route": "latest",
    "angular-mocks": "latest",
    "active-support": "latest",
    "async": "latest",
    "lodash": "latest",
    "leaflet": "latest",
    "leaflet.markercluster": "latest"
  }
}
  

我的意思是在将这些版本放在用户面前之前确定版本。

的Gemfile

gem 'rails-assets-angular'
gem 'rails-assets-angular-resource'
gem 'rails-assets-angular-route'
gem 'rails-assets-angular-mocks'
gem 'rails-assets-active-support'
gem 'rails-assets-async'
gem 'rails-assets-lodash'
gem 'rails-assets-leaflet'
gem 'rails-assets-requirejs'
gem 'rails-assets-sinon'
# gem 'rails-assets-leaflet.markercluster' -- wasn't working, so I included the relevant scripts in app/assets/javascripts/ -- seems to be working

我还在我的Gemfile的test组中添加了这些内容。我担心这些JS包含的重叠和蔓延,但这是让JS测试工作的原因。

  gem "jasmine-rails"
  gem 'jasmine-headless-webkit'
  gem 'guard-jasmine'
  gem 'rails-assets-rosie'
  gem "sinon-rails"

由于各种原因,我手动预编译了一些资产:

配置/初始化/ assets.rb

Rails.application.config.assets.precompile += [ 
  'api/bookmarklets/view.js', 
  'sections/bookmarklet.css',   
  'icons.eot',
  'icons.svg',
  'icons.ttf',
  'icons.woff'
]

在本地,(现在正在制作),我的资产只托管在服务器上(所以在localhost:3000)。怀疑数据库是否相关,但其池设置为2并超时到5000。搜索其他可能相关的代码,我在config/environments/development.rb中发现了这个问题 - 可能出现问题?:

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

编辑 - 在运行功能规范时从我遇到的其中一个错误中添加完整堆栈跟踪:

# /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:125:in `[]'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:125:in `process_comment'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:88:in `s'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:82:in `block in stylesheet'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:545:in `block_contents'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:82:in `stylesheet'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/scss/parser.rb:27:in `parse'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/engine.rb:342:in `_to_tree'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/engine.rb:315:in `_render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sass-3.2.19/lib/sass/engine.rb:262:in `render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/sass_compressor.rb:24:in `evaluate'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/context.rb:197:in `block in evaluate'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `each'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `evaluate'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/bundled_asset.rb:25:in `initialize'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/base.rb:377:in `new'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/base.rb:377:in `build_asset'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-2.12.3/lib/sprockets/base.rb:295:in `[]'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/helper.rb:123:in `asset_digest_path'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/helper.rb:76:in `compute_asset_path'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_url_helper.rb:132:in `asset_path'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/helper.rb:91:in `asset_path'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_url_helper.rb:256:in `stylesheet_path'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_tag_helper.rb:100:in `block in stylesheet_link_tag'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_tag_helper.rb:96:in `map'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/helpers/asset_tag_helper.rb:96:in `stylesheet_link_tag'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/helper.rb:170:in `stylesheet_link_tag'
 # ./app/views/layouts/application.html.haml:9:in `_app_views_layouts_application_html_haml__3935206380113339538_2226830520'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/template.rb:145:in `block in render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications.rb:161:in `instrument'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/template.rb:339:in `instrument'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/template.rb:143:in `render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiling_methods.rb:79:in `block in profile_method'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/template_renderer.rb:67:in `render_with_layout'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/template_renderer.rb:53:in `render_template'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/template_renderer.rb:17:in `render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/renderer.rb:42:in `render_template'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/renderer/renderer.rb:23:in `render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/rendering.rb:99:in `_render_template'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/streaming.rb:217:in `_render_template'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/rendering.rb:82:in `render_to_body'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/renderers.rb:32:in `render_to_body'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/rendering.rb:25:in `render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rendering.rb:16:in `render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/core_ext/benchmark.rb:12:in `ms'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:41:in `block in render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:40:in `render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/responder.rb:238:in `default_render'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/responder.rb:165:in `to_html'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/responder.rb:158:in `respond'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/responder.rb:151:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/mime_responds.rb:400:in `respond_with'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/app/controllers/devise/sessions_controller.rb:11:in `new'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/base.rb:189:in `process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rendering.rb:10:in `process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:113:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:113:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:229:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:229:in `block in halting'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:166:in `block in halting'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:86:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:86:in `run_callbacks'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/callbacks.rb:19:in `process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rescue.rb:29:in `process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications.rb:159:in `block in instrument'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications.rb:159:in `instrument'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/abstract_controller/base.rb:136:in `process'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionview-4.1.4/lib/action_view/rendering.rb:30:in `process'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiling_methods.rb:79:in `block in profile_method'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal.rb:196:in `dispatch'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_controller/metal.rb:232:in `block in action'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:82:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:50:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/mapper.rb:45:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/journey/router.rb:71:in `block in call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/journey/router.rb:59:in `each'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/journey/router.rb:59:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/routing/route_set.rb:678:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/flash.rb:254:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/cookies.rb:560:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/query_cache.rb:36:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/callbacks.rb:82:in `run_callbacks'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/airbrake-4.1.0/lib/airbrake/rails/middleware.rb:13:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/rack/logger.rb:38:in `call_app'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/rack/logger.rb:20:in `block in call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/tagged_logging.rb:68:in `block in tagged'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/tagged_logging.rb:26:in `tagged'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/tagged_logging.rb:68:in `tagged'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/rack/logger.rb:20:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/request_store-1.1.0/lib/request_store/middleware.rb:8:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/request_id.rb:21:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.4/lib/action_dispatch/middleware/static.rb:64:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/airbrake-4.1.0/lib/airbrake/user_informer.rb:16:in `_call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/airbrake-4.1.0/lib/airbrake/user_informer.rb:12:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-timeout-0.1.1/lib/rack/timeout.rb:104:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-mini-profiler-0.9.2/lib/mini_profiler/profiler.rb:193:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/engine.rb:514:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application.rb:144:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-test-0.6.3/lib/rack/test.rb:58:in `get'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:60:in `process'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:38:in `block in process_and_follow_redirects'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:37:in `times'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:37:in `process_and_follow_redirects'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/browser.rb:21:in `visit'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:42:in `visit'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/session.rb:227:in `visit'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
 # ./spec/features/authentication_spec.rb:7:in `block (3 levels) in <top (required)>'
 # ./spec/support/background_jobs.rb:14:in `block (3 levels) in <top (required)>'
 # ./spec/support/background_jobs.rb:5:in `run_background_jobs_immediately'
 # ./spec/support/background_jobs.rb:13:in `block (2 levels) in <top (required)>'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus/rails.rb:208:in `test'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus.rb:148:in `block in command'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus.rb:135:in `fork'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus.rb:135:in `command'
 # /Users/sasha/.rvm/gems/ruby-2.1.2/gems/zeus-0.15.2/lib/zeus.rb:50:in `go'

更新

根据coreyward的建议,我将机架超时设置为25秒并设置一些分析工具。超时的增加(特定于dev环境)使问题在localhost上消失。但是,令人困惑的是,根据NewRelic和MiniProfiler,我似乎没有经历5秒以上的任何加载时间。我认为我获得的最长加载时间约为3秒,而我只得到了一次。我改进了一个查询,并没有再次进入高负荷时间。所以我碰到了5秒的限制,这很奇怪。

基本上,当我增加机架超时时,加载时间问题似乎消失了。但我还有一些奇怪的事情,因为功能测试仍然会在持续集成测试中暂停,偶尔会在本地测试。

我清理了我的资产情况(摆脱了Bower和NPM,并通过Gemfile做了一切,通常使用Rails-Assets gem)。我还升级到Rails 4.2和Ruby 2.2以提高性能。根据分析,事情看起来通常会加快一点。

但我仍然遇到同样的测试失败。有趣的是,在我的持续集成工具中,测试几乎总是失败,当他们这样做时,他们会因为不同的错误而失败(我用截图捕获)。

Internal Server Error

could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)

________________________________

WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25) at 127.0.0.1:47539

这表明它是一个数据库问题。我的数据库设置(database.yml)用于测试环境(我的CI使用)如下:

  adapter: postgresql
  database: planit_development
  encoding: utf8
  host: localhost
  min_messages: warning
  pool: 2
  timeout: 5000

但是,奇怪的是,我的本地测试套件具有相同的设置,往往会通过(除非我弄乱了资产文件,在这种情况下,第一个功能规格可能会失败,但不会后续,运行)。 失败的测试是整个套件中数据库密集度最低的测试(只是基本的auth流测试)

分析确实帮助我解决了一些错误,但我仍然对这个看似持续存在问题的根本原因感到非常难过。基于这个新信息的任何想法?或者我还应该关注什么呢?

1 个答案:

答案 0 :(得分:1)

有很多方法可以调试它。首先,将Rack :: Timeout时间增加到25秒 - 虽然这可能会让事情变得更糟,但它可以让您准确评估请求的实际时间(5.1s与25s不同) 。

使用NewRelic或Skylight等监控工具。前者更受欢迎,可以轻松配置为记录超过特定阈值的所有请求的跟踪。这将允许您(大致)查看花费时间的位置,以及与其相关的参数/请求信息。

如果您认为失败的请求是资产,我会仔细检查您是否在生产中关闭了资产编译。您希望在production.rb

中使用此功能
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

这意味着您需要将每个资产都用于预编译。您可以运行rake assets:precompile并验证public/assets中的输出是您预期的结果来测试您的设置是否正确。

确保你也在以后可以访问它们的地方输出日志 - 我更喜欢Papertrail,但毫无疑问是其他人。这将允许您在发生错误时查找错误,尤其是404(如果您有未预编译的资产请求,则会看到这些错误)。隔离并解决问题后,您可以降低此值,但我仍然不会将其设置为低于15秒。

垃圾收集是间歇性长请求时间的另一个潜在罪魁祸首,但5秒可能过度。较新版本的Ruby(特别是2.2)更适合管理它,所以如果你可以使用可能会改进的版本。

祝你好运!