[Rt-commit] rt branch, 4.2/lower-number-of-tzset-calls, created. rt-4.0.6-489-g840db7b

Ruslan Zakirov ruz at bestpractical.com
Sun Aug 26 16:25:04 EDT 2012


The branch, 4.2/lower-number-of-tzset-calls has been created
        at  840db7bb63a70cace412501bdba2f1e669c7c26d (commit)

- Log -----------------------------------------------------------------
commit 840db7bb63a70cace412501bdba2f1e669c7c26d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun Aug 26 01:21:20 2012 +0400

    lower number of POSIX::tzset calls
    
    We call tzset twice per date to set new and restore old values. These
    two calls on my laptop take 0.0014s. For ticket's history with 100
    transactions (any txn, not only replies) it takes 0.14s to call tzset.
    
    Instead we can compare TZ env to required value in RT::Date. If
    values are equal we can skip tzset.
    
    To further increase chances of equality we set TZ env to current
    user's environment and clean it up when request ends. This part
    is QUESTIONABLE as it probably messes with calls to system.

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index ed094d0..135dcc3 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -961,6 +961,8 @@ sub Localtime
     my @local;
     if ($tz eq 'UTC') {
         @local = gmtime($unix);
+    } elsif ( ($ENV{'TZ'}||'') eq $tz ) {
+        @local = localtime($unix);
     } else {
         {
             local $ENV{'TZ'} = $tz;
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index d036518..8bce3f2 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -312,6 +312,12 @@ sub HandleRequest {
     # Process per-page global callbacks
     $HTML::Mason::Commands::m->callback( %$ARGS, CallbackName => 'Default', CallbackPage => '/autohandler' );
 
+    # set timezone to user's to avoid tzset calls
+    {
+        $ENV{'TZ'} = RT::Date->new($HTML::Mason::Commands::session{'CurrentUser'})->Timezone('user');
+        POSIX::tzset();
+    }
+
     ShowRequestedPage($ARGS);
     LogRecordedSQLStatements(RequestData => {
         Path => $HTML::Mason::Commands::m->request_comp->path,
diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
index 5af3025..bb993d6 100644
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@ -63,6 +63,8 @@ use File::Path qw( rmtree );
 use File::Glob qw( bsd_glob );
 use File::Spec::Unix;
 
+our $SERVER_TIMEZONE;
+
 sub DefaultHandlerArgs  { (
     comp_root            => [
         RT::Interface::Web->ComponentRoots( Names => 1 ),
@@ -200,6 +202,10 @@ sub CleanupRequest {
     File::Temp::cleanup()
             unless $INC{'Test/WWW/Mechanize/PSGI.pm'};
 
+    if ( ($SERVER_TIMEZONE||'') ne ($ENV{'TZ'}||'') ) {
+        $ENV{'TZ'} = $SERVER_TIMEZONE;
+        POSIX::tzset();
+    }
 
 }
 
@@ -246,6 +252,8 @@ sub PSGIApp {
         }
         $env->{PATH_INFO} = $self->_mason_dir_index( $h->interp, $req->path_info);
 
+        $SERVER_TIMEZONE = $ENV{'TZ'};
+
         my $ret;
         {
             # XXX: until we get rid of all $ENV stuff.

-----------------------------------------------------------------------


More information about the Rt-commit mailing list