diff options
author | Robert Haas <rhaas@postgresql.org> | 2012-07-02 09:36:34 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2012-07-02 09:41:01 -0400 |
commit | f83b59997d29f06c3d67e7eb9a1f2c9cd017d665 (patch) | |
tree | 78a6cf4d43ca1c677cfeec05e187e17d17d8e884 /src/backend/access | |
parent | 9ad45c18b6c8d03ce18a26223eb0d15e900c7a2c (diff) | |
download | postgresql-f83b59997d29f06c3d67e7eb9a1f2c9cd017d665.tar.gz postgresql-f83b59997d29f06c3d67e7eb9a1f2c9cd017d665.zip |
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.
Diffstat (limited to 'src/backend/access')
-rw-r--r-- | src/backend/access/transam/twophase.c | 21 | ||||
-rw-r--r-- | src/backend/access/transam/xact.c | 7 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 25 |
3 files changed, 18 insertions, 35 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index e8fb78b3311..7f198c2e3e0 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1042,13 +1042,6 @@ EndPrepare(GlobalTransaction gxact) /* If we crash now, we have prepared: WAL replay will fix things */ - /* - * Wake up all walsenders to send WAL up to the PREPARE record immediately - * if replication is enabled - */ - if (max_wal_senders > 0) - WalSndWakeup(); - /* write correct CRC and close file */ if ((write(fd, &statefile_crc, sizeof(pg_crc32))) != sizeof(pg_crc32)) { @@ -2045,13 +2038,6 @@ RecordTransactionCommitPrepared(TransactionId xid, /* Flush XLOG to disk */ XLogFlush(recptr); - /* - * Wake up all walsenders to send WAL up to the COMMIT PREPARED record - * immediately if replication is enabled - */ - if (max_wal_senders > 0) - WalSndWakeup(); - /* Mark the transaction committed in pg_clog */ TransactionIdCommitTree(xid, nchildren, children); @@ -2133,13 +2119,6 @@ RecordTransactionAbortPrepared(TransactionId xid, XLogFlush(recptr); /* - * Wake up all walsenders to send WAL up to the ABORT PREPARED record - * immediately if replication is enabled - */ - if (max_wal_senders > 0) - WalSndWakeup(); - - /* * Mark the transaction aborted in clog. This is not absolutely necessary * but we may as well do it while we are here. */ diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 4755ee6ee40..86b1afa80d9 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -1142,13 +1142,6 @@ RecordTransactionCommit(void) XLogFlush(XactLastRecEnd); /* - * Wake up all walsenders to send WAL up to the COMMIT record - * immediately if replication is enabled - */ - if (max_wal_senders > 0) - WalSndWakeup(); - - /* * Now we may update the CLOG, if we wrote a COMMIT record above */ if (markXidCommitted) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index cbfa68a4e7b..a43e2eeaf30 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -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; } |