zoukankan      html  css  js  c++  java
  • 原来自己对连接字符串中Min Pool Size的理解是错误的

    原来自己对连接字符串中Min Pool Size的理解是错误的

    假设我们在一个ASP.NET应用程序的连接字符串中将Min Pool Size设置为30:

    <add name="cnblogs" connectionString="Data Source=.;Initial Catalog=cnblogs;Min Pool Size=30" providerName="System.Data.SqlClient"/>

    访问一下应用程序,然后用Windows Performance Monitor监测一下.NET Data Provider for SqlServer -> NumberOfPooledConnections(连接池中的连接总数):

     

    连接池中的连接总数不是30,而是60(见上图)。Min Pool Size=30,为什么NumberOfPooledConnections会是60?

    用Performance Monitor监测一下.NET Data Provider for SqlServer -> NumberOfActiveConnectionPools:

     

    原来有2个连接池(Connection Pool),60(NumberOfPooledConnections) = 30(Min Pool Size) × 2(NumberOfActiveConnectionPools),60就是这么来的。

    假如这时应用程序中需要的数据库连接数超过60,情况会怎么样呢?

    NumberOfPooledConnections会变为90,也就是说ADO.NET创建了一个新的连接池(NumberOfActiveConnectionPools由2变为3),并且这个连接池中包含30个连接(Min Pool Size = 30)。

    当发现这个时,我才知道自己以前对Min Pool Size的理解完全是错误的。以前以为只有一个连接池,当设置了Min Pool Size = 30,在初始化创建连接池时,会创建30个数据库连接;当30个连接不够用时,会需要多少就创建多少。

    而MSDN中对Min Pool Size的解释真够简单:The minimum number of connections maintained in the pool. 

    再次证明了实践出真知。

     
     
     
    标签: .NET
  • 相关阅读:
    The type new View.OnClickListener(){} must implement the inherited abstract method View.Onclicklis
    vue开发环境跨域
    浅析deep深度选择器
    模块化
    highlight-current-row无效的解决方法
    element-ui的table 在页面缩放时,出现的问题
    css变量
    节流和防抖
    promise详解
    正则表达式详解
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3024046.html
Copyright © 2011-2022 走看看