Re: BUG #14231: logical replication wal sender process spins when using error traps in function - Mailing list pgsql-bugs

From Andrew Gierth
Subject Re: BUG #14231: logical replication wal sender process spins when using error traps in function
Date
Msg-id 878txea5b4.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to BUG #14231: logical replication wal sender process spins when using error traps in function  (blake@rcmail.com)
Responses Re: BUG #14231: logical replication wal sender process spins when using error traps in function
Re: BUG #14231: logical replication wal sender process spins when using error traps in function
List pgsql-bugs
>>>>> "blake" == blake  <blake@rcmail.com> 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)

pgsql-bugs by date:

Previous
From: Martin Angelovski
Date:
Subject: pgAdmin3 1.22.1 crashes constantly on Mac os 10.11.5
Next
From: Peter Geoghegan
Date:
Subject: Re: BUG #14231: logical replication wal sender process spins when using error traps in function