You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nir Dweck <ni...@vasco-de.com> on 2016/06/30 14:32:01 UTC

tomcat 7 connection pool validation interval

I am using tomcat connection  pool (tomcat 7) in my application (java application) to connect to a remote Oracle DB on an Azure machine. My connection pool configuration is as follow:

    PoolProperties p = new PoolProperties();
    p.setUrl(connString);
    p.setUsername(user);
    p.setPassword(password);
    p.setDriverClassName("oracle.jdbc.OracleDriver");
    p.setValidationQuery("SELECT 1 from dual");
    p.setValidationInterval(1 * 60000/2);
    p.setTimeBetweenEvictionRunsMillis(1 * 60000/2);
    p.setTestOnBorrow(true);
    p.setTestWhileIdle(true);
    p.setMinIdle(10);
    p.setInitialSize(10);
However looking at the capture file, I see that the connections are not checked every 30 seconds as I expected. One connection is checked correctly, the others are checked after 3 times the configuration (180 second). then again only some of the connections are checked and after a while it seems to stable on twice the configuration period (every 60 seconds).

I tested it with different configured time and different pool size, all had a instability period in which each time only part of the connections were checked and eventually it stabled on checks of all the connections every twice the configured time.
What am I missing?
Thanks,

Nir

Re: tomcat 7 connection pool validation interval

Posted by Phil Steitz <ph...@gmail.com>.
On 7/1/16 11:35 PM, Nir Dweck wrote:
> -----Original Message-----
> From: Phil Steitz [mailto:phil.steitz@gmail.com] 
> Sent: Friday, July 01, 2016 9:16 PM
> To: users@tomcat.apache.org
> Subject: Re: tomcat 7 connection pool validation interval
>
> On 7/1/16 7:14 AM, Nir Dweck wrote:
>> -----Original Message-----
>> From: Phil Steitz [mailto:phil.steitz@gmail.com]
>> Sent: Thursday, June 30, 2016 6:57 PM
>> To: Tomcat Users List
>> Subject: Re: tomcat 7 connection pool validation interval
>>
>>
>>
>>>>> On Jun 30, 2016, at 9:32 AM, Nir Dweck <ni...@vasco-de.com> wrote:
>>>>>
>>>>> I am using tomcat connection  pool (tomcat 7) in my application (java application) to connect to a remote Oracle DB on an Azure machine. My connection pool configuration is as follow:
>>>>>
>>>>>    PoolProperties p = new PoolProperties();
>>>>>    p.setUrl(connString);
>>>>>    p.setUsername(user);
>>>>>    p.setPassword(password);
>>>>>    p.setDriverClassName("oracle.jdbc.OracleDriver");
>>>>>    p.setValidationQuery("SELECT 1 from dual");
>>>>>    p.setValidationInterval(1 * 60000/2);
>>>>>    p.setTimeBetweenEvictionRunsMillis(1 * 60000/2);
>>>>>    p.setTestOnBorrow(true);
>>>>>    p.setTestWhileIdle(true);
>>>>>    p.setMinIdle(10);
>>>>>    p.setInitialSize(10);
>>>>> However looking at the capture file, I see that the connections are not checked every 30 seconds as I expected. One connection is checked correctly, the others are checked after 3 times the configuration (180 second). then again only some of the connections are checked and after a while it seems to stable on twice the configuration period (every 60 seconds).
>>>>>
>>>>> I tested it with different configured time and different pool size, all had a instability period in which each time only part of the connections were checked and eventually it stabled on checks of all the connections every twice the configured time.
>>>>> What am I missing?
>>>>> Thanks,
>>>> Most likely the connections not being tested are checked out to clients when the pool maintenance runs.  Assuming you are using the default DBCP pool, >>only idle connections (meaning waiting in the pool)  are tested by the maintenance thread.
>>>> Phil
>>> No, all connection are idle, but still looking at wireShark the validation query is sent every twice the TimeBetweenEvictionRunsMillis.
>> I am sorry I should have been more clear.  The term, "idle" is a little confusing here.  I should have said connections are only checked when they are not >checked out to client threads.  A connection can be "idle" from the DB standpoint but still checked out to a client.  A connection that is checked out to a >client will not be tested by the pool maintenance thread.  Are there clients using the pool while you are running this test?
>> I notice now a parameter not supported by DBCP, so I guess you must be using the tomcat-jdbc pool.  It looks to me like it defines "idle" the same way DBCP does - in other words above statements are true for that pool too.
>> It is also possible that setting validationInterval to a value <= timeBetweenEvictionRuns may cause some validations to be suppressed, since the former is a >max frequency.
>> Phil
> Hi Phil,
> I understood you correctly, none of the connections are held by any client. All are idle in the pool. I tried also setting timeBetweenEvictionRuns to half validationInterval, but still, the best I get is that the connections are validated in half the frequency I requested (every 2 * validationInterval). And yes I am using tomcat-jdbc pool.

Sorry I misunderstood you.  Try going the other way - making sure
that validationInterval >> timeBetweenEvictionRuns, or get rid of
the validationInterval parameter altogether.  The validationInterval
setting is designed to *suppress* excess validation - i.e., to make
sure that connections are not validated too frequently.  See the
description of this parameter in [1].

Phil
[1]
https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Tomcat_JDBC_Enhanced_Attributes

>  
> Nir
>>>  
>> Nir
>>
>>> Nir
>> ---------------------------------------------------------------------
>> 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
>
>
> ---------------------------------------------------------------------
> 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: tomcat 7 connection pool validation interval

Posted by Nir Dweck <ni...@vasco-de.com>.
-----Original Message-----
From: Phil Steitz [mailto:phil.steitz@gmail.com] 
Sent: Friday, July 01, 2016 9:16 PM
To: users@tomcat.apache.org
Subject: Re: tomcat 7 connection pool validation interval

On 7/1/16 7:14 AM, Nir Dweck wrote:
> -----Original Message-----
> From: Phil Steitz [mailto:phil.steitz@gmail.com]
> Sent: Thursday, June 30, 2016 6:57 PM
> To: Tomcat Users List
> Subject: Re: tomcat 7 connection pool validation interval
>
>
>
>>>> On Jun 30, 2016, at 9:32 AM, Nir Dweck <ni...@vasco-de.com> wrote:
>>>>
>>>> I am using tomcat connection  pool (tomcat 7) in my application (java application) to connect to a remote Oracle DB on an Azure machine. My connection pool configuration is as follow:
>>>>
>>>>    PoolProperties p = new PoolProperties();
>>>>    p.setUrl(connString);
>>>>    p.setUsername(user);
>>>>    p.setPassword(password);
>>>>    p.setDriverClassName("oracle.jdbc.OracleDriver");
>>>>    p.setValidationQuery("SELECT 1 from dual");
>>>>    p.setValidationInterval(1 * 60000/2);
>>>>    p.setTimeBetweenEvictionRunsMillis(1 * 60000/2);
>>>>    p.setTestOnBorrow(true);
>>>>    p.setTestWhileIdle(true);
>>>>    p.setMinIdle(10);
>>>>    p.setInitialSize(10);
>>>> However looking at the capture file, I see that the connections are not checked every 30 seconds as I expected. One connection is checked correctly, the others are checked after 3 times the configuration (180 second). then again only some of the connections are checked and after a while it seems to stable on twice the configuration period (every 60 seconds).
>>>>
>>>> I tested it with different configured time and different pool size, all had a instability period in which each time only part of the connections were checked and eventually it stabled on checks of all the connections every twice the configured time.
>>>> What am I missing?
>>>> Thanks,
>>> Most likely the connections not being tested are checked out to clients when the pool maintenance runs.  Assuming you are using the default DBCP pool, >>only idle connections (meaning waiting in the pool)  are tested by the maintenance thread.
>>> Phil
>> No, all connection are idle, but still looking at wireShark the validation query is sent every twice the TimeBetweenEvictionRunsMillis.
>
>I am sorry I should have been more clear.  The term, "idle" is a little confusing here.  I should have said connections are only checked when they are not >checked out to client threads.  A connection can be "idle" from the DB standpoint but still checked out to a client.  A connection that is checked out to a >client will not be tested by the pool maintenance thread.  Are there clients using the pool while you are running this test?

>I notice now a parameter not supported by DBCP, so I guess you must be using the tomcat-jdbc pool.  It looks to me like it defines "idle" the same way DBCP does - in other words above statements are true for that pool too.

>It is also possible that setting validationInterval to a value <= timeBetweenEvictionRuns may cause some validations to be suppressed, since the former is a >max frequency.

>Phil
Hi Phil,
I understood you correctly, none of the connections are held by any client. All are idle in the pool. I tried also setting timeBetweenEvictionRuns to half validationInterval, but still, the best I get is that the connections are validated in half the frequency I requested (every 2 * validationInterval). And yes I am using tomcat-jdbc pool.
 
Nir
>>  
>
> Nir
>
>> Nir
> ---------------------------------------------------------------------
> 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


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


Re: tomcat 7 connection pool validation interval

Posted by Phil Steitz <ph...@gmail.com>.
On 7/1/16 7:14 AM, Nir Dweck wrote:
> -----Original Message-----
> From: Phil Steitz [mailto:phil.steitz@gmail.com] 
> Sent: Thursday, June 30, 2016 6:57 PM
> To: Tomcat Users List
> Subject: Re: tomcat 7 connection pool validation interval
>
>
>
>>> On Jun 30, 2016, at 9:32 AM, Nir Dweck <ni...@vasco-de.com> wrote:
>>>
>>> I am using tomcat connection  pool (tomcat 7) in my application (java application) to connect to a remote Oracle DB on an Azure machine. My connection pool configuration is as follow:
>>>
>>>    PoolProperties p = new PoolProperties();
>>>    p.setUrl(connString);
>>>    p.setUsername(user);
>>>    p.setPassword(password);
>>>    p.setDriverClassName("oracle.jdbc.OracleDriver");
>>>    p.setValidationQuery("SELECT 1 from dual");
>>>    p.setValidationInterval(1 * 60000/2);
>>>    p.setTimeBetweenEvictionRunsMillis(1 * 60000/2);
>>>    p.setTestOnBorrow(true);
>>>    p.setTestWhileIdle(true);
>>>    p.setMinIdle(10);
>>>    p.setInitialSize(10);
>>> However looking at the capture file, I see that the connections are not checked every 30 seconds as I expected. One connection is checked correctly, the others are checked after 3 times the configuration (180 second). then again only some of the connections are checked and after a while it seems to stable on twice the configuration period (every 60 seconds).
>>>
>>> I tested it with different configured time and different pool size, all had a instability period in which each time only part of the connections were checked and eventually it stabled on checks of all the connections every twice the configured time.
>>> What am I missing?
>>> Thanks,
>> Most likely the connections not being tested are checked out to clients when the pool maintenance runs.  Assuming you are using the default DBCP pool, >only idle connections (meaning waiting in the pool)  are tested by the maintenance thread.
>> Phil
> No, all connection are idle, but still looking at wireShark the validation query is sent every twice the TimeBetweenEvictionRunsMillis.

I am sorry I should have been more clear.  The term, "idle" is a
little confusing here.  I should have said connections are only
checked when they are not checked out to client threads.  A
connection can be "idle" from the DB standpoint but still checked
out to a client.  A connection that is checked out to a client will
not be tested by the pool maintenance thread.  Are there clients
using the pool while you are running this test?

I notice now a parameter not supported by DBCP, so I guess you must
be using the tomcat-jdbc pool.  It looks to me like it defines
"idle" the same way DBCP does - in other words above statements are
true for that pool too.

It is also possible that setting validationInterval to a value <=
timeBetweenEvictionRuns may cause some validations to be suppressed,
since the former is a max frequency.

Phil
>  
>
> Nir
>
>> Nir
> ---------------------------------------------------------------------
> 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: tomcat 7 connection pool validation interval

Posted by Nir Dweck <ni...@vasco-de.com>.
-----Original Message-----
From: Phil Steitz [mailto:phil.steitz@gmail.com] 
Sent: Thursday, June 30, 2016 6:57 PM
To: Tomcat Users List
Subject: Re: tomcat 7 connection pool validation interval



>> On Jun 30, 2016, at 9:32 AM, Nir Dweck <ni...@vasco-de.com> wrote:
>> 
>> I am using tomcat connection  pool (tomcat 7) in my application (java application) to connect to a remote Oracle DB on an Azure machine. My connection pool configuration is as follow:
>> 
>>    PoolProperties p = new PoolProperties();
>>    p.setUrl(connString);
>>    p.setUsername(user);
>>    p.setPassword(password);
>>    p.setDriverClassName("oracle.jdbc.OracleDriver");
>>    p.setValidationQuery("SELECT 1 from dual");
>>    p.setValidationInterval(1 * 60000/2);
>>    p.setTimeBetweenEvictionRunsMillis(1 * 60000/2);
>>    p.setTestOnBorrow(true);
>>    p.setTestWhileIdle(true);
>>    p.setMinIdle(10);
>>    p.setInitialSize(10);
>> However looking at the capture file, I see that the connections are not checked every 30 seconds as I expected. One connection is checked correctly, the others are checked after 3 times the configuration (180 second). then again only some of the connections are checked and after a while it seems to stable on twice the configuration period (every 60 seconds).
>> 
>> I tested it with different configured time and different pool size, all had a instability period in which each time only part of the connections were checked and eventually it stabled on checks of all the connections every twice the configured time.
> >What am I missing?
> >Thanks,

>Most likely the connections not being tested are checked out to clients when the pool maintenance runs.  Assuming you are using the default DBCP pool, >only idle connections (meaning waiting in the pool)  are tested by the maintenance thread.

>Phil

No, all connection are idle, but still looking at wireShark the validation query is sent every twice the TimeBetweenEvictionRunsMillis. 

Nir

> 
> Nir

---------------------------------------------------------------------
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: tomcat 7 connection pool validation interval

Posted by Phil Steitz <ph...@gmail.com>.

> On Jun 30, 2016, at 9:32 AM, Nir Dweck <ni...@vasco-de.com> wrote:
> 
> I am using tomcat connection  pool (tomcat 7) in my application (java application) to connect to a remote Oracle DB on an Azure machine. My connection pool configuration is as follow:
> 
>    PoolProperties p = new PoolProperties();
>    p.setUrl(connString);
>    p.setUsername(user);
>    p.setPassword(password);
>    p.setDriverClassName("oracle.jdbc.OracleDriver");
>    p.setValidationQuery("SELECT 1 from dual");
>    p.setValidationInterval(1 * 60000/2);
>    p.setTimeBetweenEvictionRunsMillis(1 * 60000/2);
>    p.setTestOnBorrow(true);
>    p.setTestWhileIdle(true);
>    p.setMinIdle(10);
>    p.setInitialSize(10);
> However looking at the capture file, I see that the connections are not checked every 30 seconds as I expected. One connection is checked correctly, the others are checked after 3 times the configuration (180 second). then again only some of the connections are checked and after a while it seems to stable on twice the configuration period (every 60 seconds).
> 
> I tested it with different configured time and different pool size, all had a instability period in which each time only part of the connections were checked and eventually it stabled on checks of all the connections every twice the configured time.
> What am I missing?
> Thanks,

Most likely the connections not being tested are checked out to clients when the pool maintenance runs.  Assuming you are using the default DBCP pool, only idle connections (meaning waiting in the pool)  are tested by the maintenance thread.

Phil
> 
> Nir

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


Re: tomcat 7 connection pool validation interval

Posted by Keiichi Fujino <kf...@apache.org>.
2016-06-30 23:32 GMT+09:00 Nir Dweck <ni...@vasco-de.com>:

> I am using tomcat connection  pool (tomcat 7) in my application (java
> application) to connect to a remote Oracle DB on an Azure machine. My
> connection pool configuration is as follow:
>
>     PoolProperties p = new PoolProperties();
>     p.setUrl(connString);
>     p.setUsername(user);
>     p.setPassword(password);
>     p.setDriverClassName("oracle.jdbc.OracleDriver");
>     p.setValidationQuery("SELECT 1 from dual");
>     p.setValidationInterval(1 * 60000/2);
>     p.setTimeBetweenEvictionRunsMillis(1 * 60000/2);
>     p.setTestOnBorrow(true);
>     p.setTestWhileIdle(true);
>     p.setMinIdle(10);
>     p.setInitialSize(10);
> However looking at the capture file, I see that the connections are not
> checked every 30 seconds as I expected. One connection is checked
> correctly, the others are checked after 3 times the configuration (180
> second). then again only some of the connections are checked and after a
> while it seems to stable on twice the configuration period (every 60
> seconds).
>
> I tested it with different configured time and different pool size, all
> had a instability period in which each time only part of the connections
> were checked and eventually it stabled on checks of all the connections
> every twice the configured time.
> What am I missing?
> Thanks,
>

I reproduced this.

I found the following code in the
org.apache.tomcat.jdbc.pool.ConnectionPool.
===
protected static class PoolCleaner extends TimerTask {
// snip

@Override
public void run() {
    ConnectionPool pool = this.pool.get();
    if (pool == null) {
        stopRunning();
    } else if (!pool.isClosed() &&
            (System.currentTimeMillis() - lastRun) > sleepTime) {
        lastRun = System.currentTimeMillis();
        try {
        // snip
===
Regardless of the scheduled PoolCleaner, (System.currentTimeMillis() -
lastRun) > sleepTime) is called.

Since PoolCleaner has been scheduled by the Timer#scheduleAtFixedRate,
This code probably is necessary in order to avoid a continuous calling of
PoolCleaner when the previous task was delayed.
However, This code causes the unintended skip of PoolCleaner.

I plan to fix the followings if there is no objection.
-Remove the "System.currentTimeMillis() - lastRun) > sleepTime".
-The scheduleAtFixedRate method changes to the schedule method.




>
> Nir
>
> --
> Keiichi.Fujino
>