Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WFwFs-0004l6-1m for pgsql-jdbc@arkaria.postgresql.org; Wed, 19 Feb 2014 01:47:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WFwFr-000475-EG for pgsql-jdbc@arkaria.postgresql.org; Wed, 19 Feb 2014 01:47:19 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WFwFp-00046o-JD for pgsql-jdbc@postgresql.org; Wed, 19 Feb 2014 01:47:18 +0000 Received: from [58.58.27.50] (helo=mail.highgo.com.cn) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WFwFa-0003ap-F8 for pgsql-jdbc@postgresql.org; Wed, 19 Feb 2014 01:47:09 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.highgo.com.cn (Postfix) with ESMTP id 9E40A6D88483 for ; Wed, 19 Feb 2014 09:46:45 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=highgo.com.cn; h= content-type:content-type:in-reply-to:references:subject:subject :to:mime-version:user-agent:from:from:date:date:message-id; s= dkim; t=1392774394; x=1393638394; bh=l6piSchnEWzfBwMkhRNQxqKLXXX Jq0zbFKy+AASRSvA=; b=KCgRXYKnujke1AafgKk1oGbElZpHx5R7NCdsoAhlmNR FuqAHzqW2A1bC9fc9e1uH4onEx7HINqUfiw++cjggdAupJjW/2+ay5vgOMGY4XtD 4lrUzy7sPUl3qDwxQDzPRr/qLLBVrcHQgs6caO2nE0mrUmYAuz+d2hc+IAjN0f/I = X-Virus-Scanned: amavisd-new at highgo.com.cn Received: from mail.highgo.com.cn ([127.0.0.1]) by localhost (comp.highgo.com.cn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bvGGmowgtCJO for ; Wed, 19 Feb 2014 09:46:34 +0800 (CST) Received: from [192.168.100.61] (unknown [58.58.27.50]) by mail.highgo.com.cn (Postfix) with ESMTPSA id E42526D883FB; Wed, 19 Feb 2014 09:46:32 +0800 (CST) Message-ID: <53040D53.2090005@highgo.com.cn> Date: Wed, 19 Feb 2014 09:48:03 +0800 From: zhangyuanchao User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 MIME-Version: 1.0 To: Dave Cramer CC: List Subject: Re: One question about setting query timeout. References: <52F84B99.20800@highgo.com.cn> <52F9CAC9.5070103@highgo.com.cn> <53031A0F.6040402@highgo.com.cn> In-Reply-To: Content-Type: multipart/alternative; boundary="------------090207000202040901090306" X-Host-Lookup-Failed: Reverse DNS lookup failed for 58.58.27.50 (failed) X-Pg-Spam-Score: 2.4 (++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org This is a multi-part message in MIME format. --------------090207000202040901090306 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit Because the "cancelTimer" defined in Driver.java.in is different from the "cancelTimer" defined in AbstractJdbc2Statement.java. The first one is declared by "java.util.Timer",the second is declared by "java.util.TimerTask".Only the Timer class has purge function ,and TimerTask not. On 02/18/2014 08:00 PM, Dave Cramer wrote: > Why would you not just call purge on the cancelTimer ? > > Dave Cramer > > dave.cramer(at)credativ(dot)ca > http://www.credativ.ca > > > On Tue, Feb 18, 2014 at 3:30 AM, zhangyuanchao > > wrote: > > On 02/17/2014 09:08 PM, Dave Cramer wrote: >> Hi, >> >> There were some fixes put into the latest version can you check >> out the snapshot here ? >> >> https://oss.sonatype.org/content/repositories/snapshots/org/postgresql/postgresql/ >> >> Dave Cramer >> >> dave.cramer(at)credativ(dot)ca >> http://www.credativ.ca >> >> >> On Tue, Feb 11, 2014 at 2:01 AM, zhangyuanchao >> > > wrote: >> >> On 02/10/2014 07:18 PM, Dave Cramer wrote: >>> I think this is a known issues. What version of the driver >>> are you using ? >>> >>> Dave Cramer >>> >>> dave.cramer(at)credativ(dot)ca >>> http://www.credativ.ca >>> >>> >>> On Sun, Feb 9, 2014 at 10:46 PM, zhangyuanchao >>> >> > wrote: >>> >>> Hi, >>> I have a question about setting query timeout by jdbc. >>> When tested my application with Tomcat7.0 and >>> loadrunner,my tomcat's configure file is like this: >>> >> jdbcInterceptors="QueryTimeoutInterceptor(queryTimeout=600)" >>> ....../>. >>> After setting like above ,tomcat will call the jdbc's >>> setQueryTimeout function and set the query timeout to >>> 600seconds for each statement. >>> Next,i start my test with 150 concurrency.After about 10 >>> minutes later,i found the response time was much longer >>> than before.At that moment,i found there were a lot of >>> statement object in the heap memory of the JVM.And the >>> JVM's gc could not clean these objects,because they were >>> referenced by the TimerTask.So i read the source code of >>> the jdbc and Timer class,i found the mainloop function >>> of the Timer calss can cause the problem.This is the >>> code of mainloop function in Timer class and i think the >>> red colour text is that what cause the problem: >>> >>> private void mainLoop() { >>> while (true) { >>> try { >>> TimerTask task; >>> boolean taskFired; >>> synchronized(queue) { >>> // Wait for queue to become non-empty >>> while (queue.isEmpty() && newTasksMayBeScheduled) >>> queue.wait(); >>> if (queue.isEmpty()) >>> break; // Queue is empty and will forever remain; die >>> >>> // Queue nonempty; look at first evt and do the right thing >>> long currentTime, executionTime; >>> task = queue.getMin();fixes >>> >>> synchronized(task.lock) { >>> if (task.state == TimerTask.CANCELLED) { >>> queue.removeMin(); >>> continue; // No action required, poll queue again >>> } >>> currentTime = System.currentTimeMillis(); >>> executionTime = task.nextExecutionTime; >>> if (taskFired = (executionTime<=currentTime)) { >>> if (task.period == 0) { // Non-repeating, remove >>> queue.removeMin(); >>> task.state = TimerTask.EXECUTED; >>> } else { // Repeating task, reschedule >>> queue.rescheduleMin( >>> task.period<0 ? currentTime - task.period >>> : executionTime + task.period); >>> } >>> } >>> } >>> if (!taskFired) // Task hasn't yet fired; wait >>> queue.wait(executionTime - currentTime); >>> } >>> if (taskFired) // Task fired; run it, holding no locks >>> task.run(); >>> } catch(InterruptedException e) { >>> } >>> } >>> } >>> } >>> So,i want to ask if there is any solution for this problem. >>> Thanks very much. >>> >>> >>> >> Hi Dave, >> Thanks for your response. >> The version of driver that i am using is 9.3-1100(the latest >> version).And i searched some similar problem in the mail >> list,but i did not get it.I think the reason is : when an >> statement has been execute finished successfully and the >> statement cancel the timertask,but the timertask is still in >> Timer's queue.So the statement is always referenced by the >> Timer class and it can not be cleaned. >> Let me look at the mainloop function of Timer class.The part >> that is marked red colour can cause the mainloop stop,so the >> canceled timetask can not be removed from the queue.If i set >> the query timeout to 600 seconds,the mainloop will wait for >> about ten minutes.In the ten minutes,there will be more an >> more statement in the JVM heap. >> I think this is what cause the problem,but i don't have some >> good idea to solve it.Do you have some solution?Thanks a lot. >> >> > Hi, > I checked out the snapshot you sent to me.And i download this > https://oss.sonatype.org/content/repositories/snapshots/org/postgresql/postgresql/9.3-1101-jdbc4-SNAPSHOT/postgresql-9.3-1101-jdbc4-20140214.105528-4.jar > and test my application , i got the same problem.I look at the > fixes that was put into the latest version,i think that can not > solve my issue.I think you may not understand my question. > I have a solution like this, > adding a function into Driver.java.in : > public static Timer getCancelTimer() > { > return cancelTimer; > } > and modifing the killTimer() function AbstractJdbc2Statement.java: > private synchronized void killTimer() > { > if ( cancelTimer != null ) > { > cancelTimer.cancel(); > Driver.getCancelTimer().purge(); > cancelTimer = null; > } > > } > After modifing like above, i solved the problem.But i don't know > if the solution is good. > Thank you. > > --------------090207000202040901090306 Content-Type: text/html; charset=GB2312 Content-Transfer-Encoding: 7bit
Because the "cancelTimer" defined in Driver.java.in is different from the "cancelTimer" defined in AbstractJdbc2Statement.java. The first one is declared by
"java.util.Timer",the second is declared by "java.util.TimerTask".Only the Timer class has purge function ,and TimerTask not.
On 02/18/2014 08:00 PM, Dave Cramer wrote:
Why would you not just call purge on the cancelTimer ?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Tue, Feb 18, 2014 at 3:30 AM, zhangyuanchao <zhangyuanchao@highgo.com.cn> wrote:
On 02/17/2014 09:08 PM, Dave Cramer wrote:
Hi,

There were some fixes put into the latest version can you check out the snapshot here ?


Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Tue, Feb 11, 2014 at 2:01 AM, zhangyuanchao <zhangyuanchao@highgo.com.cn> wrote:
On 02/10/2014 07:18 PM, Dave Cramer wrote:
I think this is a known issues. What version of the driver are you using ?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Sun, Feb 9, 2014 at 10:46 PM, zhangyuanchao <zhangyuanchao@highgo.com.cn> wrote:
Hi,
    I have a question about setting query timeout by jdbc.
    When tested my application with Tomcat7.0 and loadrunner,my tomcat's configure file is like this:
<Resource ......
        jdbcInterceptors="QueryTimeoutInterceptor(queryTimeout=600)"
....../>.
    After setting like above ,tomcat will call the jdbc's setQueryTimeout function and set the query timeout to 600seconds for each statement.
Next,i start my test with 150 concurrency.After about 10 minutes later,i found the response time was much longer than before.At that moment,i found there were a lot of statement object in the heap memory of the JVM.And the JVM's gc could not clean these objects,because they were referenced by the TimerTask.So i read the source code of the jdbc and Timer class,i found the mainloop function of the Timer calss can cause the problem.This is the code of mainloop function in Timer class and i think the red colour text is that what cause the problem:

private void mainLoop() {
        while (true) {
            try {
                TimerTask task;
                boolean taskFired;
                synchronized(queue) {
                    // Wait for queue to become non-empty
                    while (queue.isEmpty() && newTasksMayBeScheduled)
                        queue.wait();
                    if (queue.isEmpty())
                        break; // Queue is empty and will forever remain; die

                    // Queue nonempty; look at first evt and do the right thing
                    long currentTime, executionTime;
                    task = queue.getMin();fixes

                    synchronized(task.lock) {
                        if (task.state == TimerTask.CANCELLED) {
                            queue.removeMin();
                            continue;  // No action required, poll queue again
                        }
                        currentTime = System.currentTimeMillis();
                        executionTime = task.nextExecutionTime;
                        if (taskFired = (executionTime<=currentTime)) {
                            if (task.period == 0) { // Non-repeating, remove
                                queue.removeMin();
                                task.state = TimerTask.EXECUTED;
                            } else { // Repeating task, reschedule
                                queue.rescheduleMin(
                                  task.period<0 ? currentTime   - task.period
                                                : executionTime + task.period);
                            }
                        }
                    }
                    if (!taskFired) // Task hasn't yet fired; wait
                        queue.wait(executionTime - currentTime);

                }
                if (taskFired)  // Task fired; run it, holding no locks
                    task.run();
            } catch(InterruptedException e) {
            }
        }
    }
}
So,i want to ask if there is any solution for this problem.
Thanks very much.

   

Hi Dave,
    Thanks for your response.
    The version of driver that i am using is 9.3-1100(the latest version).And i searched some similar problem in the mail list,but i did not get it.I think the reason is : when an statement has been execute finished successfully and the statement cancel the timertask,but the timertask is still in Timer's queue.So the statement is always referenced by the Timer class and it can not be cleaned.
     Let me look at the mainloop function of Timer class.The part that is marked red colour can cause the mainloop stop,so the canceled timetask can not be removed from the queue.If i set the query timeout to 600 seconds,the mainloop will wait for about ten minutes.In the ten minutes,there will be more an more statement in the JVM heap.
    I think this is what cause the problem,but i don't have some good idea to solve it.Do you have some solution?Thanks a lot.

Hi,
    I checked out the snapshot you sent to me.And i download this
https://oss.sonatype.org/content/repositories/snapshots/org/postgresql/postgresql/9.3-1101-jdbc4-SNAPSHOT/postgresql-9.3-1101-jdbc4-20140214.105528-4.jar and test my application ,  i got the same problem.I look at the fixes that was put into the latest version,i think that can not solve my issue.I think you may not understand my question.
I have a solution like this,
adding a function into Driver.java.in:
public static Timer getCancelTimer()
    {
         return cancelTimer;
    }
and modifing the killTimer() function AbstractJdbc2Statement.java:
private synchronized void killTimer()
    {
        if ( cancelTimer != null )
        {
            cancelTimer.cancel();
            Driver.getCancelTimer().purge();
            cancelTimer = null;
        }
           
    }
After modifing like above, i solved the problem.But i don't know if the solution is good.
Thank you.


--------------090207000202040901090306--