Hi, I found the bug which causes walsender to enter into busy loop when replication connection is terminated. Walsender consumes lots of CPU resource (%sys), and this situation lasts until it has detected the termination of replication connection and exited.
The cause of this bug is that the walsender loop doesn't call ResetLatch at all in the above case. Since the latch remains set, the walsender loop cannot sleep on the latch, i.e., WaitLatch always returns immediately. We can fix this bug by adding ResetLatch into the top of the walsender loop. Patch attached. This bug exists in 9.1 but not in 9.2dev. In 9.2dev, this bug has already been fixed by the commit (cff75130b5f63e45423c2ed90d6f2e84c21ef840). This commit refactors and refines the walsender loop logic in addition to adding ResetLatch. So I'm tempted to backport this commit (except the deletion of wal_sender_delay) to 9.1 rather than applying the attached patch. OTOH, attached patch is quite simple, and its impact on 9.1 would be very small, so it's easy to backport that. Thought? Regards, -- Fujii Masao NIPPON TELEGRAPH AND TELEPHONE CORPORATION NTT Open Source Software Center
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 3497269..35c7042 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -700,6 +700,9 @@ WalSndLoop(void) /* Loop forever, unless we get an error */ for (;;) { + /* Clear any already-pending wakeups */ + ResetLatch(&MyWalSnd->latch); + /* * Emergency bailout if postmaster has died. This is to avoid the * necessity for manual cleanup of all postmaster children.
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers