design patterns - Is there any reason for an object pool to not be treated as a singleton? -


i don't mean implemented using singleton pattern, rather, having , using 1 instance of pool. don't idea of having 1 pool (or 1 per pooled type). however, can't come concrete situations there's advantage multiple pools for mutable types, @ least not single pool can function well.

what advantages there having multiple pools on singleton pool?

what advantages there having multiple pools on singleton pool?

i supposed object pools use, threadpool, implemented singletons simplicity: in that, designers of pools didn't see purpose in multiple-instance pools either.

however, there handful of places have multiple pools: iis application pools , database connection pools.

app pools

in iis, can configure multiple application pools, related web applications run in own pool. there couple of advantages design, , advantages can generalize pool implementations outside of iis:

  • multiple object pools allow degree of isolation, error in 1 pool should not have impact on objects in other pools.

  • each pool can run under different user, gives different levels of security based on application pool.

  • each pool can have different handler errors.

  • each pool can run different version of .net framework.

  • each pool can have own http timeout.

connection pools

in sql server, multiple calls database use connection pooling avoid overhead of creating new database connection on every query, sql server creates new pool per connection string. imagine rationale behind design follows:

  • each pool holds connection specific database instance. if there 1 pool containing connections, need search through connections until finds connection matching connection string you've requested. since there multiple pools per connection string, easier pull first available connection particular pool without searching through other connections.

  • in other words, suspect sql server uses multiple connection pools optimization grab database connection.

  • i can imagine of connections share resources specific connection pool, may not possible single pool. example, can specify maximum connection pool size per connection string; may not able control number of simultaneous connections particular database using single-pool design.

how design pool

you can't choose whether have multiple pools or single pool without looking @ need design.

if have simple object pool, might able away singleton design. if need flexibility, customization, or maybe have unique setup object pool distributed across multiple processes or machines, benefit n-gleton design instead.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -