Skip to content

Commit

Permalink
Force the TZ enviroment variable to be set, as this stops linux from …
Browse files Browse the repository at this point in the history
…opening, calling fstat twice and reading /etc/localtime, giving a 2% boost to requests/second.
  • Loading branch information
pquerna committed Nov 14, 2011
1 parent f84c5cb commit 37e5815
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions server/mpm/event/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "apr_version.h"
#include "apr_env.h"

#if APR_HAVE_UNISTD_H
#include <unistd.h>
Expand Down Expand Up @@ -2099,6 +2100,27 @@ static void join_start_thread(apr_thread_t * start_thread_id)
}
}

static void force_set_tz(apr_pool_t *p) {
/* If the TZ variable is unset, many operationg systems,
* such as Linux, will at runtime read from /etc/localtime
* and call fstat on it.
*
* By forcing the time zone to UTC if it is unset, we gain
* about 2% in raw requests/second (since we format log files
* in the local time, if present)
*
* For more info, see:
* <http://www.gnu.org/s/hello/manual/libc/TZ-Variable.html>
*/
char *v = NULL;
apr_status_t rv;

rv = apr_env_get(&v, "TZ", p);
if (v == NULL || rv == APR_ENOENT) {
apr_env_set("TZ", "UTC+0", p);
}
}

static void child_main(int child_num_arg)
{
apr_thread_t **threads;
Expand Down Expand Up @@ -3143,6 +3165,8 @@ static void event_hooks(apr_pool_t * p)
static const char *const aszSucc[] = { "core.c", NULL };
one_process = 0;

force_set_tz(p);

ap_hook_open_logs(event_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST);
/* we need to set the MPM state before other pre-config hooks use MPM query
* to retrieve it, so register as REALLY_FIRST
Expand Down

0 comments on commit 37e5815

Please sign in to comment.