Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLuIB-0004sP-5b for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Dec 2017 17:12:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLuI9-00071C-Qq for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Dec 2017 17:12:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eLu20-00036a-0R for pgsql-hackers@lists.postgresql.org; Mon, 04 Dec 2017 16:55:48 +0000 Received: from gg-0.genua.de ([80.154.94.10] helo=gg.genua.de) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eLu1s-0000d9-KO for pgsql-hackers@postgresql.org; Mon, 04 Dec 2017 16:55:46 +0000 Received: from gg.genua.de (localhost [127.0.0.1]) by gg.genua.de (Postfix) with ESMTP id 95DDC83A217; Mon, 4 Dec 2017 17:55:36 +0100 (CET) Received: (from localhost) by gg.genua.de (MSCAN) id 2/gg.genua.de/smtp-gw/mscan; Mon Dec 4 17:55:36 2017 Date: Mon, 4 Dec 2017 17:55:25 +0100 From: Marco Pfatschbacher To: Tom Lane Cc: Thomas Munro , Pg Hackers Subject: Re: [HACKERS] PATCH: Keep one postmaster monitoring pipe per process Message-ID: <20171204165525.GA19160@genua.de> References: <20160915135755.GC19008@genua.de> <13774.1473972000@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <13774.1473972000@sss.pgh.pa.us> Organization: genua Gmbh User-Agent: Mutt/1.9.1 (2017-09-22) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Sep 15, 2016 at 04:40:00PM -0400, Tom Lane wrote: > Thomas Munro 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 diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c index 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 */