orientechnologies/orientdb — pull request #1814 by fabriziofortino (2013-11-11 17:05:33+00:00)
Title: added idleTimeout with eviction handling for connection pools

This is a really simple implementation of eviction for connections that stay idle in the pool for a minimum time. In this way the pools can be dynamically resized if the connections are not used for a certain amount of time.

Optionally, one may configure the pool to examine and possibly evict connections as they sit idle in the pool. This is performed by an "idle object eviction" task. Caution should be used when configuring this optional feature. Eviction runs contend with client threads for access to connections in the pool, so if they run too frequently performance issues may result.

This can be an important feature for an application with multiple databases / pools (eg: multi tenant application with one database per tenant) that has periodic peak loads. With this implementation the connections are dynamically evicted when are idle for a certain amount of time.

The following code:

```
pool = new ODatabaseDocumentPool();
pool.setup(0, 50, 120000, 600000);
```

runs the Evictor task every 10 minutes closing the connections that are idle for at least 2 minutes.

For a more fine grained handling of pools I would consider the use of Apache Common Pools (http://commons.apache.org/proper/commons-pool/index.html) which gives additional features like LIFO/FIFO pool management or JMX management / monitoring and other useful stuff (see here http://commons.apache.org/proper/commons-pool/api-1.6/index.html).