Do you want a timeout?
Do you want a timeout?
You’re feeling accomplished and excited; the new features for your application are finished, committed, and deployed. You fire it up, expecting your shiny new app on your screen. Unexpectedly, the app errors out or hangs indefinitely.
What’s going on?!
You may have just had your first direct encounter with the subtleties of your MongoDB driver’sconnection options.
At a high level, whenever you create or use a MongoClient object to talk to your database, the driver establishes a connection to your MongoDB server. How long your application waits for the initial connection to be established and how long it waits for responses to subsequent requests is determined by the values of your connection and socket timeouts.
Connection timeout
The connection timeout value determines the maximum amount of time your driver will wait for a connection to be established with the server.
This value is only used when making an initial connection to your database, and so selecting the correct setting for this timeout can be a balancing act.
On the one hand you want to make sure that your connection timeout is high enough that your application can reliably establish a connection to the database server, even in the face of high server load or intermittent network lag. On the other hand you don’t want the timeout to be so large that your application “hangs” for an inordinate amount of time while it waits to connect to a server that may be temporarily unreachable; in this case you will want to propagate the error state up to your users in a relatively timely matter and too high a timeout can make this difficult.
The default driver connection timeout value ranges anywhere from 1 second (e.g. the Node.JS driver in some cases) to 30 seconds (e.g the Ruby driver), so you really need to think about what the optimal setting is for your use case.
Our suggestions for the connection timeout
We suggest starting with a relatively low timeout value and slowly increasing it if you face regular connection timeouts. Generally, you’ll want to use a connection timeout of 5 seconds.
For connections made through a Platform-as-a-Serivce (PaaS) such as Heroku, you might consider an even higher timeout (e.g. 30 seconds) since your application is likely running in a container that can be “idled” or “passivated” during periods of low activity. In such cases it may take longer for your code to establish new database connections when your application is made active again.
Of course, we also recommend that you use connection pooling so that you are seldom creating new connections to the database server… (but this will be the topic of another post :)
Socket timeout
The socket timeout option specifies to your driver how long to wait for responses from the server. This timeout governs all types of requests (queries, writes, commands, authentication, etc.).
For example, if you have this timeout set to 30 seconds, your driver will never wait more than 30 seconds for the result of a query (although the query will continue to run to completion on the server). While there are some types of operations where you might consider defining a hard timeout (e.g. authentication), you usually don’t want to limit the amount of time your database operations take as they can be inherently variable.
The default socket timeout value for most drivers is infinite (i.e. no timeout) which is usually expressed as 0 or a null value.
Our suggestions for the socket timeout
We suggest leaving this setting at the default (i.e. no timeout) unless you have good reason to change it. That said, some drivers allow you to control this setting on a per operation basis, in which case you may consider fine-tuning this setting based on your knowledge of specific operations.
Further your knowledge
Each MongoDB driver implements the MongoClient class and these network timeout options differently. If you would like to investigate these timeout options further, you can peruse each specific driver’s documentation and source code for details on how to configure these options with that driver.
These timeouts are only two of many MongoDB driver options available to you. We encourage you to explore and learn more about your driver configuration settings so that you may fine-tune your app with optimal settings based on your use case.
When in doubt, you can drop us a line anytime at support@mongolab.com. With Mongo power comes Mongo responsibility!
Do you want a timeout?的更多相关文章
- ASP.NET MVC Html.BeginForm 设置 timeout
示例代码: @using (Html.BeginForm("PublishSubmit", "Blog", FormMethod.Post, new { id ...
- tomcat 504 gateway time-out
今天有个环境ajax调用一个请求的时候,出现一个504 gateway time-out响应,原以为是nginx找不到资源的问题,恰当我们的服务器上又配置了nginx,看了配置文件,没有指向tomca ...
- mysql timeout知多少
1.timeout变量知多少 打开mysql,用show variables like '%timeout%'命令一看,不看不知道,一看吓一跳,结果如下面所示,这么多timeout相关变量,一下就吓尿 ...
- angularjs 中的setTimeout(),setInterval() / $interval 和 $timeout
$interval window.setInterval的Angular包装形式.Fn是每次延迟时间后被执行的函数. 间隔函数的返回值是一个承诺.这个承诺将在每个间隔刻度被通知,并且到达规定迭代次数后 ...
- shiro session计算timeout
/** * Determines if this session is expired. * * @return true if the specified session has expired, ...
- adb connect 出现timeout的处理方式
默认的timeout是5000ms毫秒,如果是断点调试的时候,经常会出现timeout, 所以修改这个值就不会出现timeout了, Eclipse下的设置位置: Window->Prefere ...
- 更改pip安装源的镜像解决安装总是timeout的情况
由于国外的pip源总是由于各种原因不能被访问或者网速过慢,而造成的timeout错误 解决方法是修改pip的配置文件(如果没有配置文件在相应的地方新建,配置文件的路径和名字参考这里),设置安装包时候访 ...
- 【异常】No ManagedConnections available within configured blocking timeout
Caused by: org.jboss.util.NestedSQLException: No ManagedConnections available within configured bloc ...
- $watch $apply and $evalAsync vs $timeout
$watch $scope对象上的$watch方法会给Angular事件循环内的每个$digest调用装配一个脏值检查. 如果在表达式上检测到变化, Angular总是会返回$digest循环. $w ...
- vue-resource请求超时timeout设置
请求超时设置通过拦截器Vue.http.interceptors实现具体代码如下 main.js里在全局拦截器中添加请求超时的方法 方法1:超时之后会调用请求中的onTimeoutd方法,then方法 ...
随机推荐
- rfid 125khz
环境是STVD V4.1.6, 编译器是COSMIC STM8 C Compiler 16K ,Version: 4.3.1 调用的库有:GPIO,TIM2 相关宏定义: //RF数据引脚 #defi ...
- CAS (8) —— Mac下配置CAS到JBoss EAP 6.4(6.x)的Standalone模式(服务端)
CAS (8) -- Mac下配置CAS到JBoss EAP 6.4(6.x)的Standalone模式(服务端) jboss版本: jboss-eap-6.4-CVE-2015-7501 jdk版本 ...
- mac OS X:[11]如何添加打印机
苹果菜单中,单击下拉列表中的『系统偏好设置』: 或在Dock上,单击『系统偏好设置』图标. 2 在『系统偏好设置』窗口中,单击『打印机与扫描仪』图标. 3 在『打印机与扫描仪』窗口中,单击打印机框架下 ...
- WmS具体解释(二)之怎样理解Window和窗体的关系?基于Android7.0源代码
上篇博客(WmS具体解释(一)之token究竟是什么?基于Android7.0源代码)中我们简要介绍了token的作用,这里涉及到的概念非常多,当中出现频率最高的要数Window和窗体这一对搭档了,那 ...
- MSSQL跨服务器查询
1.因为此功能服务器安全配置的一部分而被关闭,所以我们先开启 reconfigure reconfigure 2.如果需要关闭,执行 reconfigure reconfigure 3.查询语句 SE ...
- MySQL 入门教程
目录 一.MySQL的相关概念介绍 二.Windows下MySQL的配置 配置步骤 MySQL服务的启动.停止与卸载 三.MySQL脚本的基本组成 四.MySQL中的数据类型 五.使用MySQL数据库 ...
- PHP经纬度 测距
/** *求两个已知经纬度之间的距离,单位为米 *@param lng1,lng2 经度 *@param lat1,lat2 纬度 *@return float 距离,单位米 **/ function ...
- Mybatis set标签
set - 更新语句 当 update 语句中没有使用 if 标签时,如果有一个参数为 null,都会导致错误. 当在 update 语句中使用if标签时,如果前面的if没有执行,则或导致逗号多余错误 ...
- CI框架 -- 在视图文件中使用 PHP 替代语法
如果你不使用 CodeIgniter 的 模板引擎, 那么你就只能在视图文件中使用纯 PHP 语法了.为了精简视图文件, 使其更可读,建议你在写控制结构或 echo 语句时使用 PHP 的替代语法. ...
- jQuery 文件上传插件:uploadify、swfupload
jQuery 文件上传插件: uploadify.swfupload