在Heroku/Unicorn上经常出现的Rails错误 - 'execution expired',一个ActionView::Template::Error。

11

我的问题类似于以下问题,但发生在稍微不同的情况下。

Rails:time_zone_select上执行超时

我的设置是:

  • Rails 3.2.13
  • Unicorn 4.6.2
  • Mongoid 3.0.22
  • Moped 1.4.2

运行在Heroku Cedar上。 MongoDB 托管在 MongoLab上。

这些错误会批量出现,并且通常可以通过 Heroku 进程重启来解决。 第一个错误通常如下所示:

An ActionView::Template::Error occurred in [controller]#[action]:

 execution expired
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/sockets/connectable.rb:46:in `read'
以下是堆栈跟踪的顶部信息。 如有需要,可以增加更多信息!
vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/sockets/connectable.rb:46:in `read'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/sockets/connectable.rb:46:in `block in read'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/sockets/connectable.rb:118:in `handle_socket_errors'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/sockets/connectable.rb:46:in `read'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/connection.rb:177:in `read_data'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/connection.rb:99:in `block in read'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/connection.rb:202:in `with_connection'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/connection.rb:97:in `read'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/protocol/query.rb:163:in `receive_replies'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/connection.rb:135:in `block in receive_replies'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/connection.rb:134:in `map'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/connection.rb:134:in `receive_replies'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/node.rb:553:in `block (2 levels) in flush'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/node.rb:129:in `ensure_connected'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/node.rb:551:in `block in flush'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/node.rb:566:in `logging'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/node.rb:550:in `flush'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/node.rb:539:in `process'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/node.rb:349:in `query'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/cursor.rb:138:in `block in load_docs'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/session/context.rb:105:in `block in with_node'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/cluster.rb:250:in `with_secondary'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/session/context.rb:104:in `with_node'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/cursor.rb:137:in `load_docs'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/cursor.rb:25:in `each'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/query.rb:76:in `each'
 vendor/bundle/ruby/1.9.1/gems/moped-1.4.2/lib/moped/query.rb:76:in `each'
 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.22/lib/mongoid/contextual/mongo.rb:132:in `block in each'
 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.22/lib/mongoid/contextual/mongo.rb:556:in `selecting'
 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.22/lib/mongoid/contextual/mongo.rb:131:in `each'
 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.22/lib/mongoid/contextual.rb:18:in `each'

Rack::Timeout被设置为10秒(我相信这是我阅读的缓存教程中建议的) - 如果答案是增加超时时间,那很好。但我是否会怀疑这不是一个慢查询问题呢?行为似乎表明这只是一个挂起的Unicorn进程(这就是为什么ps重启似乎可以解决它的原因)。

如果有任何想法或技巧,将不胜感激!


1
我在EC2上看到了一个非常相似的堆栈,出现了同样的问题/堆栈跟踪。 - nont
这不是问题的解决方案,而是一种轻微的变通方法(也不一定是好方法)--我在Heroku上将Unicorn换成了Puma,并增加到了2个Dynos,这样问题就大大减少了。但它仍然没有被解决,我仍然每天会收到一些“执行超时”的错误(从每小时一些减少到了每天一些)。我的直觉告诉我这是Mongoid/MongoLab的问题--要么是缓慢的查询响应,要么是与非本地数据库挂起的连接。 - nlh
更新 #2:即使使用了2个dynos和Puma而不是Unicorn,这种情况仍然经常发生。唉。 - nlh
@NoahLehmann-Haupt,你解决了这个问题吗?我也遇到了类似的问题。 - Jason Swett
很遗憾,我没有解决这个问题。最后我转而使用Puma,并完全摒弃了Rack::Timeout -- 网站在这种设置下运行得更好。我知道这并不能解决问题或解决这个问题,可惜。 - nlh
显示剩余2条评论
2个回答

1
我建议这是Heroku文件或网络系统的问题。 modped读取方法调用Kernel :: select。 Select本身是一个系统阻塞调用,它将等待IO对象变为可读。在这种情况下,它是与MongoLab进行外部连接的TCP端口。 TCP端口无法读取可能有许多原因。网络和文件问题是其中之一。我怀疑这不是长时间运行的查询,因为套接字在查询运行期间是可读的,因此选择不会阻止脚本执行。如果问题仍然存在,我会考虑远离Heroku或者在不同网络上使用外部数据库。 AWS始终是一个很好的选择,因为它们在盒子之间具有非常低的延迟。希望对你有所帮助。

0

尝试在您的Gemfile中将Ruby版本设置为1.9.3,然后再次进行bundle、提交和部署


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接