Squid b17 patch

From: Michael O'Reilly <michael@dont-contact.us>
Date: 23 Mar 1998 13:01:24 +0800

Little patch that does two things:

#1. close() called on a network socket on linux doesn't block, so
there's no point in paying the cost an aioClose.

#2. More importantly, comm_select_incoming is getting called WAY too
often on machines with lot of file handles. It's getting called when a
filehandle is tested, rather than when a handler is actually called
(no point in doing it per check, the check is _very_ cheap. The
handler may not be).

So this patch changes it to be called at least once per invocation of
comm_select(), and then every 16 handlers.

This patch fairly dramatically dropped my CPU load without causing any
noticeable impact on anything else (my box does around 40-50 TCP
requests/second on average).

--- comm.c.old Mon Mar 23 12:47:46 1998
+++ comm.c Mon Mar 23 12:53:29 1998
@@ -640,7 +640,7 @@
     if (F->uses) /* assume persistent connect count */
         pconnHistCount(1, F->uses);
     fd_close(fd); /* update fdstat */
-#if USE_ASYNC_IO
+#if USE_ASYNC_IO && !defined(_SQUID_LINUX_)
     aioClose(fd);
 #else
     close(fd);
@@ -1044,6 +1044,9 @@
             else
                 setSocketShutdownLifetimes(1);
         }
+
+ comm_select_incoming();
+
         nfds = 0;
         maxfd = Biggest_FD + 1;
         for (i = 0; i < maxfd; i++) {
@@ -1098,11 +1101,7 @@
             if (!FD_ISSET(fd, &readfds) && !FD_ISSET(fd, &writefds))
                 continue;
             if (fdIsHttpOrIcp(fd)) {
- if (num < 7)
- comm_select_incoming();
                 continue;
- } else if ((incoming_counter++ & (lastinc > 0 ? 1 : 7)) == 0) {
- comm_select_incoming();
             }
             if (FD_ISSET(fd, &readfds)) {
                 debug(5, 6) ("comm_select: FD %d ready for reading\n", fd);
@@ -1111,6 +1110,8 @@
                     fd_table[fd].read_handler = NULL;
                     hdl(fd, fd_table[fd].read_data);
                 }
+ if ((++incoming_counter & 15) == 0)
+ comm_select_incoming();
             }
             if (FD_ISSET(fd, &writefds)) {
                 debug(5, 5) ("comm_select: FD %d ready for writing\n", fd);
@@ -1119,6 +1120,8 @@
                     fd_table[fd].write_handler = NULL;
                     hdl(fd, fd_table[fd].write_data);
                 }
+ if ((++incoming_counter & 15) == 0)
+ comm_select_incoming();
             }
             lastinc = polledinc;
         }
Received on Tue Jul 29 2003 - 13:15:47 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:11:44 MST