连接池(Connection pooling)
Connection pooling is a complex beast, let me try to explain how Connection
pooling works.
Note that each provider may use different protocols and heuristics, here I'm
only talking about the SQL client provider.
Connection pools are per 'application domain' containers who are maintained
on a per db 'instance' per security context basis. That means that multiple
pools can exist in a process/application domain at the same time depending
on the instance and security context. Note also that two different AD's
cannot share the same pool.
A pool is established the first time you create a connection with a certain
instance using specific credentials. This is the most costly operation (say
>150 msec's.) as it involves :
- the creation of the connection pool,
- an authentication handshake (a network logon) and,
- the establishment of a physical network connection.
When your application opens a subsequent connection with the same DB
instance using the same credentials, the provider will search the pool for a
free connection entry and return this one to your application. This is a
very cheap operation (a few hundred µsec's. or less) as it doesn't involve
any security handshake nor physical connection.
If no free entry exists in the pool, a new connection will be created with
the server, no authentication has to be done as long as a security context
exists between the client and the server, such contexts is maintained,by the
provider, per existing pool.
where it waits (a reconnect time-out period) for a new open request from
your application to the same db instance using the same security context. If
no connection arrives before the 'reconnect time-out' expires, the
connection with the DB is closed and the entry removed from the pool. If
this entry was the last entry in the pool, the next connection request will
be more costly as the provider needs to establish a physical connection with
the db instance (can take >20 msec's. over TCP/IP), but it won't be as
costly as the first connection at pool creation time.
以上是 Willy Denoyette [MVP] 对 SQL client provider 中提供的连接池的描述。
[ 来源:Google Groups ]
posted on 2006-05-17 09:38 Easy Company 阅读(425) 评论(0) 收藏 举报