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
This commit is contained in:
parent
e2d394df5d
commit
e7591fd3ca
@ -4458,6 +4458,8 @@ PgstatCollectorMain(int argc, char *argv[])
|
|||||||
int len;
|
int len;
|
||||||
PgStat_Msg msg;
|
PgStat_Msg msg;
|
||||||
int wr;
|
int wr;
|
||||||
|
WaitEvent event;
|
||||||
|
WaitEventSet *wes;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ignore all signals usually bound to some action in the postmaster,
|
* Ignore all signals usually bound to some action in the postmaster,
|
||||||
@ -4485,6 +4487,12 @@ PgstatCollectorMain(int argc, char *argv[])
|
|||||||
pgStatRunningInCollector = true;
|
pgStatRunningInCollector = true;
|
||||||
pgStatDBHash = pgstat_read_statsfiles(InvalidOid, true, true);
|
pgStatDBHash = pgstat_read_statsfiles(InvalidOid, true, true);
|
||||||
|
|
||||||
|
/* Prepare to wait for our latch or data in our socket. */
|
||||||
|
wes = CreateWaitEventSet(CurrentMemoryContext, 3);
|
||||||
|
AddWaitEventToSet(wes, WL_LATCH_SET, PGINVALID_SOCKET, MyLatch, NULL);
|
||||||
|
AddWaitEventToSet(wes, WL_POSTMASTER_DEATH, PGINVALID_SOCKET, NULL, NULL);
|
||||||
|
AddWaitEventToSet(wes, WL_SOCKET_READABLE, pgStatSock, NULL, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Loop to process messages until we get SIGQUIT or detect ungraceful
|
* Loop to process messages until we get SIGQUIT or detect ungraceful
|
||||||
* death of our parent postmaster.
|
* death of our parent postmaster.
|
||||||
@ -4672,10 +4680,7 @@ PgstatCollectorMain(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Sleep until there's something to do */
|
/* Sleep until there's something to do */
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
wr = WaitLatchOrSocket(MyLatch,
|
wr = WaitEventSetWait(wes, -1L, &event, 1, WAIT_EVENT_PGSTAT_MAIN);
|
||||||
WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE,
|
|
||||||
pgStatSock, -1L,
|
|
||||||
WAIT_EVENT_PGSTAT_MAIN);
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4688,18 +4693,15 @@ PgstatCollectorMain(int argc, char *argv[])
|
|||||||
* to not provoke "using stale statistics" complaints from
|
* to not provoke "using stale statistics" complaints from
|
||||||
* backend_read_statsfile.
|
* backend_read_statsfile.
|
||||||
*/
|
*/
|
||||||
wr = WaitLatchOrSocket(MyLatch,
|
wr = WaitEventSetWait(wes, 2 * 1000L /* msec */ , &event, 1,
|
||||||
WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE | WL_TIMEOUT,
|
WAIT_EVENT_PGSTAT_MAIN);
|
||||||
pgStatSock,
|
|
||||||
2 * 1000L /* msec */ ,
|
|
||||||
WAIT_EVENT_PGSTAT_MAIN);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Emergency bailout if postmaster has died. This is to avoid the
|
* Emergency bailout if postmaster has died. This is to avoid the
|
||||||
* necessity for manual cleanup of all postmaster children.
|
* necessity for manual cleanup of all postmaster children.
|
||||||
*/
|
*/
|
||||||
if (wr & WL_POSTMASTER_DEATH)
|
if (wr == 1 && event.events == WL_POSTMASTER_DEATH)
|
||||||
break;
|
break;
|
||||||
} /* end of outer loop */
|
} /* end of outer loop */
|
||||||
|
|
||||||
@ -4708,6 +4710,8 @@ PgstatCollectorMain(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
pgstat_write_statsfiles(true, true);
|
pgstat_write_statsfiles(true, true);
|
||||||
|
|
||||||
|
FreeWaitEventSet(wes);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user