diff options
| author | Simon Riggs | 2011-11-13 09:00:57 +0000 |
|---|---|---|
| committer | Simon Riggs | 2011-11-13 09:00:57 +0000 |
| commit | 4de82f7d7c50a81ec8e70e2cb0ab413ab9134c0b (patch) | |
| tree | 7ee129540269debbdf22771e1e99244445213e6a /src/backend/postmaster | |
| parent | 02d88efea1f719e59ce684c2e14bad23d55fdd15 (diff) | |
Wakeup WALWriter as needed for asynchronous commit performance.
Previously we waited for wal_writer_delay before flushing WAL. Now
we also wake WALWriter as soon as a WAL buffer page has filled.
Significant effect observed on performance of asynchronous commits
by Robert Haas, attributed to the ability to set hint bits on tuples
earlier and so reducing contention caused by clog lookups.
Diffstat (limited to 'src/backend/postmaster')
| -rw-r--r-- | src/backend/postmaster/walwriter.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c index 23c4aacd7da..157728e20e7 100644 --- a/src/backend/postmaster/walwriter.c +++ b/src/backend/postmaster/walwriter.c @@ -11,7 +11,8 @@ * * Note that as with the bgwriter for shared buffers, regular backends are * still empowered to issue WAL writes and fsyncs when the walwriter doesn't - * keep up. + * keep up. This means that the WALWriter is not an essential process and + * can shutdown quickly when requested. * * Because the walwriter's cycle is directly linked to the maximum delay * before async-commit transactions are guaranteed committed, it's probably @@ -76,7 +77,6 @@ static void wal_quickdie(SIGNAL_ARGS); static void WalSigHupHandler(SIGNAL_ARGS); static void WalShutdownHandler(SIGNAL_ARGS); - /* * Main entry point for walwriter process * @@ -89,6 +89,8 @@ WalWriterMain(void) sigjmp_buf local_sigjmp_buf; MemoryContext walwriter_context; + InitLatch(WALWriterLatch()); /* initialize latch used in main loop */ + /* * If possible, make this process a group leader, so that the postmaster * can signal any child processes too. (walwriter probably never has any @@ -220,7 +222,7 @@ WalWriterMain(void) */ for (;;) { - long udelay; + ResetLatch(WALWriterLatch()); /* * Emergency bailout if postmaster has died. This is to avoid the @@ -248,20 +250,9 @@ WalWriterMain(void) */ XLogBackgroundFlush(); - /* - * Delay until time to do something more, but fall out of delay - * reasonably quickly if signaled. - */ - udelay = WalWriterDelay * 1000L; - while (udelay > 999999L) - { - if (got_SIGHUP || shutdown_requested) - break; - pg_usleep(1000000L); - udelay -= 1000000L; - } - if (!(got_SIGHUP || shutdown_requested)) - pg_usleep(udelay); + (void) WaitLatch(WALWriterLatch(), + WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, + WalWriterDelay /* ms */); } } @@ -308,6 +299,7 @@ static void WalSigHupHandler(SIGNAL_ARGS) { got_SIGHUP = true; + SetLatch(WALWriterLatch()); } /* SIGTERM: set flag to exit normally */ @@ -315,4 +307,5 @@ static void WalShutdownHandler(SIGNAL_ARGS) { shutdown_requested = true; + SetLatch(WALWriterLatch()); } |
