需求:在.Net 中我想有一个连接池并且使连接一直处于被打开状态,比如我有 100 个已经被打开的连接,这样流量过来的时候就不需要新创建 SqlConnection 然后再 Open(这个操作 Latency 太高了),有类似实现的 SDK 嘛
1
jtwor 2023-04-13 17:29:49 +08:00
|
2
forgottencoast 2023-04-15 21:33:11 +08:00
连接池是内置的,你只需要根据你的需求进行配置就可以了。
详见: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-connection-pooling Connection pooling reduces the number of times that new connections must be opened. The pooler maintains ownership of the physical connection. It manages connections by keeping alive a set of active connections for each given connection configuration. Whenever a user calls Open on a connection, the pooler looks for an available connection in the pool. If a pooled connection is available, it returns it to the caller instead of opening a new connection. When the application calls Close on the connection, the pooler returns it to the pooled set of active connections instead of closing it. Once the connection is returned to the pool, it is ready to be reused on the next Open call. |