diff options
author | Andres Freund <andres@anarazel.de> | 2016-03-18 11:43:59 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2016-03-18 11:47:05 -0700 |
commit | c4901a1e03a7730e4471fd1143f1caf79695493d (patch) | |
tree | 179283f34e306ff45e71a7aa98ad9b06f7c4f864 /src/backend/port/win32_latch.c | |
parent | c17966201c7de2a4c437bed6d83c6a7f2e7108f4 (diff) | |
download | postgresql-c4901a1e03a7730e4471fd1143f1caf79695493d.tar.gz postgresql-c4901a1e03a7730e4471fd1143f1caf79695493d.zip |
Only clear latch self-pipe/event if there is a pending notification.
This avoids a good number of, individually quite fast, system calls in
scenarios with many quick queries. Besides the aesthetic benefit of
seing fewer superflous system calls with strace, it also improves
performance by ~2% measured by pgbench -M prepared -c 96 -j 8 -S (scale
100).
Without having benchmarked it, this patch also adjust the windows code,
as that makes it easier to unify the unix/windows codepaths in a later
patch. There's little reason to diverge in behaviour between the
platforms.
Discussion: CA+TgmoYc1Zm+Szoc_Qbzi92z2c1vRHZmjhfPn5uC=w8bXv6Avg@mail.gmail.com
Reviewed-By: Robert Haas
Diffstat (limited to 'src/backend/port/win32_latch.c')
-rw-r--r-- | src/backend/port/win32_latch.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/backend/port/win32_latch.c b/src/backend/port/win32_latch.c index b1b071339ee..bbf1b24bdf3 100644 --- a/src/backend/port/win32_latch.c +++ b/src/backend/port/win32_latch.c @@ -181,14 +181,11 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, do { /* - * Reset the event, and check if the latch is set already. If someone - * sets the latch between this and the WaitForMultipleObjects() call - * below, the setter will set the event and WaitForMultipleObjects() - * will return immediately. + * The comment in unix_latch.c's equivalent to this applies here as + * well. At least after mentally replacing self-pipe with windows + * event. There's no danger of overflowing, as "Setting an event that + * is already set has no effect.". */ - if (!ResetEvent(latchevent)) - elog(ERROR, "ResetEvent failed: error code %lu", GetLastError()); - if ((wakeEvents & WL_LATCH_SET) && latch->is_set) { result |= WL_LATCH_SET; @@ -217,9 +214,13 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, else if (rc == WAIT_OBJECT_0 + 1) { /* - * Latch is set. We'll handle that on next iteration of loop, but - * let's not waste the cycles to update cur_timeout below. + * Reset the event. We'll re-check the, potentially, set latch on + * next iteration of loop, but let's not waste the cycles to + * update cur_timeout below. */ + if (!ResetEvent(latchevent)) + elog(ERROR, "ResetEvent failed: error code %lu", GetLastError()); + continue; } else if ((wakeEvents & (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE)) && |