Proposed -- untested -- delay pools patch for comment

From: David Luyer <luyer@dont-contact.us>
Date: Thu, 01 Jul 1999 20:40:19 +0800

What do people think of this to fix the delay pools scanning order problem?
[that's a nice word for a long-standing bug which I didn't want to fix :)]

I'm now quite convinced that random() is the best possible sequence to use :-)

[nb. patch is untested beyond the fact it compiles]

My older patch
David.

diff -urN squid-2.2.STABLE3/src/comm_select.c squid-2.2.STABLE3-DJL2/src/comm_select.c
--- squid-2.2.STABLE3/src/comm_select.c Tue Jan 19 06:23:33 1999
+++ squid-2.2.STABLE3-DJL2/src/comm_select.c Thu Jul 1 20:22:49 1999
@@ -528,6 +528,31 @@
     statHistCount(&Counter.comm_http_incoming, nevents);
 }
 
+#if DELAY_POOLS
+static int slowfdcnt = 0;
+static int slowfdarr[SQUID_MAXFD];
+
+static void
+commAddSlowFd(int fd)
+{
+ assert(slowfdcnt < SQUID_MAXFD);
+ slowfdarr[slowfdcnt++] = fd;
+}
+
+static int
+commGetSlowFd(void)
+{
+ int whichfd, retfd;
+
+ if(!slowfdcnt)
+ return -1;
+ whichfd = squid_random() % slowfdcnt;
+ retfd = slowfdarr[whichfd];
+ slowfdarr[whichfd] = slowfdarr[--slowfdcnt];
+ return retfd;
+}
+#endif
+
 #define DEBUG_FDBITS 0
 /* Select on all sockets; call handlers for those that are ready. */
 int
@@ -535,6 +560,9 @@
 {
     fd_set readfds;
     fd_set writefds;
+#if DELAY_POOLS
+ fd_set slowfds;
+#endif
     PF *hdl = NULL;
     int fd;
     int maxfd;
@@ -569,6 +597,9 @@
             howmany(maxfd, FD_MASK_BITS) * FD_MASK_BYTES);
         xmemcpy(&writefds, &global_writefds,
             howmany(maxfd, FD_MASK_BITS) * FD_MASK_BYTES);
+#if DELAY_POOLS
+ FD_ZERO(&slowfds);
+#endif
         /* remove stalled FDs */
         maxindex = howmany(maxfd, FD_MASK_BITS);
         fdsp = (fd_mask *) & readfds;
@@ -580,14 +611,33 @@
                     continue;
                 /* Found a set bit */
                 fd = (j * FD_MASK_BITS) + k;
+#if DELAY_POOLS
+ switch (commDeferRead(fd)) {
+ case 0:
+ break;
+ case 1:
+ FD_CLR(fd, &readfds);
+ break;
+ case -1:
+ FD_SET(fd, &slowfds);
+ break;
+ default:
+ assert(!"commDeferRead(fd) should return 0,1,-1");
+ }
+#else
                 if (commDeferRead(fd))
                     FD_CLR(fd, &readfds);
+#endif
             }
         }
 #if DEBUG_FDBITS
         for (i = 0; i < maxfd; i++) {
             /* Check each open socket for a handler. */
+#if DELAY_POOLS
+ if (fd_table[i].read_handler && commDeferRead(i) != 1) {
+#else
             if (fd_table[i].read_handler && !commDeferRead(i)) {
+#endif
                 assert(FD_ISSET(i, &readfds));
             }
             if (fd_table[i].write_handler) {
@@ -651,12 +701,18 @@
 #endif
                 if (fdIsIcp(fd)) {
                     callicp = 1;
- continue;
+ goto out_r;
                 }
                 if (fdIsHttp(fd)) {
                     callhttp = 1;
- continue;
+ goto out_r;
+ }
+#if DELAY_POOLS
+ if (FD_ISSET(fd, &slowfds)) {
+ commAddSlowFd(fd);
+ goto out_r;
                 }
+#endif
                 F = &fd_table[fd];
                 debug(5, 6) ("comm_select: FD %d ready for reading\n", fd);
                 if (F->read_handler) {
@@ -670,6 +726,7 @@
                     comm_select_icp_incoming();
                 if (commCheckHTTPIncoming)
                     comm_select_http_incoming();
+ out_r:
                 EBIT_CLR(tmask, k); /* this bit is done */
                 if (tmask == 0)
                     break; /* and no more bits left */
@@ -690,11 +747,11 @@
 #endif
                 if (fdIsIcp(fd)) {
                     callicp = 1;
- continue;
+ goto out_w;
                 }
                 if (fdIsHttp(fd)) {
                     callhttp = 1;
- continue;
+ goto out_w;
                 }
                 F = &fd_table[fd];
                 debug(5, 5) ("comm_select: FD %d ready for writing\n", fd);
@@ -709,6 +766,7 @@
                     comm_select_icp_incoming();
                 if (commCheckHTTPIncoming)
                     comm_select_http_incoming();
+ out_w:
                 EBIT_CLR(tmask, k); /* this bit is done */
                 if (tmask == 0)
                     break; /* and no more bits left */
@@ -718,6 +776,23 @@
             comm_select_icp_incoming();
         if (callhttp)
             comm_select_http_incoming();
+#if DELAY_POOLS
+ while((fd = commGetSlowFd()) != -1) {
+ F = &fd_table[fd];
+ debug(5, 6) ("comm_select: slow FD %d selected for reading\n", fd);
+ if (F->read_handler) {
+ hdl = F->read_handler;
+ F->read_handler = NULL;
+ commUpdateReadBits(fd, NULL);
+ hdl(fd, F->read_data);
+ Counter.select_fds++;
+ }
+ if (commCheckICPIncoming)
+ comm_select_icp_incoming();
+ if (commCheckHTTPIncoming)
+ comm_select_http_incoming();
+ }
+#endif
         return COMM_OK;
     } while (timeout > current_dtime);
     debug(5, 8) ("comm_select: time out: %d\n", (int) squid_curtime);
diff -urN squid-2.2.STABLE3/src/forward.c squid-2.2.STABLE3-DJL2/src/forward.c
--- squid-2.2.STABLE3/src/forward.c Wed May 12 04:37:52 1999
+++ squid-2.2.STABLE3-DJL2/src/forward.c Thu Jul 1 19:25:39 1999
@@ -455,6 +455,12 @@
 {
     StoreEntry *e = data;
     MemObject *mem = e->mem_obj;
+#ifdef DELAY_POOLS
+ int i = 0;
+#else
+#define i 0
+#endif
+
     if (mem == NULL)
         return 0;
 #if DELAY_POOLS
@@ -462,14 +468,21 @@
         (void) 0;
     else if (delayIsNoDelay(fd))
         (void) 0;
- else if (delayMostBytesWanted(mem, 1) == 0)
- return 1;
+ else {
+ i = delayMostBytesWanted(mem, INT_MAX);
+ if (i == 0)
+ return 1;
+ i = -(i != INT_MAX);
+ }
 #endif
     if (EBIT_TEST(e->flags, ENTRY_FWD_HDR_WAIT))
- return 0;
+ return i;
     if (mem->inmem_hi - storeLowestMemReaderOffset(e) < READ_AHEAD_GAP)
- return 0;
+ return i;
     return 1;
+#ifndef DELAY_POOLS
+#undef i
+#endif
 }
 
 void
diff -urN squid-2.2.STABLE3/src/ssl.c squid-2.2.STABLE3-DJL2/src/ssl.c
--- squid-2.2.STABLE3/src/ssl.c Thu May 13 02:49:20 1999
+++ squid-2.2.STABLE3-DJL2/src/ssl.c Thu Jul 1 19:19:48 1999
@@ -118,7 +118,14 @@
 sslDeferServerRead(int fdnotused, void *data)
 {
     SslStateData *s = data;
- return delayBytesWanted(s->delay_id, 0, 1) == 0;
+ int i;
+
+ i = delayBytesWanted(s->delay_id, 0, INT_MAX);
+ if(i == INT_MAX)
+ return 0;
+ if(i == 0)
+ return 1;
+ return -1;
 }
 #endif
 
Received on Tue Jul 29 2003 - 13:15:59 MDT

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