Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e7591fd

Browse files
committed
Introduce a WaitEventSet for the stats collector.
This avoids avoids some epoll/kqueue system calls for every wait. Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKGJAC4Oqao%3DqforhNey20J8CiG2R%3DoBPqvfR0vOJrFysGw%40mail.gmail.com
1 parent e2d394d commit e7591fd

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4458,6 +4458,8 @@ PgstatCollectorMain(int argc, char *argv[])
44584458
int len;
44594459
PgStat_Msg msg;
44604460
int wr;
4461+
WaitEvent event;
4462+
WaitEventSet *wes;
44614463

44624464
/*
44634465
* Ignore all signals usually bound to some action in the postmaster,
@@ -4485,6 +4487,12 @@ PgstatCollectorMain(int argc, char *argv[])
44854487
pgStatRunningInCollector = true;
44864488
pgStatDBHash = pgstat_read_statsfiles(InvalidOid, true, true);
44874489

4490+
/* Prepare to wait for our latch or data in our socket. */
4491+
wes = CreateWaitEventSet(CurrentMemoryContext, 3);
4492+
AddWaitEventToSet(wes, WL_LATCH_SET, PGINVALID_SOCKET, MyLatch, NULL);
4493+
AddWaitEventToSet(wes, WL_POSTMASTER_DEATH, PGINVALID_SOCKET, NULL, NULL);
4494+
AddWaitEventToSet(wes, WL_SOCKET_READABLE, pgStatSock, NULL, NULL);
4495+
44884496
/*
44894497
* Loop to process messages until we get SIGQUIT or detect ungraceful
44904498
* death of our parent postmaster.
@@ -4672,10 +4680,7 @@ PgstatCollectorMain(int argc, char *argv[])
46724680

46734681
/* Sleep until there's something to do */
46744682
#ifndef WIN32
4675-
wr = WaitLatchOrSocket(MyLatch,
4676-
WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE,
4677-
pgStatSock, -1L,
4678-
WAIT_EVENT_PGSTAT_MAIN);
4683+
wr = WaitEventSetWait(wes, -1L, &event, 1, WAIT_EVENT_PGSTAT_MAIN);
46794684
#else
46804685

46814686
/*
@@ -4688,18 +4693,15 @@ PgstatCollectorMain(int argc, char *argv[])
46884693
* to not provoke "using stale statistics" complaints from
46894694
* backend_read_statsfile.
46904695
*/
4691-
wr = WaitLatchOrSocket(MyLatch,
4692-
WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE | WL_TIMEOUT,
4693-
pgStatSock,
4694-
2 * 1000L /* msec */ ,
4695-
WAIT_EVENT_PGSTAT_MAIN);
4696+
wr = WaitEventSetWait(wes, 2 * 1000L /* msec */ , &event, 1,
4697+
WAIT_EVENT_PGSTAT_MAIN);
46964698
#endif
46974699

46984700
/*
46994701
* Emergency bailout if postmaster has died. This is to avoid the
47004702
* necessity for manual cleanup of all postmaster children.
47014703
*/
4702-
if (wr & WL_POSTMASTER_DEATH)
4704+
if (wr == 1 && event.events == WL_POSTMASTER_DEATH)
47034705
break;
47044706
} /* end of outer loop */
47054707

@@ -4708,6 +4710,8 @@ PgstatCollectorMain(int argc, char *argv[])
47084710
*/
47094711
pgstat_write_statsfiles(true, true);
47104712

4713+
FreeWaitEventSet(wes);
4714+
47114715
exit(0);
47124716
}
47134717

0 commit comments

Comments
 (0)