Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ahs7K-0002TX-JE for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Mar 2016 05:11:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ahs7K-0002h6-57 for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Mar 2016 05:11:02 +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 1ahs5r-00012k-Mo for pgsql-hackers@postgresql.org; Mon, 21 Mar 2016 05:09:31 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ahs5o-0003Yh-Ek for pgsql-hackers@postgresql.org; Mon, 21 Mar 2016 05:09:30 +0000 Received: by mail.anarazel.de (Postfix, from userid 108) id 8B33D3B49A7; Mon, 21 Mar 2016 06:09:26 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail X-Spam-Level: X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.5 Received: from anarazel.de (pD9F6ACB7.dip0.t-ipconnect.de [217.246.172.183]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id B31D63B49A4; Mon, 21 Mar 2016 06:09:19 +0100 (CET) Received: by anarazel.de (Postfix, from userid 1000) id EEEB6109B91; Mon, 21 Mar 2016 06:09:18 +0100 (CET) Date: Mon, 21 Mar 2016 06:09:18 +0100 From: Andres Freund To: Thomas Munro Cc: Amit Kapila , Robert Haas , Amit Kapila , Tom Lane , =?utf-8?B?0JLQsNGB0LjQu9GM0LXQsiDQlNC80LjRgtGA0LjQuQ==?= , "pgsql-hackers@postgresql.org" Subject: Re: Performance degradation in commit ac1d794 Message-ID: <20160321050918.GA6781@awork2.anarazel.de> References: <20160317020426.uz5oobr6b72mpcdw@alap3.anarazel.de> <20160318080428.meaaq237dcee4eip@alap3.anarazel.de> <20160320014536.tzumekq34tqa46fm@alap3.anarazel.de> <20160320041409.oy7v32nk6niapxhv@alap3.anarazel.de> <20160320144600.pqiozzqnje3iglrl@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Hi, On 2016-03-21 11:52:43 +1300, Thomas Munro wrote: > The contract that I invented here is that an async-aware parent node > can ask any child node "are you ready?" and get back various answers > including an fd which means please don't call ExecProcNode until this > fd is ready to read. But after ExecProcNode is called, the fd must > not be accessed again (the subplan has the right to close it, return a > different one next time etc), so it must not appear in any > WaitEventSet wait on after that. Hm, why did you choose to go with that contract? Why do children need to switch fds and such? > As you can see, in append_next_async_wait, it therefore needs to > create an new WaitEventSet every time it needs to wait, which makes it > feel more like select() than epoll(). Ideally it'd just have just one > single WaitEventSet for the lifetime of the append node, and just add > and remove fds as required. Yes, I see. I think that'd be less efficient than not manipulating the set all the time, but still a lot more efficient than adding/removing the postmaster death latch every round. Anyway, I want to commit this ASAP, so I can get on to some patches in the CF. But I'd welcome you playing with adding that ability. > On the subject of short-lived and frequent calls to WaitLatchOrSocket, > I wonder if there would be some benefit in reusing a statically > allocated WaitEventSet for that. Wondered the same. It looks like there'd be a number (just latch, latch + postmaster death), for it to be beneficial. Most latch waits aren't that frequent though, so I've decided not to initially go there. > That would become possible if you > could add and remove the latch and socket as discussed, with an > opportunity to skip the modification work completely if the reusable > WaitEventSet already happens to have the right stuff in it from the > last WaitLatchOrSocket call. Or maybe the hot wait loops should > simply be rewritten to reuse a WaitEventSet explicitly so they can > manage that... Yea, I think that's better. > * It looks like epoll (and maybe kqueue?) can associate user data with > an event and give it back to you; if you have a mapping between fds > and some other object (in the case of the attached patch, subplan > nodes that are ready to be pulled), would it be possible and useful to > expose that (and simulate it where needed) rather than the caller > having to maintain associative data structures (see the linear search > in my patch)? We already use the pointer that epoll gives you. But note that the 'WaitEvent' struct already contains the original position the event was registered at. That's filled in when you call WaitEventSetWait(). So you could either just build an array based on ->pos, or we could also add a void *private; or such to the definition. > * I would be interested in writing a kqueue implementation of this for > *BSD (and MacOSX?) at some point if someone doesn't beat me to it. I hoped that somebody would do that - that'd afaics be the only major API missing. > * It would be very cool to get some view into which WaitEventSetWait > call backends are waiting in from a system view if it could be done > cheaply enough. A name/ID for the call site, and an indication of > which latch and how many fds... or something. That's not something I plan to tackle today; we don't have wait event integration for latches atm. There's some threads somewhere about this, but that seems mostly independent of the way latches are implemented. Thanks, Andres -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers