pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: Implementing setQueryTimeout() - round 2
7+ messages / 6 participants
[nested] [flat]
* Re: Implementing setQueryTimeout() - round 2
@ 2008-02-19 04:39 Oliver Jowett <oliver@opencloud.com>
0 siblings, 3 replies; 7+ messages in thread
From: Oliver Jowett @ 2008-02-19 04:39 UTC (permalink / raw)
To: pgsql-jdbc; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Gregory Stark <stark@enterprisedb.com>
Based on feedback so far here's attempt #2. The main thing I got out of
the feedback is that statement_timeout seems to be enough for most people.
Unfortunately statement_timeout is not sufficient for what I need, so my
changes will end up doing more than that. Here's an attempt at a compromise:
Add 4 new connection parameters, associated connection / statement
values and accessors on the postgresql extension interfaces:
- softQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
- hardQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
- softQueryMargin: -1=disabled, >=0 = margin in ms, default 0
- hardQueryMargin: -1=disabled, >=0 = margin in ms, default 60s
The soft query timeout (if enabled) makes the driver set
statement_timeout before executing a query, which in most cases will
result in a SQLException being reported if the timeout is reached (but
this is not guaranteed).
The hard query timeout (if enabled) makes the driver forcibly close the
connection after that timeout if the query has not completed, which will
result in a fatal SQLException due to an IOException from the blocked
query thread.
The setQueryTimeout(N) logic then looks something like this:
> if (N == 0) {
> softQueryTimeout = hardQueryTimeout = 0;
> return;
> }
>
> if (softQueryMargin == -1 && hardQueryMargin == -1)
> throw new PSQLException("not implemented");
>
> if (softQueryMargin != -1)
> softQueryTimeout = max(1,N*1000+softQueryMargin)
> else
> softQueryTimeout = 0;
>
> if (hardQueryMargin != -1)
> hardQueryTimeout = max(1,N*1000+hardQueryMargin)
> else
> hardQueryTimeout = 0;
The net effect is that if you call "setQueryTimeout(N)" by default you
get an attempt at query cancellation after N seconds and a hard close of
the connection after N+60 seconds.
Any comments on this iteration? Too configurable? Not configurable
enough? Are the defaults sensible?
-O
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Implementing setQueryTimeout() - round 2
@ 2008-02-19 05:06 peter royal <peter.royal@pobox.com>
parent: Oliver Jowett <oliver@opencloud.com>
2 siblings, 0 replies; 7+ messages in thread
From: peter royal @ 2008-02-19 05:06 UTC (permalink / raw)
To: pgsql-jdbc
On Feb 18, 2008, at 8:39 PM, Oliver Jowett wrote:
> Unfortunately statement_timeout is not sufficient for what I need,
> so my changes will end up doing more than that. Here's an attempt at
> a compromise:
>
> Add 4 new connection parameters, associated connection / statement
> values and accessors on the postgresql extension interfaces:
this seems complicated.
can setQueryTimeout set statement_timeout, and then can any additional
logic be implemented externally?
i agree with tom that tying queries actually running long and network
failures isn't appropriate.
-pete
--
(peter.royal|osi)@pobox.com - http://fotap.org/~osi
Attachments:
smime.p7s (application/pkcs7-signature, 2.4K) download
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Implementing setQueryTimeout() - round 2
@ 2008-02-19 08:27 Till Toenges <tt@kyon.de>
parent: Oliver Jowett <oliver@opencloud.com>
2 siblings, 1 reply; 7+ messages in thread
From: Till Toenges @ 2008-02-19 08:27 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc; Tom Lane <tgl@sss.pgh.pa.us>; Gregory Stark <stark@enterprisedb.com>
Oliver Jowett wrote:
> - softQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
> - hardQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
> - softQueryMargin: -1=disabled, >=0 = margin in ms, default 0
> - hardQueryMargin: -1=disabled, >=0 = margin in ms, default 60s
I had to think about how you mean this. Doesn't this reduce to just one
useful parameter, namely hardQueryMargin? If hardQueryMargin is set,
then kill the connection after setQueryTimeout() + hardQueryMargin
seconds? All other cases would be covered by setting appropriate values
for these two.
And i'm still not quite convinced that anything but "softQueryTimeout"
should be implemented by the driver, but that's just my personal
opinion. How about starting with the simple case (using set), and then
see how it turns out in the real world?
Till
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Implementing setQueryTimeout() - round 2
@ 2008-02-19 08:30 Oliver Jowett <oliver@opencloud.com>
parent: Till Toenges <tt@kyon.de>
0 siblings, 1 reply; 7+ messages in thread
From: Oliver Jowett @ 2008-02-19 08:30 UTC (permalink / raw)
To: Till Toenges <tt@kyon.de>; +Cc: pgsql-jdbc; Tom Lane <tgl@sss.pgh.pa.us>; Gregory Stark <stark@enterprisedb.com>
Till Toenges wrote:
> Oliver Jowett wrote:
>> - softQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
>> - hardQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
>> - softQueryMargin: -1=disabled, >=0 = margin in ms, default 0
>> - hardQueryMargin: -1=disabled, >=0 = margin in ms, default 60s
>
> I had to think about how you mean this. Doesn't this reduce to just one
> useful parameter, namely hardQueryMargin? If hardQueryMargin is set,
> then kill the connection after setQueryTimeout() + hardQueryMargin
> seconds? All other cases would be covered by setting appropriate values
> for these two.
The two Margins are there for applications that are not aware of the
extensions and just uses setQueryTimeout().
If your code is aware of the two timeouts, it can set them directly. Or
they can be set at the connection level and inherited by all users, even
ones that don't use setQueryTimeout at all.
> And i'm still not quite convinced that anything but "softQueryTimeout"
> should be implemented by the driver, but that's just my personal
> opinion. How about starting with the simple case (using set), and then
> see how it turns out in the real world?
The real world case I am dealing with needs the hardQueryTimeout
behaviour. If I'm going to implement anything first, it's that.
-O
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Implementing setQueryTimeout() - round 2
@ 2008-02-19 09:46 Gregory Stark <stark@enterprisedb.com>
parent: Oliver Jowett <oliver@opencloud.com>
0 siblings, 0 replies; 7+ messages in thread
From: Gregory Stark @ 2008-02-19 09:46 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: Till Toenges <tt@kyon.de>; pgsql-jdbc; Tom Lane <tgl@sss.pgh.pa.us>
"Oliver Jowett" <oliver@opencloud.com> writes:
> The real world case I am dealing with needs the hardQueryTimeout behaviour. If
> I'm going to implement anything first, it's that.
I still don't understand why this has to be in the driver. Your application is
going to have to be able to handle creating a new connection in response to
this error so why can't it just also be the one to close the connection?
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's 24x7 Postgres support!
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Implementing setQueryTimeout() - round 2
@ 2008-02-19 10:01 Kris Jurka <books@ejurka.com>
parent: Oliver Jowett <oliver@opencloud.com>
2 siblings, 1 reply; 7+ messages in thread
From: Kris Jurka @ 2008-02-19 10:01 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc; Tom Lane <tgl@sss.pgh.pa.us>; Gregory Stark <stark@enterprisedb.com>
On Tue, 19 Feb 2008, Oliver Jowett wrote:
> Add 4 new connection parameters, associated connection / statement values and
> accessors on the postgresql extension interfaces:
>
> - softQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
> - hardQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
> - softQueryMargin: -1=disabled, >=0 = margin in ms, default 0
> - hardQueryMargin: -1=disabled, >=0 = margin in ms, default 60s
>
> Any comments on this iteration? Too configurable? Not configurable enough?
> Are the defaults sensible?
>
Sounds too configurable. I don't understand the use case for
softQueryMargin at all right now. Since hardQueryTimeout +
hardQueryMargin should be > softQueryTimeout + softQueryMargin for a
reasonable configuration, we don't need all these parameters. Don't you
just want:
1) defaultQueryTimeout: 0=disabled, >0 timeout in ms
2) hardTimeoutMargin: -1 disabled, >=0 hard timeout above query timeout
Kris Jurka
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Implementing setQueryTimeout() - round 2
@ 2008-02-19 16:22 Michael Paesold <mpaesold@gmx.at>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 0 replies; 7+ messages in thread
From: Michael Paesold @ 2008-02-19 16:22 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: Oliver Jowett <oliver@opencloud.com>; pgsql-jdbc; Tom Lane <tgl@sss.pgh.pa.us>; Gregory Stark <stark@enterprisedb.com>
Kris Jurka wrote:
> On Tue, 19 Feb 2008, Oliver Jowett wrote:
>
>> Add 4 new connection parameters, associated connection / statement
>> values and accessors on the postgresql extension interfaces:
>>
>> - softQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
>> - hardQueryTimeout: 0=disabled, >0 = timeout in ms, default 0
>> - softQueryMargin: -1=disabled, >=0 = margin in ms, default 0
>> - hardQueryMargin: -1=disabled, >=0 = margin in ms, default 60s
>>
>> Any comments on this iteration? Too configurable? Not configurable
>> enough? Are the defaults sensible?
>>
>
> Sounds too configurable. I don't understand the use case for
> softQueryMargin at all right now. Since hardQueryTimeout +
> hardQueryMargin should be > softQueryTimeout + softQueryMargin for a
> reasonable configuration, we don't need all these parameters. Don't you
> just want:
>
> 1) defaultQueryTimeout: 0=disabled, >0 timeout in ms
> 2) hardTimeoutMargin: -1 disabled, >=0 hard timeout above query timeout
+1 from me, sounds easier to grasp, and looks like it would be
everything Oliver needs, too. Oliver?
setQueryTimeout() could by default only set "soft" timeout
(hardTimeoutMargin set to -1)
If hardTimeoutMargin is set to >= 0 you will get hard timeouts at
setQueryTimeout + margin. Margin can be 0 of course.
If you want to have soft/hard timeout for all queries, you set one or
both parameters.
Any use cases not working with just these two parameters?
Best Regards
Michael Paesold
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2008-02-19 16:22 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-02-19 04:39 Re: Implementing setQueryTimeout() - round 2 Oliver Jowett <oliver@opencloud.com>
2008-02-19 05:06 ` peter royal <peter.royal@pobox.com>
2008-02-19 08:27 ` Till Toenges <tt@kyon.de>
2008-02-19 08:30 ` Oliver Jowett <oliver@opencloud.com>
2008-02-19 09:46 ` Gregory Stark <stark@enterprisedb.com>
2008-02-19 10:01 ` Kris Jurka <books@ejurka.com>
2008-02-19 16:22 ` Michael Paesold <mpaesold@gmx.at>
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