tpop3d-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tpop3d-discuss][PATCH]: avoid tons of time() calls


From: Arkadiusz Miskiewicz
Subject: Re: [tpop3d-discuss][PATCH]: avoid tons of time() calls
Date: Wed, 28 Jun 2006 20:10:37 +0200
User-agent: KMail/1.9.3

On Wednesday 28 June 2006 19:52, Arkadiusz Miskiewicz wrote:
> Hi,
>
> I've just checked that on busy server I get
> nearly 10000 time() calls per second!
>
> # grep  19:36:04 OUT |grep time | wc -l
> 9668
>
> where OUT is output from strace -tt -f -F -s 200 -p 5571 -o OUT
> (5571 is main parent of all tpop3d childs).
>
> Do we need to call it so often?
>
> In most cases if (!(c = connections[i])) will just continue and I see no
> point to check time every iteration.
>
> --- netloop.c       2006-06-26 07:30:25.000000000 +0200
> +++ netloop.c   2006-06-28 19:46:00.000000000 +0200
> @@ -387,16 +387,20 @@
>      static size_t i;
>      size_t i0;
>      time_t start;
> +    int latency = 1;
>
>      time(&start);
>
> -    for (i0 = (i + max_connections - 1) % max_connections; time(NULL) <
> start + LATENCY && i != i0; i = (i + 1) % max_connections) { +    for (i0 =
> (i + max_connections - 1) % max_connections; latency && i != i0; i = (i +
> 1) % max_connections) { connection c;
>          int r;
>
>          if (!(c = connections[i]))
>              continue;
>
> +       if (time(NULL) >= start + LATENCY)
> +               latency = 0;
> +
>          if (i > 0 && post_fork) {
>              connections[0] = c;
>              connections[i] = NULL;

Even better:

@@ -387,16 +387,22 @@
     static size_t i;
     size_t i0;
     time_t start;
+    int latency = 1;

     time(&start);

-    for (i0 = (i + max_connections - 1) % max_connections; time(NULL) < start 
+ LATENCY && i != i0; i = (i + 1) % max_connections) {
+    for (i0 = (i + max_connections - 1) % max_connections; latency && i != i0; 
i = (i + 1) % max_connections) {
         connection c;
         int r;

         if (!(c = connections[i]))
             continue;

+       if (time(NULL) >= start + LATENCY) {
+               latency = 0;
+               continue;
+       }
+
         if (i > 0 && post_fork) {
             connections[0] = c;
             connections[i] = NULL;


ps. remember poll(..., n + 1, ...) change to poll(..., n, ....) in my latest 
,,fixes'' patch?
The original (n+1) was correct, please revert that change. poll want's number
of elements in an array - not highest index. Sorry for that.

-- 
Arkadiusz Miƛkiewicz        PLD/Linux Team
arekm / maven.pl            http://ftp.pld-linux.org/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]