我可以设置Mongoid查询超时吗? Mongoid不会杀死长时间的查询 [英] Can I set Mongoid query timeout? Mongoid don't kill long time query

查看:61
本文介绍了我可以设置Mongoid查询超时吗? Mongoid不会杀死长时间的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mongoid没有超时选项.
http://mongoid.org/en/mongoid/docs/installation.html

Mongoid don't have timeout option.
http://mongoid.org/en/mongoid/docs/installation.html

我希望Mongoid杀死长时间的查询. 如何设置Mongoid查询超时?

I want Mongoid to kill long time queries. How can I set Mongoid query timeout?

如果我什么也不做,Mongoid会像下面这样长时间等待.

If I do nothing, Mongoid wait a long time like the below.

mongo > db.currentOp()

{
    "opid" : 34973,
    "active" : true,
    "secs_running" : 1317, // <- too long!
    "op" : "query",
    "ns" : "db_name.collection_name",
    "query" : {
    "$msg" : "query not recording (too large)"
  },
    "client" : "123.456.789.123:46529",
    "desc" : "conn42",
    "threadId" : "0x7ff5fb95c700",
    "connectionId" : 42,
    "locks" : {
    "^db_name" : "R"
  },
    "waitingForLock" : true,
    "numYields" : 431282,
    "lockStats" : {
    "timeLockedMicros" : {
     "r" : NumberLong(514304267),
     "w" : NumberLong(0)
  },
    "timeAcquiringMicros" : {
     "r" : NumberLong(1315865170),
     "w" : NumberLong(0)
    }
  }
 }

推荐答案

Mongoids的默认查询超时通常为60秒,但是由于Rubys线程,在正确关闭进程时往往会出现问题.

The default query timeout is typically 60 seconds for Mongoids but due to Rubys threading there tend to be issues when it comes to shutting down processes properly.

希望您的请求都不会对Mongrels造成压力,但是如果您继续遇到此问题,我会考虑对您的应用程序进行一些优化更改,或者可能考虑采用God或Monit.如果您不喜欢它,并且想更改您的请求处理方式,那么我可能会建议Unicorn(如果您已经在使用nginx的话)(github进行了这种转换,您可以阅读更多内容

Hopefully none of your requests will be putting that strain on the Mongrels but if you keep running into this issue I would consider some optimization changes to your application or possibly consider adopting God or Monit. If you aren't into that and want to change your request handing I might recommend Unicorn if you are already on nginx (github has made this transition and you can read about it more here)

这篇关于我可以设置Mongoid查询超时吗? Mongoid不会杀死长时间的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆