Re: inefficient loop in StandbyReleaseLockList()
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "Bossart, Nathan" <bossartn@amazon.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>,
"michael@paquier.xyz" <michael@paquier.xyz>,
"andres@anarazel.de" <andres@anarazel.de>,
"sulamul@gmail.com" <sulamul@gmail.com>,
"pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2021-11-01T22:01:18Z
Lists: pgsql-hackers
Attachments
- improve-SyncPostCheckpoint-performance.patch (text/x-diff) patch
"Bossart, Nathan" <bossartn@amazon.com> writes: > On 10/31/21, 1:55 PM, "Tom Lane" <tgl@sss.pgh.pa.us> wrote: >> 2. I think we almost certainly have a problem in SyncPostCheckpoint. > This one doesn't look as straightforward. It looks like we might need > a list_delete_first_n() to delete the first N entries all at once to > improve this one. Yeah. We don't absolutely need a new list primitive: we could use list_copy_tail() and then free the old list. But the extra palloc traffic involved makes this sound like a bad idea. It does have the advantage that we could shorten the List's storage even when it doesn't go to empty, but I'm not sure that's worth anything. If the List isn't going to empty, that implies that we're getting a steady stream of unlink requests, meaning we'd probably just fill it up again. The minimum-change patch would have us truncating the list before each AbsorbSyncRequests call, so that the list state meets that function's expectations. However, as long as UNLINKS_PER_ABSORB is only 10, I don't think that gets us out of the O(N^2) woods. So what I did in the attached is add a "canceled" flag to PendingUnlinkEntry, which lets us deal with canceled or finished entries without having to delete them from the list right away. Then we only need to physically clean up the list once per SyncPostCheckpoint call. regards, tom lane
Commits
-
Doc: add some notes about performance of the List functions.
- 27ef132a805c 15.0 landed
-
Avoid O(N^2) behavior in SyncPostCheckpoint().
- 65c6cab1365a 15.0 landed
- 08cfa5981e17 14.1 landed
- 0151af40cd4e 13.5 landed
-
Avoid some other O(N^2) hazards in list manipulation.
- e477642a1ba8 13.5 landed
- ad87bf355214 14.1 landed
- e9d9ba2a4ddc 15.0 landed
-
Avoid O(N^2) behavior when the standby process releases many locks.
- df238aed1090 13.5 landed
- 8424dfced790 14.1 landed
- 6301c3adabd9 15.0 landed