gpt4 book ai didi

c# - 数据库连接池如何影响性能?

转载 作者:行者123 更新时间:2023-11-30 13:29:22 24 4
gpt4 key购买 nike

我正在使用 .Net 2.0 + SQL Server 2005 Enterprise + VSTS 2008 + C# + ADO.Net 来开发 ASP.Net Web 应用程序。 ASP.Net Web 应用程序是以数据库为中心/驱动的。我想知道在ADO.Net连接字符串设置中打开/关闭线程池设置时性能有哪些差异,是否有性能引用数据?性能我指的是可以支持的并发连接数和从 ADO.Net 客户端执行的特定 SQL 命令的执行时间?

在此先感谢,乔治

最佳答案

我手头没有任何性能统计数据,但在使用连接池时可能会有一句警告:你可能会得到太多的小池,而不是一个大池。

ADO.NET 将为

创建一个新的连接池
  • 每个连接字符串;这也是非常挑剔的 - 如果您有两个连接字符串,即使只是一个空格或其他东西也不同,这些连接字符串被认为是两个单独的连接字符串,并将导致单独的连接池创建

  • 如果使用“集成安全”(可信连接)设置,则针对每个 Windows 凭据

所以如果你有一个像这样的连接字符串

server=MyDBServer;database=MyDatabase;integrated security=SSPI;

将为每个可区分的用户创建一个连接池 - 这相当违反直觉,但事实就是如此(并且它不能被影响/关闭)。

查看 MSDN docs有关 ADO.NET 连接池的详细信息:

When a connection is first opened, a connection pool is created based on an exact matching algorithm that associates the pool with the connection string in the connection. Each connection pool is associated with a distinct connection string. When a new connection is opened, if the connection string is not an exact match to an existing pool, a new pool is created. Connections are pooled per process, per application domain, per connection string and when integrated security is used, per Windows identity. Connection strings must also be an exact match; keywords supplied in a different order for the same connection will be pooled separately.

此外,如果您有这两个连接字符串:

server=MyDBServer;database=MyDatabase;user id=tom;pwd=top$secret

server=MyDBServer;database=MyDatabase;user id=tom; pwd=top$secret;

那些被认为是不同连接字符串,因此将创建两个独立的连接池。

在尝试测量连接池的效果时,需要注意这一点!

马克

关于c# - 数据库连接池如何影响性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1645297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com