]> granicus.if.org Git - postgresql/commit
Improve LISTEN startup time when there are many unread notifications.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 1 Oct 2015 03:32:23 +0000 (23:32 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 1 Oct 2015 03:32:23 +0000 (23:32 -0400)
commit03f9b63e24ea6a40afbf518a281e9fca134e999c
treed23146643240a35720699daf3ea3e0ab98717345
parentb62c870ff1774c98865a930f2f0a09544e11d2e5
Improve LISTEN startup time when there are many unread notifications.

If some existing listener is far behind, incoming new listener sessions
would start from that session's read pointer and then need to advance over
many already-committed notification messages, which they have no interest
in.  This was expensive in itself and also thrashed the pg_notify SLRU
buffers a lot more than necessary.  We can improve matters considerably
in typical scenarios, without much added cost, by starting from the
furthest-ahead read pointer, not the furthest-behind one.  We do have to
consider only sessions in our own database when doing this, which requires
an extra field in the data structure, but that's a pretty small cost.

Back-patch to 9.0 where the current LISTEN/NOTIFY logic was introduced.

Matt Newell, slightly adjusted by me
src/backend/commands/async.c