[Rt-commit] rt branch, 4.2/lower-number-of-tzset-calls, created. rt-4.2.4-35-gc0acf25

Alex Vandiver alexmv at bestpractical.com
Fri May 23 18:08:50 EDT 2014


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

- Log -----------------------------------------------------------------
commit c0acf25e321e6ec3f8ae7ab7545c7d877ccebd75
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 c9f9ca4..eab9380 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -1038,6 +1038,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 c1eb0e1..4d8ab03 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -367,6 +367,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_path,
diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
index cf94610..70d2a56 100644
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@ -65,6 +65,8 @@ use HTTP::Message::PSGI;
 use HTTP::Request;
 use HTTP::Response;
 
+our $SERVER_TIMEZONE;
+
 sub DefaultHandlerArgs  { (
     comp_root            => [
         RT::Interface::Web->ComponentRoots( Names => 1 ),
@@ -201,6 +203,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();
+    }
 
 }
 
@@ -295,6 +301,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