Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bKtws-0001Aj-C4 for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jul 2016 21:01:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bKtwr-0001uf-2p for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jul 2016 21:01:33 +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 1bKtwD-0001D1-Nb for pgsql-bugs@postgresql.org; Wed, 06 Jul 2016 21:00:53 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bKtwA-0006Z8-VT for pgsql-bugs@postgresql.org; Wed, 06 Jul 2016 21:00:52 +0000 Received: from localhost ([127.0.0.1]:19208 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.84 (FreeBSD)) (envelope-from ) id 1bKtw6-0001x8-SZ; Wed, 06 Jul 2016 21:00:46 +0000 From: Andrew Gierth To: blake@rcmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14231: logical replication wal sender process spins when using error traps in function In-Reply-To: <20160706185502.1426.28143@wrigleys.postgresql.org> (blake@rcmail.com's message of "Wed, 06 Jul 2016 18:55:02 +0000") Message-ID: <878txea5b4.fsf@news-spur.riddles.org.uk> References: <20160706185502.1426.28143@wrigleys.postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix) Date: Wed, 06 Jul 2016 22:00:46 +0100 MIME-Version: 1.0 Content-Type: text/plain X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org >>>>> "blake" == blake writes: blake> Connect a logical client with test_decoding plugin and run the blake> code below. It will cause the replication process to spin, blake> using 100% CPU for some long period of time. So what I've found in my analysis so far since you mentioned this on IRC is: 1. The time is being spent in ReorderBufferCleanupTXN and the functions it calls. This is called once for the transaction and (recursively) once per subtransaction. 2. Within each of those calls, the main culprit seems to be pathological behavior of the retail pfree() calls of allocated memory. The loop in AllocSetFree which chases down the allocated block list (for chunks over the chunk limit) is being executed nearly 900 million times for what seems to be about 42 thousand calls. A quick scan of the code suggests that the worst case is when blocks are being freed in FIFO order, which seems quite plausible in this case, and the performance is potentially O(N^2). So I think this is primarily an artifact of doing so much retail palloc/pfree in a single memory context. -- Andrew (irc:RhodiumToad) -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs