On Thu, Sep 15, 2016 at 04:40:00PM -0400, Tom Lane wrote: > Thomas Munro <thomas.mu...@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 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 */