does anyone know if this impacts docker images as well ?
Yes, at least the Docker images that use glibc as their libc. (eg, most Debian/Ubuntu images) It looks like musl, which is used on Alpine Linux images for example, will only read it once, and then cache it: https://github.com/esmil/musl/blob/master/src/time/__tz.c#L1... It has a mutex/lock around the use of the TZ info, but avoids re-stat'ing the localtime file.
How setting the TZ environment variable avoids thousands of system calls
11–20 of 148 posts
Re: How setting the TZ environment variable avoids thousands of system calls
#12Side note - why do some sites completely hide information about who is behind them? I couldn't find a single thing about that on their blog or main site.
Maybe it's just that I use packagecloud and follow people in their circle on Twitter, but Joe Damato is the CEO and founder: https://twitter.com/joedamato I'm under the impression that he may also write a lot these himself? Not entirely certain, though.
Re: How setting the TZ environment variable avoids thousands of system calls
#13If this has a real-world/measurable/etc. impact why isn't this set by default? Are there potential side-effects? Is it set in some distros but not others?
Re: How setting the TZ environment variable avoids thousands of system calls
#14If this has a real-world/measurable/etc. impact why isn't this set by default? Are there potential side-effects? Is it set in some distros but not others?
Probably because while there may be tens of thousands of additional syscalls, the total amount of added latency and resources consumed are more likely to be on a scale of micro/nano/milli seconds.
Re: How setting the TZ environment variable avoids thousands of system calls
#15TZ=:/etc/localtime
I've set TZ sometimes without the colon and it seem to work. I did a quick online search and didn't find anything relevant.
Re: How setting the TZ environment variable avoids thousands of system calls
#16Re: How setting the TZ environment variable avoids thousands of system calls
#17Is there a reason why the path to the timezone file is prefixed with a colon? TZ=:/etc/localtime I've set TZ sometimes without the colon and it seem to work. I did a quick online search and didn't find anything relevant.
Re: How setting the TZ environment variable avoids thousands of system calls
#18I ran an experiment where I timed the runtime of the sample program provided in the OP, except I changed the number of calls to localtime() from ten times to a million. I then timed the difference with and without export TZ=:/etc/localhost. The net savings was .6 seconds. So for a single call to localtime(3), the net savings is 0.6 microseconds.
That's non-zero, but it's likely in the noise compared to everything else that your program might be doing.
Re: How setting the TZ environment variable avoids thousands of system calls
#19Is there a reason why the path to the timezone file is prefixed with a colon? TZ=:/etc/localtime I've set TZ sometimes without the colon and it seem to work. I did a quick online search and didn't find anything relevant.
However the reason it works without : is that the implementation is being lazy and just ignores the : delimiter and falls back to parsing out a filename either way:
https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzset....
Re: How setting the TZ environment variable avoids thousands of system calls
#20Side note - why do some sites completely hide information about who is behind them? I couldn't find a single thing about that on their blog or main site.
$ whois packagecloud.io|grep Owner
Owner Name : JOSEPH DAMATO
Owner OrgName : COMPUTOLOGY, LLC
Owner Addr : 359 FILLMORE ST!12
Owner Addr : SAN FRANCISCO
Owner Addr : CA
Owner Addr : US