Patch to fix comm_incoming (squid-1.2beta22)

From: Stewart Forster <slf@dont-contact.us>
Date: Thu, 04 Jun 1998 16:35:50 +1000

--MimeMultipartBoundary
Content-Type: text/plain; charset=us-ascii

Hiya,

        Some problems with the standard beta22 comm_incoming business.

        As noted by Michael O'Reilly, if there stuff on the UDP write
queue, that never gets sent. I've fixed this by adding a check in
icpHandleUdp to call and reset the write handler on a UDP socket if
it's set. That way the queue gets cleared when necessary.

        Further, the algorithm was a fair bit of a shambles. It required
progressively larger and larger `incame' values just to keep the current
incoming_interval where it was. ie. if the incoming_interval rate dropped,
the we needed to have even more `incame' just to keep it there. That's
kinda against what the whole idea was. It was fighting an increasing
curve.

        My new algorithm is much simpler and does away with the horrible
division array. I've assumed that we want half of our number of incoming
sockets to have activity on them (on average).

        incoming_interval = incoming_interval + (no_incoming_sockets / 2)
                            - incame;

        This allows for fairly rapid dropping on the incoming_interval
when things start blowing out, but only increases fairly slowly. Also,
since we only want to call the checks when things are probably going to
happen we avoid excessive calls and also excessive delays.

        Cheers,

                Stew.

===================================================================
RCS file: RCS/main.c,v
retrieving revision 1.1
diff -u -r1.1 main.c
--- main.c 1998/06/04 06:24:29 1.1
+++ main.c 1998/06/04 06:27:21
@@ -392,6 +392,7 @@
     if (theOutIcpConnection >= 0 && (!Config2.Accel.on ||
Config.onoff.accel_with_proxy))
        neighbors_open(theOutIcpConnection);
     storeDirOpenSwapLogs();
+ commConfigure();
     debug(1, 0) ("Ready to serve requests.\n");
     reconfiguring = 0;
 }
@@ -500,6 +501,7 @@
     serverConnectionsOpen();
     if (theOutIcpConnection >= 0 && (!Config2.Accel.on ||
Config.onoff.accel_with_proxy))
        neighbors_open(theOutIcpConnection);
+ commConfigure();
 
     if (!configured_once)
        writePidFile(); /* write PID file */
===================================================================
RCS file: RCS/comm.c,v
retrieving revision 1.1
diff -u -r1.1 comm.c
--- comm.c 1998/06/04 06:06:49 1.1
+++ comm.c 1998/06/04 06:31:01
@@ -113,7 +113,7 @@
 #endif
 
 #if USE_ASYNC_IO
-#define MAX_POLL_TIME 50
+#define MAX_POLL_TIME 10
 #else
 #define MAX_POLL_TIME 1000
 #endif
@@ -181,12 +181,12 @@
  * Every time we check incoming sockets, we count how many new messages
  * or connections were processed. This is used to adjust the
  * incoming_interval for the next iteration. The new incoming_interval
- * is calculated as the average of the current incoming_interval and
- * 32 divided by the number of incoming events just processed. e.g.
+ * is calculated as the current incoming_interval plus what we would
+ * like to see as an average number of events minus the number of
+ * events just processed.
  *
- * 1 1 32
- * incoming_interval = - incoming_interval + - -----------------
- * 2 2 incoming_events
+ * incoming_interval = incoming_interval + (number_of_incoming_sockets / 2)
+ * - number_of_events_processed
  *
  * You can see the current value of incoming_interval, as well as
  * a histogram of 'incoming_events' by asking the cache manager
@@ -194,22 +194,17 @@
  *
  * % ./client mgr:comm_incoming
  *
- * Bugs:
+ * Caveats:
  *
  * - We have 32 as a magic upper limit on incoming_interval.
- * - INCOMING_TOTAL_MAX = INCOMING_ICP_MAX + INCOMING_HTTP_MAX,
- * but this assumes only one ICP socket and one HTTP socket.
- * If there are multiple incoming HTTP sockets, the we could
- * conceivably process more than INCOMING_TOTAL_MAX events
- * in comm_incoming().
- *
- * The 'invert32[]' array is a pre-calculated array of division for 32/i
  *
  */
+#define INCOMING_FACTOR 6
+#define MAX_INCOMING_INTERVAL (32 << INCOMING_FACTOR)
 static int io_events = 0;
-static int incoming_interval = 16 << 4;
-static int invert32[INCOMING_TOTAL_MAX];
-#define commCheckIncoming (++io_events > (incoming_interval>>4))
+static int average_incoming = 1;
+static int incoming_interval = 16 << INCOMING_FACTOR;
+#define commCheckIncoming (++io_events > (incoming_interval>>INCOMING_FACTOR))
 
 static void
 CommWriteStateCallbackAndFree(int fd, int code)
@@ -780,8 +775,11 @@
        httpAccept(HttpSockets[j], &incame);
     }
     statHistCount(&Counter.comm_incoming, incame);
- if (incame < INCOMING_TOTAL_MAX)
- incoming_interval = (incoming_interval >> 1) + (invert32[incame] << 3);
+ incoming_interval = incoming_interval + 2 - incame;
+ if (incoming_interval < 0)
+ incoming_interval = 0;
+ if (incoming_interval > MAX_INCOMING_INTERVAL)
+ incoming_interval = MAX_INCOMING_INTERVAL;
 }
 
 static int
@@ -1189,6 +1187,17 @@
 #endif
 
 void
+commConfigure(void)
+{
+ average_incoming = NHttpSockets >> 1;
+ if (theInIcpConnection != theOutIcpConnection)
+ average_incoming++;
+ if (average_incoming < 1)
+ average_incoming = 1;
+}
+
+
+void
 comm_init(void)
 {
     int i;
@@ -1200,9 +1209,6 @@
     RESERVED_FD = XMIN(100, Squid_MaxFD / 4);
     zero_tv.tv_sec = 0;
     zero_tv.tv_usec = 0;
- invert32[0] = 32;
- for (i = 1; i < INCOMING_TOTAL_MAX; i++)
- invert32[i] = (int) (32.0 / (double) i + 0.5);
     cachemgrRegister("comm_incoming",
        "comm_incoming() stats",
        commIncomingStats, 0);
@@ -1420,7 +1426,7 @@
 {
     StatCounters *f = &Counter;
     storeAppendPrintf(sentry, "Current incoming_interval: %d\n",
- incoming_interval >> 4);
+ incoming_interval >> INCOMING_FACTOR);
     storeAppendPrintf(sentry, "\n");
     storeAppendPrintf(sentry, "Histogram of number of incoming sockets or\n");
     storeAppendPrintf(sentry, "Messages handled per comm_incoming() call:\n");
===================================================================
RCS file: RCS/icp_v2.c,v
retrieving revision 1.1
diff -u -r1.1 icp_v2.c
--- icp_v2.c 1998/06/04 06:01:03 1.1
+++ icp_v2.c 1998/06/04 06:04:00
@@ -307,7 +307,13 @@
     int len;
     int icp_version;
     int max = INCOMING_ICP_MAX;
+ PF *hdl = NULL;
+
     commSetSelect(sock, COMM_SELECT_READ, icpHandleUdp, NULL, 0);
+ if ((hdl = fd_table[sock].write_handler) != NULL) {
+ fd_table[sock].write_handler = NULL;
+ hdl(sock, fd_table[sock].write_data);
+ }
     while (max--) {
        from_len = sizeof(from);
        memset(&from, '\0', from_len);

--MimeMultipartBoundary--
Received on Tue Jul 29 2003 - 13:15:50 MDT

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