From: zhangyuanchao <zhangyuanchao@highgo.com.cn>
To: Dave Cramer <pg@fastcrypt.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: One question about setting query timeout.
Date: Tue, 11 Feb 2014 15:01:29 +0800
Message-ID: <52F9CAC9.5070103@highgo.com.cn> (raw)
In-Reply-To: <CADK3HH+N6Dcot9OT0VnwyfkxEhEZ_oNWcNoHiTOztTFWWNwPZQ@mail.gmail.com>
References: <52F84B99.20800@highgo.com.cn>
<CADK3HH+N6Dcot9OT0VnwyfkxEhEZ_oNWcNoHiTOztTFWWNwPZQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
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 <mailto: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();
> 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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: zhangyuanchao@highgo.com.cn, pg@fastcrypt.com
Subject: Re: One question about setting query timeout.
In-Reply-To: <52F9CAC9.5070103@highgo.com.cn>
References: <52F84B99.20800@highgo.com.cn> <CADK3HH+N6Dcot9OT0VnwyfkxEhEZ_oNWcNoHiTOztTFWWNwPZQ@mail.gmail.com> <52F9CAC9.5070103@highgo.com.cn>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox