ASP.NET 应用程序中的 ConnectionString 超时时间应该是多长? (sql客户端)
在我的 ASP.NET 应用程序中,我的 web.config 文件中有一个 sqlclient 连接字符串,生产环境的建议超时设置是多少?默认值为 15 秒。
我的网络场和数据库集群位于同一交换机上,因此应该不会有太多延迟。
In my ASP.NET application, I have a sqlclient connectionstring in my web.config file, What is the recommended timeout setting for production environment? Default is 15 seconds.
My web farm and database cluster are on the same switch, so there should not be much latency.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认值 15 秒是一个合理的值,很少有理由更改它。
超时时间较长的一个原因是,例如,如果您的数据库服务器有时运行大量查询,导致其在几秒钟内无响应。
缩短超时时间的一个原因是,如果您希望尽早出错,而不是在数据库无响应时等待,例如,如果您可以使用缓存数据作为备份。
The default of 15 seconds is a reasonable value, and there is rarely any reason to change it.
A reason to have a longer timeout is for example if your database server is sometimes running heavy queries that makes it unresponsive for a few seconds.
A reason to have a shorter timeout would be if you want an error early instead of waiting when the database is unresponsive, for example if you can use cached data as a backup.
默认超时适用于大多数情况。如果它不属于您的并且您遇到问题,您可以对其进行修改。如果您希望在连接出现问题时立即引发异常以避免独占工作线程,则降低此超时可能会很好。
The default timeout will work for most scenarios. If it doesn't in yours and you encounter problems you could modify it. Lowering this timeout could be good in cases where you want to immediately throw an exception if there are problems connecting to avoid monopolizing worker threads.
大多数情况下这应该是好的。如果您遇到问题,您可以尝试进行调整,但最重要的事情始终是衡量更改的影响。
另一件让事情变得更顺利的事情是使用缓存。有一些开源工具可用,例如 memcached。微软也有自己的分布式缓存机制:AppFabric。
Mostly that should be good. If you encounter problems you could experiment with tweaking it but the most important thing then, and always actually, is the measure the impact of your changes.
Another thing to keep things from going more smoothly is to use caching. There are open source tools available like memcached. Microsoft also has its own distributed caching mechanism: AppFabric.