Ruby Mongo驱动程序上的timeout和connect_timeout选项之间的区别

时间:2013-06-17 18:16:57

标签: ruby mongodb

我们需要在通过Ruby连接到Mongo时设置超时值。我们在Mongo 2.2上。

我们应该使用:timeout还是:connect_timeout?我们在SO和其他地方看到了使用这两个选项的代码片段。有什么区别?

1 个答案:

答案 0 :(得分:0)

您可以看到不同的超时内容:

https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/mongo_client.rb#L104

从那里复制:

#  @option opts [Float] :timeout (5.0) When all of the self.connections a pool are checked out,
#    this is the number of seconds to wait for a new connection to be released before throwing an exception.
#    Note: this setting is relevant only for multi-threaded applications.
#  @option opts [Float] :op_timeout (nil) The number of seconds to wait for a read operation to time out.
#    Disabled by default.
#  @option opts [Float] :connect_timeout (nil) The number of seconds to wait before timing out a
#    connection attempt.