walsender doesn't send keepalives when writes are pending

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: walsender doesn't send keepalives when writes are pending
Date: 2014-02-14 12:05:22
Message-ID: 20140214120522.GK4910@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

In WalSndLoop() we do:

wakeEvents = WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_TIMEOUT |
WL_SOCKET_READABLE;

if (pq_is_send_pending())
wakeEvents |= WL_SOCKET_WRITEABLE;
else if (wal_sender_timeout > 0 && !ping_sent)
{
...
if (GetCurrentTimestamp() >= timeout)
WalSndKeepalive(true);
...

I think those two if's should simply be separate. There's no reason not
to ask for a ping when we're writing. On a busy server that might be the
case most of the time.
The if (pq_is_send_pending()) should also be *after* sending the
keepalive, after all, it might not immediately have been flushed as
unlikely as that is.

The attached patch is unsurprisingly simple.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
walsender-send-keepalive-with-writes-pending.patch text/x-patch 797 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Florian Pflug 2014-02-14 12:28:47 Re: Memory ordering issue in LWLockRelease, WakeupWaiters, WALInsertSlotRelease
Previous Message Mitsumasa KONDO 2014-02-14 11:54:14 Re: gaussian distribution pgbench