Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 386071

Summary: >=timezone-data-2011h: Russia: Medvedev's federal law "On calculation of time" causes performance degradation in affected regions
Product: Gentoo Linux Reporter: Dmitry Bilunov <kmeaw>
Component: [OLD] Core systemAssignee: Gentoo Toolchain Maintainers <toolchain>
Severity: normal CC: bircoph, kaikaikai, maksbotan
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Package list:
Runtime testing required: ---
Attachments: Updated timezone-data to patch the performance issue
A patch file used by the ebuild
A test case that shows the performance degradation

Description Dmitry Bilunov 2011-10-07 12:37:11 UTC
According to Kremlin press service, Russian President Dmitry Medvedev
signed a federal law "On calculation of time" on June 9, 2011.
According to the law Russia is abolishing daylight saving time.

timezone-data-2011h and later includes changes caused by this law.

After timezone-data is compiled by zic into binary data and installed,
the system time after the end of october 2011 becomes correct. However,
all applications calling time-related glibc functions suffer a performance

glibc's tzfile.c has a __tzfile_compute function. It checks whether you
have a timezone rule covering the timestamp you want to convert to a
local time value. If there is no such rule, a default zone rule will
be applied.

The problem is that the default rule is a string, that would cause a
glibc's TZ parse routine to be called. So string parsing code is called
every time you convert timestamps.

You can't fix it by simply adding a zero-correction rule since now till
"max", because it would be optimized out by zic.

Reproducible: Always

Steps to Reproduce:
1. Set your timezone to Europe/Moscow
2. Update to timezone-data-2011h or later
3. Call glibc's localtime function
Actual Results:  
Performance degradation by approx. 3200%. Profiling shows lots of sscanf calls in a callgraph.

Expected Results:  
No performance degradation.

Portage 2.2.0_alpha50_p1 (default/linux/amd64/10.0, gcc-4.5.3, glibc-2.13-r4, 3.0.0 x86_64)
System uname: Linux-3.0.0-x86_64-Intel-R-_Core-TM-_i5-2400_CPU_@_3.10GHz-with-gentoo-2.0.3
Timestamp of tree: Mon, 03 Oct 2011 06:15:01 +0000
distcc 3.1 x86_64-pc-linux-gnu [disabled]
app-shells/bash:          4.2_p10
dev-java/java-config:     2.1.11-r3
dev-lang/python:          2.7.2-r3, 3.1.4-r3, 3.2.2
dev-util/cmake:           2.8.5-r2
dev-util/pkgconfig:       0.26
sys-apps/baselayout:      2.0.3
sys-apps/openrc:          0.9.3-r1
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.68
sys-devel/automake:       1.9.6-r3, 1.10.3, 1.11.1-r1
sys-devel/binutils:       2.21.1-r1
sys-devel/gcc:            4.5.3-r1
sys-devel/gcc-config:     1.4.1-r1
sys-devel/libtool:        2.4-r3
sys-devel/make:           3.82-r3
sys-kernel/linux-headers: 2.6.39 (virtual/os-headers)
sys-libs/glibc:           2.13-r4
Repositories: gentoo bitcoin kmeaw Yandex-Internal sunrise msp430
Installed sets: 
ACCEPT_KEYWORDS="amd64 ~amd64 ~ppc"
ACCEPT_LICENSE="* -@EULA skype-eula cadsoft AdobeFlash-10 AdobeFlash-10.1 dlj-1.1 googleearth Oracle-BCLA-JavaSE"
CFLAGS="-O2 -pipe -fomit-frame-pointer -march=core2 -msse4.1 -mfpmath=sse,387"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt /usr/share/openvpn/easy-rsa"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.3/ext-active/ /etc/php/cgi-php5.3/ext-active/ /etc/php/cli-php5.3/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -pipe -fomit-frame-pointer -march=core2 -msse4.1 -mfpmath=sse,387"
FEATURES="assume-digests binpkg-logs distlocks ebuild-locks fixlafiles fixpackages news parallel-fetch preserve-libs protect-owned sandbox sfperms splitdebug strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-O1 -Wl,--sort-common -Wl,--enable-new-dtags"
LINGUAS="en ru"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTDIR_OVERLAY="/var/lib/layman/bitcoin /usr/local/portage/kmeaw /usr/local/portage/yandex /var/lib/layman/sunrise /var/lib/layman/msp430"
USE="X a52 aac acl acpi alsa amd64 audiofile avahi berkdb bindist bluetooth bzip2 caps cli consolekit cracklib crypt cups cxx dbus doc dri dri2 dvd emerald fastcgi ffmpeg fftw fontconfig fuse gd gdbm gif gimp glitz gnutls gphoto2 gpm gstreamer gtk gtkhtml guile i18n i18n-ru iconv imlib ipv6 jabber jpeg lame libcaca libnotify libsamplerate lm_sensors mad matroska mikmod mixer mmap mmx modplug modules mp3 mpeg mplayer mudflap multilib musepack ncurses network networking nls nptl nptlonly nsplugin ocaml openal opengl openmp pam pango pcmcia pcre perl png policykit pppd python readline recode ruby sdl session sharedmem slang sndfile sox speex spell sqlite3 sse sse2 ssh ssl svg sysfs tcpd theora threads timidity truetype udev unicode usb userlocales utf8 v4l v4l2 video vim-syntax vorbis wavpack webkit wifi x264 xcb xcomposite xft xinerama xml xorg xprint xscreensaver zeroconf zlib zsh-completion" ALSA_CARDS="hda-intel seq-dummy virmidi usb-audio" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan stage tables krita karbon braindump" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" GRUB_PLATFORMS="grub_platforms_efi-64" INPUT_DEVICES="keyboard mouse evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en ru" LIRC_DEVICES="asusdh" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="intel" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" 
Comment 1 Dmitry Bilunov 2011-10-07 12:37:59 UTC
Created attachment 289069 [details]
Updated timezone-data to patch the performance issue
Comment 2 Dmitry Bilunov 2011-10-07 12:39:51 UTC
Created attachment 289071 [details, diff]
A patch file used by the ebuild

This patch disables the optimization routine in zic and adds a zero-correction rule since 1996 till "max" so Europe/Moscow becomes UTC+4 forever since 2011.
It works around the performance issue.
Comment 3 Dmitry Bilunov 2011-10-07 12:42:13 UTC
Created attachment 289073 [details]
A test case that shows the performance degradation

% time ./test
Fri Oct  7 16:02:51 2011

./test  3.91s user 0.00s system 99% cpu 3.917 total
% sudo cp /tmp/goodzone /usr/share/zoneinfo/Europe/Moscow 
% time ./test
Fri Oct  7 16:03:07 2011

./test  1.13s user 0.00s system 99% cpu 1.139 total
Comment 4 Jeremy Olexa (darkside) (RETIRED) archtester Gentoo Infrastructure gentoo-dev Security 2011-10-07 14:04:02 UTC
Really good report, BUT, these type of things really need to be reported upstream:

However, I'm not sure that there IS a home right now..
Comment 5 SpanKY gentoo-dev 2011-10-07 15:05:39 UTC
there is: