From: Marco Pfatschbacher <Marco_Pfatschbacher@genua.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] PATCH: Keep one postmaster monitoring pipe per process
Date: Mon, 4 Dec 2017 17:55:25 +0100
Message-ID: <20171204165525.GA19160@genua.de> (raw)
In-Reply-To: <13774.1473972000@sss.pgh.pa.us>
References: <20160915135755.GC19008@genua.de>
<CAEepm=27K-2AP1th97kiVvKpTuria9ocbjT0cXCJqnt4if5rJQ@mail.gmail.com>
<13774.1473972000@sss.pgh.pa.us>
On Thu, Sep 15, 2016 at 04:40:00PM -0400, Tom Lane wrote:
> Thomas Munro <thomas.munro@enterprisedb.com> writes:
> > Very interesting. Perhaps that is why NetBSD shows a speedup with the
> > kqueue patch[1] but FreeBSD doesn't. I guess that if I could get the
> > kqueue patch to perform better on large FreeBSD systems, it would also
> > be a solution to this problem.
>
> I just noticed that kqueue appears to offer a solution to this problem,
> ie one of the things you can wait for is exit of another process (named
> by PID, looks like). If that's portable to all kqueue platforms, then
> integrating a substitute for the postmaster death pipe might push that
> patch over the hump to being a net win.
>
> regards, tom lane
Hi,
sorry for the long silence.
I forgot about this after being on vacation.
kqueue does indeed support EVFILT_PROC like you said.
But using this effectively, would need a separate monitoring process,
because we cannot use poll(2) and kevent(2) together within the same loop.
But how about this:
We just use getppid to see whether the process id of our parent
has changed to 1 (init).
Just like calling read on the pipe, that's just one systemcall.
I did not bother to weed the postmaster_alive_fds yet, but
this change works fine for me.
Regards,
Marco
inline patch 1: src/backend/storage/ipc/pmsignal.c (+6/-11 lines) download inline-1.patchdiff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.cindex 85db6b21f8..a0596c61fd 100644--- a/src/backend/storage/ipc/pmsignal.c+++ b/src/backend/storage/ipc/pmsignal.c@@ -272,21 +272,16 @@ bool
PostmasterIsAlive(void)
{
#ifndef WIN32
- char c;- ssize_t rc;+ pid_t ppid;- rc = read(postmaster_alive_fds[POSTMASTER_FD_WATCH], &c, 1);- if (rc < 0)+ ppid = getppid();+ if (ppid == 1)
{
- if (errno == EAGAIN || errno == EWOULDBLOCK)- return true;- else- elog(FATAL, "read on postmaster death monitoring pipe failed: %m");+ elog(FATAL, "postmaster died: our ppid changed to init");+ return false;
}
- else if (rc > 0)- elog(FATAL, "unexpected data in postmaster death monitoring pipe");- return false;+ return true;
#else /* WIN32 */
return (WaitForSingleObject(PostmasterHandle, 0) == WAIT_TIMEOUT);
#endif /* WIN32 */
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-hackers@postgresql.org
Cc: Marco_Pfatschbacher@genua.de, tgl@sss.pgh.pa.us, thomas.munro@enterprisedb.com
Subject: Re: [HACKERS] PATCH: Keep one postmaster monitoring pipe per process
In-Reply-To: <20171204165525.GA19160@genua.de>
References: <20160915135755.GC19008@genua.de> <CAEepm=27K-2AP1th97kiVvKpTuria9ocbjT0cXCJqnt4if5rJQ@mail.gmail.com> <13774.1473972000@sss.pgh.pa.us> <20171204165525.GA19160@genua.de>
* 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