Ruby on rails Rails:在时区选择时执行过期

Ruby on rails Rails:在时区选择时执行过期,ruby-on-rails,actionview,activesupport,Ruby On Rails,Actionview,Activesupport,以下异常间歇性出现: An ActionView::Template::Error occurred execution expired vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require' 这是完整的跟踪: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_suppo

以下异常间歇性出现:

An ActionView::Template::Error occurred

execution expired
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
这是完整的跟踪:

vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
vendor/bundle/ruby/1.9.1/gems/tzinfo-0.3.37/lib/tzinfo/timezone.rb:103:in `get'
vendor/bundle/ruby/1.9.1/gems/tzinfo-0.3.37/lib/tzinfo/timezone_proxy.rb:80:in `real_timezone'
vendor/bundle/ruby/1.9.1/gems/tzinfo-0.3.37/lib/tzinfo/timezone_proxy.rb:52:in `period_for_utc'
vendor/bundle/ruby/1.9.1/gems/tzinfo-0.3.37/lib/tzinfo/timezone.rb:458:in `current_period'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/object/try.rb:36:in `try'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:212:in `utc_offset'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:226:in `<=>'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:334:in `sort'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:334:in `all'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/helpers/form_options_helper.rb:507:in `time_zone_options_for_select'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/helpers/form_options_helper.rb:612:in `to_time_zone_select_tag'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/helpers/form_options_helper.rb:277:in `time_zone_select'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/helpers/form_options_helper.rb:654:in `time_zone_select'
跟踪:

vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:5:in `accept'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:36:in `block in visit_Psych_Nodes_Sequence'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:36:in `each'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:36:in `visit_Psych_Nodes_Sequence'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:5:in `accept'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:26:in `block in visit_Psych_Nodes_Document'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:26:in `each'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:26:in `visit_Psych_Nodes_Document'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:5:in `accept'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:20:in `block in visit_Psych_Nodes_Stream'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:20:in `each'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/emitter.rb:20:in `visit_Psych_Nodes_Stream'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:15:in `visit'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/visitors/visitor.rb:5:in `accept'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/nodes/node.rb:46:in `yaml'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych.rb:243:in `dump'
vendor/bundle/ruby/1.9.1/gems/psych-1.3.4/lib/psych/core_ext.rb:14:in `psych_to_yaml'
/usr/local/lib/ruby/1.9.1/syck/rubytypes.rb:110:in `to_yaml'
vendor/bundle/ruby/1.9.1/gems/dalli-delete-matched-1.1.0/lib/dalli-delete-matched.rb:13:in `write_entry'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/cache/strategy/local_cache.rb:140:in `write_entry'
vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:102:in `block in write'
vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:279:in `block in instrument'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications.rb:125:in `instrument'
vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:279:in `instrument'
vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:101:in `write'
vendor/bundle/ruby/1.9.1/gems/dalli-2.6.2/lib/active_support/cache/dalli_store.rb:78:in `fetch'
app/models/concerns/roleable.rb:11:in `roles'
再次强调,任何见解都是非常受欢迎的


我在Heroku上托管了这个,并使用Unicorn按照

上的说明进行操作,因为两个堆栈跟踪完全不同,我敢说页面呈现通常需要很多时间,并且与特定堆栈跟踪中显示的内容无关:ActionView将在超时发生时停止

您应该尝试加快呈现过程,例如通过使用缓存:让机器人只命中从缓存提供的非动态内容,以减少服务器负载。甚至将大页面拆分成部分并缓存这些部分也会有所帮助


如果您仍然遇到这种情况,尤其是因为这种情况非常罕见,那么当出现这种异常时,您可以随时自动重新呈现页面。有关示例代码,请参见。

回答此问题:

我真的很想把这个修好,但我真的没有 建议从何处开始:/

您可以开始补救此错误,将其记录下来,向您发送一封电子邮件,由于此错误只发生过几次,请重试(使用“重试”命令)。在此之后,您可能希望检查此IP执行的最后一个操作,并查看它是否相关。日志还记录会话变量

可能您在服务器使用率较高的情况下出现超时-尝试使用一种工具,甚至自己记录内存使用情况、cpu使用情况和磁盘使用情况以及其他信息

编辑:

由于这不仅仅是一个操作,您可以在ApplicationController上获得如下所示的每个错误:

class ApplicationController < ActionController::Base
  rescue_from MyException, :with => :handle_my_exception

  def handle_my_exception
     grab_data
     send_mail
     retry
  end
 end
class ApplicationController:处理我的\u异常
def处理我的异常
抓取数据
寄信
重试
结束
结束
我认为这是一个特定的操作,所以我不确定重试在这里是否有效。但是,即使您不能重试,您仍然可以通过这种方式获取更多信息并通过电子邮件发送给自己。当然,您需要添加重试计数器逻辑,否则您将遇到麻烦

再次编辑:

考虑得更好,您可以根据请求参数使用重定向到模拟重试。在这个答案中,他解释了如何得到它。别忘了也给我送些情人

这个问题(无论如何在Heroku上)归结为以下代码:

ActiveSupport::TimeZone::MAPPING.each do |key,val|
  TZInfo::Timezone.get(val)
end
所有时区信息都是从一组相当大的文件(每个时区一个)中加载,然后进行解析。由于某种原因,这项工作非常繁重。也许是Ruby在基于文件的IO(?)方面效率不高,而Heroku dynos在文件系统中随机出现问题


我目前的解决方案是在所有Unicorn Worker(在fork之后)中预加载时区信息(基本上运行上述代码)。现在,至少问题是确定性的,而不是随机发生的…

这是否发生在控制器的一个特定操作上?不,两个堆栈跟踪来自不同的控制器。您是否找到了此错误的根源?我在heroku身上也看到了同样的错误。我的堆栈跟踪看起来和你的第一个堆栈跟踪很相似。@Clark-它非常断断续续。我不想说它是“固定的”,但它发生的次数较少,尽管我(有意识地)没有做任何事情来解决这个特定的问题——除了调整我的独角兽超时设置和添加另一个dyno(我本来打算这么做)。如果你发现了什么,请告诉我/发布答案!我的直觉是,这是由于等待heroku的文件系统造成的。我增加了超时变量-从heroku网站上推荐的10秒增加到25秒。。。将监视营救/重试代码的去向?在
render
调用的控制器中,或者在视图中?我添加了一些代码示例,说明了如何执行我的假设。但不确定重试是否能正常工作:(关于发送邮件:仔细查看它会发送一封非常有用的电子邮件。是的,我正在使用异常通知来获取提醒我这一点的电子邮件:)
ActiveSupport::TimeZone::MAPPING.each do |key,val|
  TZInfo::Timezone.get(val)
end