You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Xavier Poinsard <xp...@openpricer.com> on 2009/11/16 17:04:20 UTC

jdbc-pool ignoring minIdle ?

Hi all,

I have seen a strange behaviour with the new Tomcat jdbc-pool (1.0.7.1).
It seems to ignore the minIdle parameter.
I have been able to reproduce it with a simple program.
minIdle is set to 5 and after a few seconds, I don't have any idle 
connection left.
Could anybody confirm the bug or point the mistake in my configuration ?
Thanks in advance.
Best regards,
Xavier.

Here is the test program :

public class TestPool {
	public static void main(String[] args) throws Exception {
		PoolProperties p = new PoolProperties();
		p.setUrl("jdbc:postgresql:XXX");
		p.setDriverClassName("org.postgresql.Driver");
		p.setUsername("login");
		p.setPassword("password");
		p.setDefaultAutoCommit(false);
		p.setJmxEnabled(false);
		p.setTestWhileIdle(true);
		p.setTestOnBorrow(true);
		p.setValidationQuery("SELECT 1");
		p.setTestOnReturn(false);
		p.setMaxActive(30);
		p.setInitialSize(5);
		p.setMaxWait(200000);
		p.setMaxAge(43200);
		p.setMinIdle(5);
		p.setMaxIdle(15);
		p.setLogAbandoned(true);
		p.setRemoveAbandoned(true);
		p.setRemoveAbandonedTimeout(300);
		p.setJdbcInterceptors("StatementFinalizer;ResetAbandonedTimer");

		DataSource datasource = new DataSource();
		datasource.setPoolProperties(p);
		Connection con = null;
		try {
			while(true){
				con = datasource.getConnection();
				Statement st = con.createStatement();
				ResultSet rs = st.executeQuery("select count(*) from users");
				rs.close();
				st.close();
				System.out.println("Pool size : " +datasource.getSize());
				System.out.println("Idle : " +datasource.getIdle());
				System.out.println("Active : " +datasource.getActive());
				con.close();
				Thread.sleep(1000);
			}
		} finally {
			if (con!=null) try {con.close();}catch (Exception ignore) {}
		}
	}
}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jdbc-pool ignoring minIdle ?

Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
hi Xavier, if you don't configure a maxAge, then you will get the 
behavior the way you expected it.
However, the maxAge has a very unique functionality, and that is to 
close a DB session regardless of usage after a certain amount of time.
You see, if your test case had five or more threads, you'd see 5 idle 
connections. The way the pool is sizing itself is optimal for the 
configuration you picked.

Filip

On 11/17/2009 03:51 AM, Xavier Poinsard wrote:
> Hi Filip,
>
> Thanks for this precision.
> Based on the description on the minIdle parameter, I was thinking the 
> validation query failure was the only case where the pool can have 
> less connections than minIdle.
> Maybe you could add a note about this or change the behaviour.
>
> Best regards,
> Xavier.
>
> Filip Hanik - Dev Lists a écrit :
>> hi Xavier, the pool is not ignoring the minIdle flag, but you have 
>> configured
>>         p.setMaxAge(43200);
>>
>> This means,that if a connection has been connected longer than this, 
>> next time you call con.close() it will be closed and not returned to 
>> the pool.
>>
>> The connection pool itself at this point in time will not create a 
>> new connection. Only when you actually call getConnection() may 
>> another connection be created.
>>
>> Filip
>>
>>
>> On 11/16/2009 09:04 AM, Xavier Poinsard wrote:
>>> Hi all,
>>>
>>> I have seen a strange behaviour with the new Tomcat jdbc-pool 
>>> (1.0.7.1).
>>> It seems to ignore the minIdle parameter.
>>> I have been able to reproduce it with a simple program.
>>> minIdle is set to 5 and after a few seconds, I don't have any idle 
>>> connection left.
>>> Could anybody confirm the bug or point the mistake in my 
>>> configuration ?
>>> Thanks in advance.
>>> Best regards,
>>> Xavier.
>>>
>>> Here is the test program :
>>>
>>> public class TestPool {
>>>     public static void main(String[] args) throws Exception {
>>>         PoolProperties p = new PoolProperties();
>>>         p.setUrl("jdbc:postgresql:XXX");
>>>         p.setDriverClassName("org.postgresql.Driver");
>>>         p.setUsername("login");
>>>         p.setPassword("password");
>>>         p.setDefaultAutoCommit(false);
>>>         p.setJmxEnabled(false);
>>>         p.setTestWhileIdle(true);
>>>         p.setTestOnBorrow(true);
>>>         p.setValidationQuery("SELECT 1");
>>>         p.setTestOnReturn(false);
>>>         p.setMaxActive(30);
>>>         p.setInitialSize(5);
>>>         p.setMaxWait(200000);
>>>         p.setMaxAge(43200);
>>>         p.setMinIdle(5);
>>>         p.setMaxIdle(15);
>>>         p.setLogAbandoned(true);
>>>         p.setRemoveAbandoned(true);
>>>         p.setRemoveAbandonedTimeout(300);
>>>         
>>> p.setJdbcInterceptors("StatementFinalizer;ResetAbandonedTimer");
>>>
>>>         DataSource datasource = new DataSource();
>>>         datasource.setPoolProperties(p);
>>>         Connection con = null;
>>>         try {
>>>             while(true){
>>>                 con = datasource.getConnection();
>>>                 Statement st = con.createStatement();
>>>                 ResultSet rs = st.executeQuery("select count(*) from 
>>> users");
>>>                 rs.close();
>>>                 st.close();
>>>                 System.out.println("Pool size : " 
>>> +datasource.getSize());
>>>                 System.out.println("Idle : " +datasource.getIdle());
>>>                 System.out.println("Active : " 
>>> +datasource.getActive());
>>>                 con.close();
>>>                 Thread.sleep(1000);
>>>             }
>>>         } finally {
>>>             if (con!=null) try {con.close();}catch (Exception 
>>> ignore) {}
>>>         }
>>>     }
>>> }
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jdbc-pool ignoring minIdle ?

Posted by Xavier Poinsard <xp...@openpricer.com>.
Hi Filip,

Thanks for this precision.
Based on the description on the minIdle parameter, I was thinking the 
validation query failure was the only case where the pool can have less 
connections than minIdle.
Maybe you could add a note about this or change the behaviour.

Best regards,
Xavier.

Filip Hanik - Dev Lists a écrit :
> hi Xavier, the pool is not ignoring the minIdle flag, but you have 
> configured
>         p.setMaxAge(43200);
> 
> This means,that if a connection has been connected longer than this, 
> next time you call con.close() it will be closed and not returned to the 
> pool.
> 
> The connection pool itself at this point in time will not create a new 
> connection. Only when you actually call getConnection() may another 
> connection be created.
> 
> Filip
> 
> 
> On 11/16/2009 09:04 AM, Xavier Poinsard wrote:
>> Hi all,
>>
>> I have seen a strange behaviour with the new Tomcat jdbc-pool (1.0.7.1).
>> It seems to ignore the minIdle parameter.
>> I have been able to reproduce it with a simple program.
>> minIdle is set to 5 and after a few seconds, I don't have any idle 
>> connection left.
>> Could anybody confirm the bug or point the mistake in my configuration ?
>> Thanks in advance.
>> Best regards,
>> Xavier.
>>
>> Here is the test program :
>>
>> public class TestPool {
>>     public static void main(String[] args) throws Exception {
>>         PoolProperties p = new PoolProperties();
>>         p.setUrl("jdbc:postgresql:XXX");
>>         p.setDriverClassName("org.postgresql.Driver");
>>         p.setUsername("login");
>>         p.setPassword("password");
>>         p.setDefaultAutoCommit(false);
>>         p.setJmxEnabled(false);
>>         p.setTestWhileIdle(true);
>>         p.setTestOnBorrow(true);
>>         p.setValidationQuery("SELECT 1");
>>         p.setTestOnReturn(false);
>>         p.setMaxActive(30);
>>         p.setInitialSize(5);
>>         p.setMaxWait(200000);
>>         p.setMaxAge(43200);
>>         p.setMinIdle(5);
>>         p.setMaxIdle(15);
>>         p.setLogAbandoned(true);
>>         p.setRemoveAbandoned(true);
>>         p.setRemoveAbandonedTimeout(300);
>>         p.setJdbcInterceptors("StatementFinalizer;ResetAbandonedTimer");
>>
>>         DataSource datasource = new DataSource();
>>         datasource.setPoolProperties(p);
>>         Connection con = null;
>>         try {
>>             while(true){
>>                 con = datasource.getConnection();
>>                 Statement st = con.createStatement();
>>                 ResultSet rs = st.executeQuery("select count(*) from 
>> users");
>>                 rs.close();
>>                 st.close();
>>                 System.out.println("Pool size : " +datasource.getSize());
>>                 System.out.println("Idle : " +datasource.getIdle());
>>                 System.out.println("Active : " +datasource.getActive());
>>                 con.close();
>>                 Thread.sleep(1000);
>>             }
>>         } finally {
>>             if (con!=null) try {con.close();}catch (Exception ignore) {}
>>         }
>>     }
>> }
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jdbc-pool ignoring minIdle ?

Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
hi Xavier, the pool is not ignoring the minIdle flag, but you have 
configured
         p.setMaxAge(43200);

This means,that if a connection has been connected longer than this, 
next time you call con.close() it will be closed and not returned to the 
pool.

The connection pool itself at this point in time will not create a new 
connection. Only when you actually call getConnection() may another 
connection be created.

Filip


On 11/16/2009 09:04 AM, Xavier Poinsard wrote:
> Hi all,
>
> I have seen a strange behaviour with the new Tomcat jdbc-pool (1.0.7.1).
> It seems to ignore the minIdle parameter.
> I have been able to reproduce it with a simple program.
> minIdle is set to 5 and after a few seconds, I don't have any idle 
> connection left.
> Could anybody confirm the bug or point the mistake in my configuration ?
> Thanks in advance.
> Best regards,
> Xavier.
>
> Here is the test program :
>
> public class TestPool {
>     public static void main(String[] args) throws Exception {
>         PoolProperties p = new PoolProperties();
>         p.setUrl("jdbc:postgresql:XXX");
>         p.setDriverClassName("org.postgresql.Driver");
>         p.setUsername("login");
>         p.setPassword("password");
>         p.setDefaultAutoCommit(false);
>         p.setJmxEnabled(false);
>         p.setTestWhileIdle(true);
>         p.setTestOnBorrow(true);
>         p.setValidationQuery("SELECT 1");
>         p.setTestOnReturn(false);
>         p.setMaxActive(30);
>         p.setInitialSize(5);
>         p.setMaxWait(200000);
>         p.setMaxAge(43200);
>         p.setMinIdle(5);
>         p.setMaxIdle(15);
>         p.setLogAbandoned(true);
>         p.setRemoveAbandoned(true);
>         p.setRemoveAbandonedTimeout(300);
>         p.setJdbcInterceptors("StatementFinalizer;ResetAbandonedTimer");
>
>         DataSource datasource = new DataSource();
>         datasource.setPoolProperties(p);
>         Connection con = null;
>         try {
>             while(true){
>                 con = datasource.getConnection();
>                 Statement st = con.createStatement();
>                 ResultSet rs = st.executeQuery("select count(*) from 
> users");
>                 rs.close();
>                 st.close();
>                 System.out.println("Pool size : " +datasource.getSize());
>                 System.out.println("Idle : " +datasource.getIdle());
>                 System.out.println("Active : " +datasource.getActive());
>                 con.close();
>                 Thread.sleep(1000);
>             }
>         } finally {
>             if (con!=null) try {con.close();}catch (Exception ignore) {}
>         }
>     }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org