Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkutA-0007nL-JU for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Sep 2016 15:17:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bkutA-0006Yz-5o for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Sep 2016 15:17:16 +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 1bko01-0007nE-DE for pgsql-hackers@postgresql.org; Fri, 16 Sep 2016 07:55:53 +0000 Received: from gg6-2.genua.de ([2001:a60:f08e:c000::2] helo=gg.genua.de) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bknzy-0006md-NZ for pgsql-hackers@postgresql.org; Fri, 16 Sep 2016 07:55:52 +0000 Received: from gg.genua.de (localhost [127.0.0.1]) by gg.genua.de (Postfix) with ESMTP id 372597AE934 for ; Fri, 16 Sep 2016 09:55:49 +0200 (CEST) Received: (from localhost) by gg.genua.de (MSCAN) id 4/gg.genua.de/smtp-gw/mscan; Fri Sep 16 09:55:49 2016 Date: Fri, 16 Sep 2016 09:55:48 +0200 From: Marco Pfatschbacher To: Andres Freund Cc: pgsql-hackers@postgresql.org Subject: Re: PATCH: Keep one postmaster monitoring pipe per process Message-ID: <20160916075547.GC15576@genua.de> References: <20160915135755.GC19008@genua.de> <20160915192616.f2yq4wtltnlhjw3h@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160915192616.f2yq4wtltnlhjw3h@alap3.anarazel.de> Organization: genua Gmbh User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -4.2 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On Thu, Sep 15, 2016 at 12:26:16PM -0700, Andres Freund wrote: > Hi, > > On 2016-09-15 15:57:55 +0200, Marco Pfatschbacher wrote: > > the current implementation of PostmasterIsAlive() uses a pipe to > > monitor the existence of the postmaster process. > > One end of the pipe is held open in the postmaster, while the other end is > > inherited to all the auxiliary and background processes when they fork. > > This leads to multiple processes calling select(2), poll(2) and read(2) > > on the same end of the pipe. > > While this is technically perfectly ok, it has the unfortunate side > > effect that it triggers an inefficient behaviour[0] in the select/poll > > implementation on some operating systems[1]: > > The kernel can only keep track of one pid per select address and > > thus has no other choice than to wakeup(9) every process that > > is waiting on select/poll. > > Yikes, that's a pretty absurd implementation. Not when you take into account that it's been written over 20 years ago ;) > Does openbsd's kqueue implementation have the same issue? There's > http://archives.postgresql.org/message-id/CAEepm%3D37oF84-iXDTQ9MrGjENwVGds%2B5zTr38ca73kWR7ez_tA%40mail.gmail.com Looks ok, but your milage may vary. I've seen strange subtle bugs using kqeue.. struct kevent { __uintptr_t ident; /* identifier for this event */ short filter; /* filter for event */ u_short flags; u_int fflags; quad_t data; void *udata; /* opaque user data identifier */ }; > > Attached patch avoids the select contention by using a > > separate pipe for each auxiliary and background process. > > I'm quite unenthusiastic about forcing that many additional file > descriptors onto the postmaster... In our use case it's about 30. > I'm not quite sure I understand why this an issue here - there shouldn't > ever be events on this fd, so why is the kernel waking up all processes? > It'd kinda makes sense it'd wake up all processes if there's one > waiting, but ... ? Every read is an event, and that's what PostmasterIsAlive does. Marco -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers