我在许多网络语言中看到的一个常见问题是,数据库连接需要关闭,否则总连接数会逐渐增加,然后以任何形式停止。
HTTP是无状态的,当请求完成处理时,为什么这些语言不能丢弃请求打开的任何连接?有什么正当理由可以让它继续开放吗?
我在许多网络语言中看到的一个常见问题是,数据库连接需要关闭,否则总连接数会逐渐增加,然后以任何形式停止。
HTTP是无状态的,当请求完成处理时,为什么这些语言不能丢弃请求打开的任何连接?有什么正当理由可以让它继续开放吗?
因为打开、验证和授权访问数据库的成本相当昂贵。这就是为什么通常每个人都使用数据库连接池的原因。当请求处理程序从池中提取可用的已打开连接时,连接仍处于打开状态。当一个人关闭一个连接时,真正发生的事情是该连接被释放给其他人使用。
要回答。。。
why can t these languages just drop any connections that request opened? Are there any legitimate reasons for why you might keep it open?
请求完成后,连接可能会保持打开状态,并用于其他目的。例如,数据的异步更新。但我同意你的看法,在90%的情况下,当请求完成时,打开的连接应该返回到池中。根据您使用的Web框架(Spring、DJANGO…),可以配置或至少以最少的工作量实现这种行为。
在关闭http连接的同时检查打开的连接会带来更多的开销,所以我想这就是为什么有些语言默认情况下不关闭它的原因。
如果不显式关闭它,则必须由垃圾收集器来完成,这可能需要一段时间。
$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...
I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...
I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...
Does anybody know if it is possible to move some (not all) users from one ASP.NET membership database to another? (for the purposes of migrating some users to another database on another machine, but ...
Is it because of size? By the way, what is the limit of the size?
I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...
For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...
I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...