From 6e546c286c928825fe57e789b3bdd3903310c5b3 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 19 Feb 2002 19:53:35 +0000 Subject: [PATCH] Arrange to call localtime() during postmaster startup. On most Unixen, the first call of localtime() in a process will read /usr/lib/tztab or local equivalent. Better to do this once in the postmaster and inherit the data by fork() than to have to do it during every backend start. --- src/backend/postmaster/postmaster.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index c480bf2f41..e5ce458c0d 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.264 2002/01/10 01:11:45 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.265 2002/02/19 19:53:35 tgl Exp $ * * NOTES * @@ -723,6 +723,10 @@ PostmasterMain(int argc, char *argv[]) /* * Set up signal handlers for the postmaster process. + * + * CAUTION: when changing this list, check for side-effects on the + * signal handling setup of child processes. See tcop/postgres.c, + * bootstrap/bootstrap.c, and postmaster/pgstat.c. */ pqinitmask(); PG_SETMASK(&BlockSig); @@ -749,6 +753,18 @@ PostmasterMain(int argc, char *argv[]) */ whereToSendOutput = None; + /* + * On many platforms, the first call of localtime() incurs significant + * overhead to load timezone info from the system configuration files. + * By doing it once in the postmaster, we avoid having to do it in every + * started child process. The savings are not huge, but they add up... + */ + { + time_t now = time(NULL); + + (void) localtime(&now); + } + /* * Initialize and startup the statistics collector process */ @@ -1793,7 +1809,6 @@ SignalChildren(int signal) Dlelem *curr, *next; Backend *bp; - int mypid = getpid(); curr = DLGetHead(BackendList); while (curr) @@ -1801,7 +1816,7 @@ SignalChildren(int signal) next = DLGetSucc(curr); bp = (Backend *) DLE_VAL(curr); - if (bp->pid != mypid) + if (bp->pid != MyProcPid) { if (DebugLvl >= 1) elog(DEBUG, "SignalChildren: sending signal %d to process %d", @@ -2412,13 +2427,12 @@ CountChildren(void) { Dlelem *curr; Backend *bp; - int mypid = getpid(); int cnt = 0; for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr)) { bp = (Backend *) DLE_VAL(curr); - if (bp->pid != mypid) + if (bp->pid != MyProcPid) cnt++; } if (CheckPointPID != 0) -- GitLab