Bug: walsender and high CPU usage - Mailing list pgsql-hackers

From Fujii Masao
Subject Bug: walsender and high CPU usage
Date
Msg-id CAHGQGwG=13nAEsVEO+2WpzyyuXyhB-cQE8BSTG6D7R_vMKDytA@mail.gmail.com
Whole thread Raw
Responses Re: Bug: walsender and high CPU usage
List pgsql-hackers
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

Attachment

pgsql-hackers by date:

Previous
From: Marco Nenciarini
Date:
Subject: Re: [PATCH] Support for foreign keys with arrays
Next
From: Thom Brown
Date:
Subject: Re: Command Triggers, patch v11