Re: Add client connection check during the execution of the query

Thomas Munro <thomas.munro@gmail.com>

From: Thomas Munro <thomas.munro@gmail.com>
To: Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
Cc: Tatsuo Ishii <ishii@sraoss.co.jp>, Stas Kelvich <s.kelvich@postgrespro.ru>, Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-03-01T05:18:17Z
Lists: pgsql-hackers

Attachments

On Sat, Aug 3, 2019 at 4:40 AM Konstantin Knizhnik
<k.knizhnik@postgrespro.ru> wrote:
> On 18.07.2019 6:19, Tatsuo Ishii wrote:
> > So the performance is about 5% down with the feature enabled in this
> > case.  For me, 5% down is not subtle. Probably we should warn this in
> > the doc.
>
> I also see some performance degradation, although it is not so large in
> my case (I used pgbench with scale factor 10 and run the same command as
> you).
> In my case difference is 103k vs. 105k TPS is smaller than 2%.

I didn't test, but hopefully the degradation is fixed by commit 09cf1d52?

> If OS detected closed connection, it should return POLLHUP, should not it?
> I am not sure if it is more portable or more efficient way - just seems
> to be a little bit more natural way (from my point of view) to check if
> connection is still alive.

That's if you're sleeping inepoll etc.  This patch is for CPU-bound
backends, running a long query.  We need to do something special to
find out if the kernel knows that the connection has been closed.

I've done a quick rebase of this the patch and added it to the
commitfest.  No other changes.  Several things were mentioned earlier
that still need to be tidied up.

Commits

  1. Add WL_SOCKET_CLOSED for socket shutdown events.

  2. Use WL_SOCKET_CLOSED for client_connection_check_interval.

  3. Detect POLLHUP/POLLRDHUP while running queries.

  4. Improve timeout.c's handling of repeated timeout set/cancel.