From: Oliver Jowett <oliver@opencloud.com>
To: PostgreSQL - JDBC <pgsql-jdbc@postgresql.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Gregory Stark <stark@enterprisedb.com>
Subject: Re: Implementing setQueryTimeout() - round 2
Date: Tue, 19 Feb 2008 17:39:56 +1300
Message-ID: <47BA5D9C.5050203@opencloud.com> (raw)
In-Reply-To: <47BA491E.9090603@opencloud.com>
References: <47B8E200.2020307@opencloud.com>
<5350.1203299903@sss.pgh.pa.us>
<47B8EB1C.8090802@opencloud.com>
<87ejbao6bg.fsf@oxford.xeocode.com>
<47BA2A6E.6050907@opencloud.com>
<17814.1203384054@sss.pgh.pa.us>
<47BA470A.8000904@opencloud.com>
<19443.1203390470@sss.pgh.pa.us>
<47BA491E.9090603@opencloud.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
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: oliver@opencloud.com, tgl@sss.pgh.pa.us, stark@enterprisedb.com
Subject: Re: Implementing setQueryTimeout() - round 2
In-Reply-To: <47BA5D9C.5050203@opencloud.com>
References: <47B8E200.2020307@opencloud.com> <5350.1203299903@sss.pgh.pa.us> <47B8EB1C.8090802@opencloud.com> <87ejbao6bg.fsf@oxford.xeocode.com> <47BA2A6E.6050907@opencloud.com> <17814.1203384054@sss.pgh.pa.us> <47BA470A.8000904@opencloud.com> <19443.1203390470@sss.pgh.pa.us> <47BA491E.9090603@opencloud.com> <47BA5D9C.5050203@opencloud.com>
* 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