From: Tom Lane <tgl@sss.pgh.pa.us>
To: Oliver Jowett <oliver@opencloud.com>
Cc: PostgreSQL - JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: Implementing setQueryTimeout()
Date: Sun, 17 Feb 2008 20:58:23 -0500
Message-ID: <5350.1203299903@sss.pgh.pa.us> (raw)
In-Reply-To: <47B8E200.2020307@opencloud.com>
References: <47B8E200.2020307@opencloud.com>
Oliver Jowett <oliver@opencloud.com> writes:
> (2) Run a separate timer thread. Start a timer in Statement.execute()
> before submitting the query to the protocol layer. If the timer expires,
> close the low-level DB connection (from the timer thread) which should
> cause an IOException in the guts of the protocol layer where the query
> executing thread is blocked on network I/O, eventually propagating up as
> a fatal SQLException to the caller.
> I would like to implement (2) but I can see that killing the connection
> on timeout may not be desirable in all cases.
That seems pretty darn horrid, actually. If the reason for the slow
response is server overload, this technique will make things rapidly
*worse*. In the first place it does nothing to prevent the server from
continuing to compute the too-slow query (and perhaps even committing
it). In the second place, having to establish a new connection will eat
a lot of cycles you really don't want to waste. In the third place,
once you do establish a new connection it will be competing for cycles
with the still-running query in the original backend. Iterate a few
times and you'll have a self-inflicted denial of service.
I agree with having a timer thread, I think, just not with what you want
to do when the timer fires. Can't you do something like sending a query
cancel request when you time out?
It might be that you need to decouple queries from connections a bit
more, so that a query can fail and "let go" of a connection, while the
connection object has to wait for its query to be cancelled before
returning to the pool of available connections.
regards, tom lane
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: tgl@sss.pgh.pa.us, oliver@opencloud.com
Subject: Re: Implementing setQueryTimeout()
In-Reply-To: <5350.1203299903@sss.pgh.pa.us>
References: <47B8E200.2020307@opencloud.com> <5350.1203299903@sss.pgh.pa.us>
* 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