[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-httpd-dev
Subject:    Re: [PATCH] small optimization in ap_meets_conditions() and
From:       "Jean-Jacques Clar" <JJCLAR () novell ! com>
Date:       2003-02-27 20:48:53
[Download RAW message or body]

Since the target value is in second, it should be possible to use
r->request_time instead of calling apr_time_now().
I ran a load test on my box and did not ever see a difference between
the sec value in r->request_time and the one returned by
apr_time_now().
 
end of the patch part......
 
-----------------------------------------------
 
Questions: 
1- 
It should also be valuable to change the return format of
apr_date_parse_http() to be in seconds instead of uSEC.
This is a snippet of the last part of that function:
 
--- boc ---
    /* ap_mplode_time uses tm_usec and tm_gmtoff fields, but they
haven't 
     * been set yet. 
     * It should be safe to just zero out these values.
     * tm_usec is the number of microseconds into the second.  HTTP
only
     * cares about second granularity.
     * tm_gmtoff is the number of seconds off of GMT the time is.  By
     * definition all times going through this function are in GMT, so
this
     * is zero. 
     */
    ds.tm_usec = 0;
--- eoc ---
 
and the time is exploded to match the apr_time_t format.
 
A call to apr_date_parse_httpd() is usually followed by a call to
apr_time_sec(), which do a 64 bits division to get the time in second.
What about having a new function called apr_date_parse_httpd_sec(),
which skip the end part of apr_time_exp_get() and return seconds?
It implies a small change to apr_time_exp_get() and moving the core
code in apr_time_exp_get() to apr_time_exp_get_sec().:
 
--- boc ---
APR_DECLARE(apr_status_t) apr_time_exp_get(apr_time_t *t,
apr_time_exp_t *xt)
{
    apr_status_t ret;
 
    ret = apr_time_exp_get_sec(t, xt);
    if (ret == APR_SUCCESS)
        *t = *t * APR_USEC_PER_SEC + xt->tm_usec;
 
    return ret;
}
--- eoc ---
 
-----------
 
2: 
What about creating a new define called: 
#define APR_HAS_USEC.
 
The else of that option could allow apache to run using ONLY sec for
all apr_time_t field removing all 64 bits division to transform uSEC to
sec.
The size of the apr_time_t variables could also be changed to 32 bits
and calls to gettimeofday() changed to time().
Why is apache using uSEC, when time variables are mostly used in
seconds at run-time, and that http requirements use seconds from my
modest knownledge.
The performance gain is minor but measurable: between 1 and 2.5% on my
box (from 1 to 4 CPUs).
 
-----------
 
3:
On having a time variable in the mpm keeping updated sec and uSEC
field:
NetWare has its main thread resuming every 1000000 uSEC (1 sec) to do
the idle server maintenance.
I am thinking of using a set of functions like the following ones:
 
--- boc ---
static apr_int32_t mpm_clock_initialized;
static apr_time_t now;
struct timeval tv;
 
static void synchonize_usec_clock( void )
{
  static apr_int32_t counter;
 
  if (mpm_clock_initialized) {
    if(++counter > 4) {
      gettimeofday(&tv, NULL);
      now = tv.tv_sec * APR_USEC_PER_SEC + tv.tv_usec;
      counter = 0;
    }
    else
      now += SCOREBOARD_MAINTENANCE_INTERVAL;
  }
  else {
    gettimeofday(&tv, NULL);
    now = tv.tv_sec * APR_USEC_PER_SEC + tv.tv_usec;
    mpm_clock_initialized = 1;
  }
}
 
AP_DECLARE(apr_time_t) ap_time_now(void)
{
  if (mpm_clock_initialized) 
    return now;
  else
    return apr_time_now();
}
--- eoc ---
 
The synchonize_usec_clock() function is called every second by the main
thread. 
It synchronizes the time fields every 5 seconds using the
gettimeofday() function. 
Calls to apr_time_now() in apache could then be replaced with call to
ap_time_now().
 
-----------
 
Thank you,
 
Jean-Jacques 


[Attachment #3 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV style="FONT: 10pt Tahoma">
<DIV>Since the target value is in second, it should be possible to use 
r-&gt;request_time instead of calling apr_time_now().</DIV>
<DIV>I ran a load test on my box and did not ever see a difference between the 
sec value in r-&gt;request_time and the one returned by apr_time_now().</DIV>
<DIV>&nbsp;</DIV>
<DIV>end of the patch&nbsp;part......</DIV>
<DIV>&nbsp;</DIV>
<DIV>-----------------------------------------------</DIV>
<DIV>&nbsp;</DIV>
<DIV>Questions: </DIV>
<DIV>1- </DIV>
<DIV>It should also be valuable to change the return format of 
apr_date_parse_http() to be in seconds instead of uSEC.</DIV>
<DIV>This is a snippet of the last part of that function:</DIV>
<DIV>&nbsp;</DIV>
<DIV>--- boc ---</DIV>
<DIV>&nbsp;&nbsp;&nbsp; /* ap_mplode_time uses tm_usec and tm_gmtoff fields, but 
they haven't <BR>&nbsp;&nbsp;&nbsp;&nbsp; * been set yet. 
<BR>&nbsp;&nbsp;&nbsp;&nbsp; * It should be safe to just zero out these 
values.<BR>&nbsp;&nbsp;&nbsp;&nbsp; * tm_usec is the number of microseconds into 
the second.&nbsp; HTTP only<BR>&nbsp;&nbsp;&nbsp;&nbsp; * cares about second 
granularity.<BR>&nbsp;&nbsp;&nbsp;&nbsp; * tm_gmtoff is the number of seconds 
off of GMT the time is.&nbsp; By<BR>&nbsp;&nbsp;&nbsp;&nbsp; * definition all 
times going through this function are in GMT, so 
this<BR>&nbsp;&nbsp;&nbsp;&nbsp; * is zero. <BR>&nbsp;&nbsp;&nbsp;&nbsp; 
*/<BR>&nbsp;&nbsp;&nbsp; ds.tm_usec = 0;<BR>--- eoc ---</DIV>
<DIV>&nbsp;</DIV>
<DIV>and the time is exploded to match the apr_time_t format.</DIV>
<DIV>&nbsp;</DIV>
<DIV>A call to apr_date_parse_httpd() is usually followed by a call to 
apr_time_sec(), which do a 64 bits division to get the time in second.</DIV>
<DIV>What about having a new function called apr_date_parse_httpd_sec(), which 
skip the end part of apr_time_exp_get() and return seconds?</DIV>
<DIV>It implies a small change to apr_time_exp_get() and moving the core code in 
apr_time_exp_get() to apr_time_exp_get_sec().:</DIV>
<DIV>&nbsp;</DIV>
<DIV>--- boc ---</DIV>
<DIV>APR_DECLARE(apr_status_t) apr_time_exp_get(apr_time_t *t, apr_time_exp_t 
*xt)<BR>{<BR>&nbsp;&nbsp;&nbsp; apr_status_t ret;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; ret = apr_time_exp_get_sec(t, xt);<BR>&nbsp;&nbsp;&nbsp; 
if (ret == APR_SUCCESS)</DIV>
<DIV>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *t = *t * APR_USEC_PER_SEC + 
xt-&gt;tm_usec;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; return ret;<BR>}<BR>--- eoc ---</DIV>
<DIV>&nbsp;</DIV>
<DIV>-----------</DIV>
<DIV>&nbsp;</DIV>
<DIV>2: </DIV>
<DIV>What about creating a new define called: </DIV>
<DIV>#define APR_HAS_USEC.</DIV>
<DIV>&nbsp;</DIV>
<DIV>The else of that option&nbsp;could allow apache to run using ONLY sec for 
all apr_time_t field removing all 64 bits division to transform uSEC to 
sec.</DIV>
<DIV>The size of the apr_time_t variables could also be changed to 32 bits and 
calls to gettimeofday() changed to time().</DIV>
<DIV>Why is apache using uSEC, when time variables are mostly used in seconds at 
run-time, and that http requirements use seconds from my modest <SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">knownledge</SPAN>.</DIV>
<DIV>The performance gain is minor but measurable: between 1 and 2.5%&nbsp;on my 
box (from 1 to 4 CPUs).</DIV>
<DIV>&nbsp;</DIV>
<DIV>-----------</DIV>
<DIV>&nbsp;</DIV>
<DIV>3:</DIV>
<DIV>On having a&nbsp;time variable in the mpm keeping updated sec and uSEC 
field:</DIV>
<DIV>NetWare has its main thread resuming every 1000000 uSEC (1 sec) to do the 
idle server maintenance.</DIV>
<DIV>I am thinking&nbsp;of using a set of functions like the following 
ones:</DIV>
<DIV>&nbsp;</DIV>
<DIV>--- boc ---</DIV>
<DIV>static apr_int32_t mpm_clock_initialized;<BR>static apr_time_t 
now;<BR>struct timeval tv;</DIV>
<DIV>&nbsp;</DIV>
<DIV>static void synchonize_usec_clock( void )<BR>{<BR>&nbsp; static apr_int32_t 
counter;<BR>&nbsp;<BR>&nbsp; if (mpm_clock_initialized) {<BR>&nbsp;&nbsp;&nbsp; 
if(++counter &gt; 4) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gettimeofday(&amp;tv, 
NULL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; now = tv.tv_sec * APR_USEC_PER_SEC + 
tv.tv_usec;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; counter = 0;<BR>&nbsp;&nbsp;&nbsp; 
}<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; now += 
SCOREBOARD_MAINTENANCE_INTERVAL;<BR>&nbsp; }<BR>&nbsp; else 
{<BR>&nbsp;&nbsp;&nbsp; gettimeofday(&amp;tv, NULL);<BR>&nbsp;&nbsp;&nbsp; now = 
tv.tv_sec * APR_USEC_PER_SEC + tv.tv_usec;<BR>&nbsp;&nbsp;&nbsp; 
mpm_clock_initialized = 1;<BR>&nbsp; }<BR>}</DIV>
<DIV>&nbsp;</DIV>
<DIV>AP_DECLARE(apr_time_t) ap_time_now(void)<BR>{<BR>&nbsp;&nbsp;if 
(mpm_clock_initialized)&nbsp;<BR>&nbsp;&nbsp;&nbsp; return now;<BR>&nbsp; 
else<BR>&nbsp;&nbsp;&nbsp; return apr_time_now();<BR>}<BR>--- eoc ---</DIV>
<DIV>&nbsp;</DIV>
<DIV>The synchonize_usec_clock() function is called every second by the main 
thread. </DIV>
<DIV>It&nbsp;synchronizes the time fields every 5 seconds using the 
gettimeofday() function.&nbsp;</DIV>
<DIV>Calls to apr_time_now() in apache could then be replaced with call to 
ap_time_now().</DIV>
<DIV>&nbsp;</DIV>
<DIV>-----------</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thank you,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Jean-Jacques&nbsp;</DIV></DIV></BODY></HTML>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic