Forum Stats

  • 3,827,527 Users
  • 2,260,790 Discussions
  • 7,897,291 Comments

Discussions

Understanding count of minimum idle connections to zero in connection pool

26111982
26111982 Member Posts: 21
Hi,

I would like to understand if there is any overhead of creating connections if we keep the minIdle to zero in a connection pool where the eviction thread is configured.

As per the understanding I have, it's the initial creation of connection to the database is expensive operation.In the case of connection pool,this is being done when the data source is instantiated initially and the connection objects are maintained till the data source is destroyed.

Please help me understand the behavior when the minIdle is made 0. Will it try to create a new connection when all the connections are evicted and cause an overhead than making minIdle >0.

Thanks in advance
Tagged:

Answers

  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy
    edited Apr 25, 2013 2:27AM
    I can advise you to use log4jdbc, it can give you logging about when connections are created and closed. That should paint a clear picture how your pool settings are behaving.
    it's the initial creation of connection to the database is expensive operation.
    Usually correct. How expensive depends on where the two machines live of course, a connection to a database running on the localhost is not going to be so expensive at all.
    In the case of connection pool,this is being done when the data source is instantiated initially and the connection objects are maintained till the data source is destroyed.
    Or until the idle timeout expires, if the pool has such a setting.
    Please help me understand the behavior when the minIdle is made 0. Will it try to create a new connection when all the connections are evicted and cause an overhead than making minIdle >0.
    There is not one pool implementation you know, you have to figure out which one you (or your application server) is using and then read its documentation to know how it will behave.
  • You haven't provided ANY info about what (or whose) connection pool you are talking about.
    >
    I would like to understand if there is any overhead of creating connections if we keep the minIdle to zero in a connection pool where the eviction thread is configured.
    >
    There is ALWAYS overhead in creating a connection. That has NOTHING to do with the setting of 'minIdle' or other parameters.
    >
    As per the understanding I have, it's the initial creation of connection to the database is expensive operation.
    >
    Yes - it is.
    >
    In the case of connection pool,this is being done when the data source is instantiated initially
    >
    Yes - and connections are also created when the current pool connections are all in use and the max number of connections for the pool has not been reached.

    The whole purpose of the pool is to try to maintain some 'spare' open connections so that the 'creation overhead' is absorbed by the pool itself and not at the time a connection is actually needed. So the number of connections will grow and shrink as connections are used and then remain unused for a configured period of time.
    >
    and the connection objects are maintained till the data source is destroyed.
    >
    NO - what data source are you even talking about? The connection objects are maintained per the pool configuration parameters while the pool exists and any connections still open when the pool is closed/destroyed are closed.
    >
    Please help me understand the behavior when the minIdle is made 0.
    >
    I'm not aware of any 'standard' defined behavior for minIdle reaching 0. What happens will depend on which/whose connection pool you are using. Don't use a connection pool if you don't want any to be idle. The whole purpose of a connection pool is to have a connection available when needed so that the overhead of creating a connection does not occur when the connection is actually needed. It is the POOL that absorbs the connection overhead.
    >
    Will it try to create a new connection when all the connections are evicted and cause an overhead than making minIdle >0.
    >
    That's the third time you've asked that same question.

    Use common sense. If a connection is needed and there aren't any in the pool what do you think will happen?

    Creating connections incurs overhead.
  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    26111982 wrote:
    As per the understanding I have, it's the initial creation of connection to the database is expensive operation.
    Which is different than saying it is significant. In a modern data center it isn't

    What it means is that in a high volume server in a modern data center that each server will be able to handle a certain percentage more of requests per second. But in such a scenario it seems unlikely that you would want a min pool size of zero anyways. Normally that is used for a server that doesn't handle a lot of traffic and which has periods of time when there is no traffic. Or when there are other factors, not performance, at play.

    You can use an eviction time when you want to insure that connections are 'fresh' even when in use.

    Tuning the connection pool is something that can only be done based on understanding the production request flow and the network topology for a specific deployment.

    Are you actually tuning something that you have measured or are you just exploring?
This discussion has been closed.