Can I set Mongoid query timeout? Mongoid don't kill long time query

丶灬走出姿态 提交于 2019-12-05 18:49:07

Actually, all queries have a timeout by default. You can set a no_timeout option to tell the query to never timeout.Take a look here

You can configure the timeout period using a initializer, like this

Mongoid.configure do |config|
  config.master = Mongo::Connection.new(
    "localhost", 27017, :op_timeout => 3, :connect_timeout => 3
  ).db("mongoid_database")
end

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.

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)

Sobolev Eugene

Try this solution:

ModelName.all.no_timeout.each do |m|
  "do something with model"
end

https://stackoverflow.com/a/19987744/706022

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!