What are the benefits of having multiple pools through a singleton pool?
I suggested that most of the object pools we use, such as ThreadPool, are implemented as single for simplicity: the developers of these pools also did not see the target in multi-instance pools.
However, there are a few places where we really have several pools: IIS application pools and database connection pools.
Application pools
In IIS, you can configure multiple application pools so that their associated web applications run in their own pool. There are several advantages to this design, and the benefits can be generalized to implement a pool outside of IIS:
Several object pools allow some degree of isolation, so an error in one pool should not affect objects in other pools.
Each pool can work under a different user, which gives you different levels of security based on your application pool.
Each pool may have a different error handler.
Each pool can work with a different version of the .NET platform.
Each pool can have its own HTTP timeout.
Connection pools
In SQL Server, several database calls use the connection pool to avoid the overhead of creating a new database connection for each query, but SQL Server creates a new pool on the connection string . I believe the rationale for this design is as follows:
Each pool has a connection to a specific database instance. If there was only one pool containing all the connections, then he would need to search all the connections until he found the connection corresponding to the requested connection string. Since there are several pools in each connection string, it is easiest to pull the first available connection from this particular pool without searching through other connections.
In other words, I suspect that SQL Server uses multiple connection pools as an optimization to quickly connect to the database.
I can also assume that all of these connections probably have some resources specific to their connection pool, which may not be possible in the same pool. For example, you can specify the maximum connection pool size for each connection string; You will not be able to control the number of simultaneous connections to a specific database using a single pool design.
How to create a pool
You cannot choose whether to have multiple pools or one pool without looking at what you really need from your design.
If you have a very simple pool of objects, you can get away with the singleton design. If you really need additional flexibility, customization, or maybe you really have a unique customization, such as an object pool distributed across several processes or machines, you will certainly benefit from the development of n-gleton.
Juliet
source share