From 4f0a2774b5e71fdc83553de7d563f7bc3db74866 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Tue, 22 Nov 2016 13:03:55 -0500 Subject: main: set TZ in environment if not already set. If TZ is not set in environment, then datetime.datetime() will stat /etc/localtime on every usage. datetime is used in the logging path of cloud-init, and as such this is very busy. During a normal cloud-init boot, it results in we roughly 400+ stat calls to /etc/localtime. The value we set is :/etc/localtime, which is described at https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html See also merge proposal at 307722 for more background. https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/307722 --- cloudinit/cmd/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py index fe37075e..26c02401 100644 --- a/cloudinit/cmd/main.py +++ b/cloudinit/cmd/main.py @@ -694,4 +694,6 @@ def main(sysv_args=None): if __name__ == '__main__': + if 'TZ' not in os.environ: + os.environ['TZ'] = ":/etc/localtime" main(sys.argv) -- cgit v1.2.3