You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by br...@apache.org on 2002/03/17 06:13:12 UTC

cvs commit: httpd-2.0/server util_time.c log.c

brianp      02/03/16 21:13:12

  Modified:    .        CHANGES
               include  util_time.h
               server   util_time.c log.c
  Log:
  Use the "recent time" cache to optimize timestamp generation for
  the httpd error log
  
  Background: According to some profile data that we collected on Solaris,
  half the run time of ap_log_rerror() was spent in localtime(3).   With
  this change, the recent-time cache ensures that the error logger won't
  cause more than one localtime() call per second, no matter how high the
  error rate is.
  
  Revision  Changes    Path
  1.638     +2 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.637
  retrieving revision 1.638
  diff -u -r1.637 -r1.638
  --- CHANGES	16 Mar 2002 06:35:11 -0000	1.637
  +++ CHANGES	17 Mar 2002 05:13:12 -0000	1.638
  @@ -1,5 +1,7 @@
   Changes with Apache 2.0.34-dev
   
  +  *) Performance improvement for the error logger [Brian Pane]
  +
     *) Change configure so that Solaris 8 and above have 
        SINGLE_LISTEN_UNSERIALIZED_ACCEPT defined by default.
        according to sun people solaris 8+ doesn't have a thundering
  
  
  
  1.4       +7 -0      httpd-2.0/include/util_time.h
  
  Index: util_time.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/include/util_time.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- util_time.h	13 Mar 2002 20:47:42 -0000	1.3
  +++ util_time.h	17 Mar 2002 05:13:12 -0000	1.4
  @@ -102,6 +102,13 @@
                                                  apr_time_t t);
   
   
  +/**
  + * format a recent timestamp in the ctime() format.
  + * @param date_str String to write to.
  + * @param t the time to convert 
  + */
  +AP_DECLARE(apr_status_t) ap_recent_ctime(char *date_str, apr_time_t t);
  +
   #ifdef __cplusplus
   }
   #endif
  
  
  
  1.5       +45 -0     httpd-2.0/server/util_time.c
  
  Index: util_time.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/util_time.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- util_time.c	13 Mar 2002 20:48:01 -0000	1.4
  +++ util_time.c	17 Mar 2002 05:13:12 -0000	1.5
  @@ -173,3 +173,48 @@
   {
       return cached_explode(tm, t, exploded_cache_gmt, 1);
   }
  +
  +AP_DECLARE(apr_status_t) ap_recent_ctime(char *date_str, apr_time_t t)
  +{
  +    /* ### This code is a clone of apr_ctime(), except that it
  +     * uses ap_explode_recent_localtime() instead of apr_explode_localtime().
  +     */
  +    apr_time_exp_t xt;
  +    const char *s;
  +    int real_year;
  +
  +    /* example: "Wed Jun 30 21:49:08 1993" */
  +    /*           123456789012345678901234  */
  +
  +    ap_explode_recent_localtime(&xt, t);
  +    s = &apr_day_snames[xt.tm_wday][0];
  +    *date_str++ = *s++;
  +    *date_str++ = *s++;
  +    *date_str++ = *s++;
  +    *date_str++ = ' ';
  +    s = &apr_month_snames[xt.tm_mon][0];
  +    *date_str++ = *s++;
  +    *date_str++ = *s++;
  +    *date_str++ = *s++;
  +    *date_str++ = ' ';
  +    *date_str++ = xt.tm_mday / 10 + '0';
  +    *date_str++ = xt.tm_mday % 10 + '0';
  +    *date_str++ = ' ';
  +    *date_str++ = xt.tm_hour / 10 + '0';
  +    *date_str++ = xt.tm_hour % 10 + '0';
  +    *date_str++ = ':';
  +    *date_str++ = xt.tm_min / 10 + '0';
  +    *date_str++ = xt.tm_min % 10 + '0';
  +    *date_str++ = ':';
  +    *date_str++ = xt.tm_sec / 10 + '0';
  +    *date_str++ = xt.tm_sec % 10 + '0';
  +    *date_str++ = ' ';
  +    real_year = 1900 + xt.tm_year;
  +    *date_str++ = real_year / 1000 + '0';
  +    *date_str++ = real_year % 1000 / 100 + '0';
  +    *date_str++ = real_year % 100 / 10 + '0';
  +    *date_str++ = real_year % 10 + '0';
  +    *date_str++ = 0;
  +
  +    return APR_SUCCESS;
  +}
  
  
  
  1.113     +1 -1      httpd-2.0/server/log.c
  
  Index: log.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/log.c,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -r1.112 -r1.113
  --- log.c	16 Mar 2002 18:26:58 -0000	1.112
  +++ log.c	17 Mar 2002 05:13:12 -0000	1.113
  @@ -409,7 +409,7 @@
   
       if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
           errstr[0] = '[';
  -        apr_ctime(errstr + 1, apr_time_now());
  +        ap_recent_ctime(errstr + 1, apr_time_now());
           errstr[1 + APR_CTIME_LEN - 1] = ']';
           errstr[1 + APR_CTIME_LEN    ] = ' ';
           len = 1 + APR_CTIME_LEN + 1;
  
  
  

Re: cvs commit: httpd-2.0/server util_time.c log.c

Posted by Cliff Woolley <jw...@virginia.edu>.
On 17 Mar 2002 brianp@apache.org wrote:

>   +    *date_str++ = real_year % 1000 / 100 + '0';
>   +    *date_str++ = real_year % 100 / 10 + '0';
>   +    *date_str++ = real_year % 10 + '0';
>   +    *date_str++ = 0;
>   +
>   +    return APR_SUCCESS;
>   +}

Nit: that last ++ is useless (granted, any decent optimizer would throw it
away anyhow).

--Cliff

--------------------------------------------------------------
   Cliff Woolley
   cliffwoolley@yahoo.com
   Charlottesville, VA