连接超时和连接寿命 [英] Connection Timeout and Connection Lifetime

查看:45
本文介绍了连接超时和连接寿命的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

connection timeout=0有什么好处和坏处?

What is the advantage and disadvantage of connection timeout=0?

而Connection Lifetime=0有什么用?

And what is the use of Connection Lifetime=0?

例如

(Database=TestDB;
 port=3306;
 Uid=usernameID;
 Pwd=myPassword;
 Server=192.168.10.1;
 Pooling=false;
 Connection Lifetime=0;
 Connection Timeout=0)

连接池有什么用?

推荐答案

超时是在您放弃之前等待请求响应的时间.TimeOut=0 意味着您将一直等待连接永远发生.很好,我想如果你连接到一个非常慢的服务器,如果需要 12 个小时来响应是正常的:-).一般是坏事.您想为请求设置某种合理的超时时间,这样您就可以意识到您的目标已经失败并继续您的生活.

Timeout is how long you wait for a response from a request before you give up. TimeOut=0 means you will keep waiting for the connection to occur forever. Good I guess if you are connecting to a really slow server that it is normal if it takes 12 hours to respond :-). Generally a bad thing. You want to put some kind of reasonable timeout on a request, so that you can realize your target is down and move on with your life.

连接生命周期 = 连接在被终止和重新创建之前的生命周期.生命周期为 0 意味着永远不会杀死和重新创建.通常不是一件坏事,因为杀死和重新创建连接很慢.通过各种错误,您的连接可能会陷入不稳定状态(例如在处理奇怪的 3 路事务时).但 99% 的情况下,最好将连接生命周期保持为无限.

Connection Lifetime = how long a connection lives before it is killed and recreated. A lifetime of 0 means never kill and recreate. Normally not a bad thing, because killing and recreating a connection is slow. Through various bugs your connections may get stuck in an unstable state (like when dealing with weird 3 way transactions).. but 99% of the time it is good to keep connection lifetime as infinite.

连接池是一种处理创建连接非常慢的事实的方法.因此,与其为每个请求建立一个新连接,不如使用一个包含 10 个预制连接的池.当你需要一个时,你借一个,使用它,然后返回.你可以调整池的大小来改变你的应用程序的行为方式.更大的池 = 更多的连接 = 更多的线程一次做一些事情,但这也可能压倒你正在做的事情.

Connection pooling is a way to deal with the fact that creating a connection is very slow. So rather than make a new connection for every request, instead have a pool of say, 10, premade connections. When you need one, you borrow one, use it, and return in. You can adjust the size of the pool to change how your app behaves. Bigger pool = more connections = more threads doing stuff at a time, but this could also overwhelm whatever you are doing.

总结:
ConnectionTimeout=0 不好,将其设为合理的值,例如 30 秒.
ConnectionLifetime=0 没问题
ConnectionPooling=disabled 不好,您可能会想要使用它.

In summary:
ConnectionTimeout=0 is bad, make it something reasonable like 30 seconds.
ConnectionLifetime=0 is okay
ConnectionPooling=disabled is bad, you will likely want to use it.

这篇关于连接超时和连接寿命的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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