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

Arkadiusz Miskiewicz arekm at pld-linux.org
Wed, 28 Jun 2006 19:52:08 +0200


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 =3D connections[i])) will just continue and I see no =
point
to check time every iteration.

=2D-- 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 =3D 1;

     time(&start);

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

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

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

=2D-=20
Arkadiusz Mi=B6kiewicz        PLD/Linux Team
arekm / maven.pl            http://ftp.pld-linux.org/