Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8Yun-0007iO-8f for pgsql-general@arkaria.postgresql.org; Wed, 10 May 2017 21:12:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d8Yum-0002PZ-QD for pgsql-general@arkaria.postgresql.org; Wed, 10 May 2017 21:12:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d8YsQ-0006Y8-Ho for pgsql-general@postgresql.org; Wed, 10 May 2017 21:10:30 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d8YsN-0001JL-TD for pgsql-general@postgresql.org; Wed, 10 May 2017 21:10:30 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id BA88220A23; Wed, 10 May 2017 17:10:26 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Wed, 10 May 2017 17:10:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=Tm77gAPKiArtG6++ht 67alUIBEUYDInLdx+/WucfVpU=; b=emaXa0FBfpNNwc0RP6qes2q7YPqzVOgNjE R3sgaRbQYGNixaBMf5+fyHkOcl0ygML5vEdbSwHLsrfe9xxB7xznodqv40sLruVf parsg+CWDY/KX2WcMbQpOs+N0VSQQ2dpaY3kWilHZdhMKX8CZhcshgd9vMW34Eva kbiM8kb2buvnYYDp0z5m0AtYqxwBfQTLh0NS7dHGC9PkCNUciC0vSC1bzsGjC4N/ wKRViOasSERc0sA5LH2Of0qZguMXKZ5HiyZCPUJaAa6Ndc36cGQSINrIjAMal+nd r7hYHn+hbTuRSpQy5z+JJfe3py0Qr88oxwxNIliqUzT1GtCBLb/w== X-ME-Sender: X-Sasl-enc: Pmya/OODpgfasnoA8vZQdxidemRWMscdBPnZj4BWTxoQ 1494450626 Received: from intern.anarazel.de (unknown [208.72.138.107]) by mail.messagingengine.com (Postfix) with ESMTPA id 64B5A24950; Wed, 10 May 2017 17:10:26 -0400 (EDT) Date: Wed, 10 May 2017 14:10:25 -0700 From: Andres Freund To: Tom Lane Cc: Mathieu Fenniak , pgsql-general@postgresql.org Subject: Re: Logical decoding CPU-bound w/ large number of tables Message-ID: <20170510211025.scae63m476ftv7i3@alap3.anarazel.de> References: <20170506012055.hhmx5hirj2yk7d3g@alap3.anarazel.de> <19256.1494034347@sss.pgh.pa.us> <20170506013810.2og6vax6a2u3rhjc@alap3.anarazel.de> <12184.1494450131@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <12184.1494450131@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org Hi Tom, Mathieu, On 2017-05-10 17:02:11 -0400, Tom Lane wrote: > Mathieu Fenniak writes: > > Andres, it seems like the problem is independent of having large data > > manipulations mixed with schema changes. The below test case demonstrates > > it with just schema changes. > > > Tom, I've tested your patch, and it seems to have a positive impact for > > sure. I've documented a test case to reproduce this issue (below), and > > your avoid-search-in-catcache-invalidate.patch reduces the test case time > > from 63 seconds per run to 27 seconds per run. > > Thanks for the test case. Indeed! > + 59.28% 59.05% 150349 postmaster postgres [.] hash_seq_search > + 8.40% 8.36% 21250 postmaster postgres [.] CallSyscacheCallbacks > + 6.37% 6.34% 16115 postmaster postgres [.] LocalExecuteInvalidationMessage > + 5.69% 5.67% 14418 postmaster postgres [.] CatCacheInvalidate > + 3.14% 3.12% 7942 postmaster postgres [.] SysCacheInvalidate > + 1.72% 1.71% 4354 postmaster postgres [.] ReorderBufferCommit > + 1.37% 1.33% 3512 postmaster postgres [.] hash_search_with_hash_value > + 1.15% 1.15% 2913 postmaster postgres [.] InvalidateCatalogSnapshot > > I looked at the hash_seq_search time a bit more, and realized that > actually there's a pretty easy fix for that, which is to reduce > the initial size of RelfilenodeMapHash from 1024 entries to 64. Heh, that's not a bad idea. Given the table resizes automatically, there seems little reason not to go there. > You could quibble about where to set that exactly, but 1024 is > just way too many --- in your example, there are never more than > 5 entries in the hash, despite the presence of 10000 tables in > the database. That's likely because there's no DML. > We're at a point of diminishing returns here; I think any further > improvement would require reducing the number of invalidation calls, > as Andres was speculating about upthread. Still, this shows that > it doesn't take very much work to get a 10X improvement in the > overhead associated with inval activities. We've never seen this > overhead stick out quite this much before, and maybe logical replication > will always be an atypical workload, but I think this may be worth > committing even if Andres does managed to cut the number of calls. I've seen these callsites prominently in profiles not using logical decoding. Never quite as big as here, but still. Temp table heavy workloads IIRC are one of the easy way to trigger it. > It would be interesting to see how much these patches help for your real > use-case, as opposed to this toy example. Assuming that the results are > positive, I would advocate for back-patching these changes as far as 9.4 > where logical decoding came in. +1. > BTW, I also noticed that we're getting scarily close to exceeding > MAX_SYSCACHE_CALLBACKS. There are 30-some calls to > CacheRegisterSyscacheCallback in our code, and while I think not all of > them can be reached in a single process, we demonstrably get as high as 21 > registered callbacks in some regression test runs. That's not leaving a > lot of daylight for add-on modules. The second patch attached includes > increasing MAX_SYSCACHE_CALLBACKS from 32 to 64. I think we'd be well > advised to apply and back-patch that, even if we don't use the rest of > the patch. +1 - I'd advocate for doing so all the way. Greetings, Andres Freund -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general