From 306c7549ecba79463ba54b9a544268e53c63bd3f Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Mon, 20 May 2013 17:29:20 -0400 Subject: [PATCH] Set TZ environment variable to avoid a stat call By setting the TZ environment variable for the WSGI process we avoid the stat("/etc/localtime") on every request handled that logs using strftime(). Change-Id: Ifc78236a99ed193a42389e383d062b38f57a5a31 Signed-off-by: Peter Portante --- swift/common/wsgi.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 63e86777d4..39bae45de5 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -245,6 +245,12 @@ def run_wsgi(conf_path, app_section, *args, **kwargs): # redirect errors to logger and close stdio capture_stdio(logger) + # Ensure TZ environment variable exists to avoid stat('/etc/localtime') on + # some platforms. This locks in reported times to the timezone in which + # the server first starts running in locations that periodically change + # timezones. + os.environ['TZ'] = time.strftime("%z", time.gmtime()) + worker_count = int(conf.get('workers', '1')) # Useful for profiling [no forks]. if worker_count == 0: