1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Make walsender more responsive.

Per testing by Andres Freund, this improves replication performance
and reduces replication latency and latency jitter.  I was a bit
concerned about moving more work into XLogInsert, but testing seems
to show that it's not a problem in practice.

Along the way, improve comments for WaitLatchOrSocket.

Andres Freund.  Review and stylistic cleanup by me.
This commit is contained in:
Robert Haas
2012-07-02 09:36:34 -04:00
parent 9ad45c18b6
commit f83b59997d
7 changed files with 59 additions and 36 deletions

View File

@ -1025,6 +1025,8 @@ begin:;
END_CRIT_SECTION();
/* wakeup the WalSnd now that we released the WALWriteLock */
WalSndWakeupProcessRequests();
return RecPtr;
}
@ -1208,6 +1210,9 @@ begin:;
END_CRIT_SECTION();
/* wakeup the WalSnd now that we outside contented locks */
WalSndWakeupProcessRequests();
return RecPtr;
}
@ -1792,6 +1797,10 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
if (finishing_seg || (xlog_switch && last_iteration))
{
issue_xlog_fsync(openLogFile, openLogSegNo);
/* signal that we need to wakeup WalSnd later */
WalSndWakeupRequest();
LogwrtResult.Flush = LogwrtResult.Write; /* end of page */
if (XLogArchivingActive())
@ -1854,7 +1863,11 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
openLogFile = XLogFileOpen(openLogSegNo);
openLogOff = 0;
}
issue_xlog_fsync(openLogFile, openLogSegNo);
/* signal that we need to wakeup WalSnd later */
WalSndWakeupRequest();
}
LogwrtResult.Flush = LogwrtResult.Write;
}
@ -2120,6 +2133,9 @@ XLogFlush(XLogRecPtr record)
END_CRIT_SECTION();
/* wakeup the WalSnd now that we released the WALWriteLock */
WalSndWakeupProcessRequests();
/*
* If we still haven't flushed to the request point then we have a
* problem; most likely, the requested flush point is past end of XLOG.
@ -2245,13 +2261,8 @@ XLogBackgroundFlush(void)
END_CRIT_SECTION();
/*
* If we wrote something then we have something to send to standbys also,
* otherwise the replication delay become around 7s with just async
* commit.
*/
if (wrote_something)
WalSndWakeup();
/* wakeup the WalSnd now that we released the WALWriteLock */
WalSndWakeupProcessRequests();
return wrote_something;
}