walsender doesn't send keepalives when writes are pending - Mailing list pgsql-hackers

From Andres Freund
Subject walsender doesn't send keepalives when writes are pending
Date
Msg-id 20140214120522.GK4910@awork2.anarazel.de
Whole thread Raw
Responses Re: walsender doesn't send keepalives when writes are pending  (Greg Stark <stark@mit.edu>)
Re: walsender doesn't send keepalives when writes are pending  (Amit Kapila <amit.kapila16@gmail.com>)
Re: walsender doesn't send keepalives when writes are pending  (Robert Haas <robertmhaas@gmail.com>)
List 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

pgsql-hackers by date:

Previous
From: Mitsumasa KONDO
Date:
Subject: Re: gaussian distribution pgbench
Next
From: Florian Pflug
Date:
Subject: Re: Memory ordering issue in LWLockRelease, WakeupWaiters, WALInsertSlotRelease