--------------------- PatchSet 7129 Date: 2005/10/25 09:09:20 Author: adri Branch: tidyup_deferred_reads Tag: (none) Log: Replace the accept defer handler with a 1 second rescheduling. This backs off the polled socket for one second. The behaviour isn't the same as the defer handler: the one handler defers IO for /all/ incoming sockets whereas this change makes it defer for just the one. But it does save checking every time through the IO loop. Members: src/client_side.c:1.47.2.59.4.4->1.47.2.59.4.5 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.47.2.59.4.4 retrieving revision 1.47.2.59.4.5 diff -u -r1.47.2.59.4.4 -r1.47.2.59.4.5 --- squid/src/client_side.c 15 Oct 2005 04:34:20 -0000 1.47.2.59.4.4 +++ squid/src/client_side.c 25 Oct 2005 09:09:20 -0000 1.47.2.59.4.5 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.47.2.59.4.4 2005/10/15 04:34:20 adri Exp $ + * $Id: client_side.c,v 1.47.2.59.4.5 2005/10/25 09:09:20 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -142,7 +142,6 @@ static int clientCachable(clientHttpRequest * http); static int clientHierarchical(clientHttpRequest * http); static int clientCheckContentLength(request_t * r); -static DEFER httpAcceptDefer; static log_type clientProcessRequest2(clientHttpRequest * http); static int clientReplyBodyTooLarge(clientHttpRequest *, squid_off_t clen); static int clientRequestBodyTooLarge(squid_off_t clen); @@ -3483,7 +3482,7 @@ } static int -httpAcceptDefer(int fdunused, void *dataunused) +httpCheckAcceptDefer(int fd, void *dataunused) { static time_t last_warn = 0; if (fdNFree() >= RESERVED_FD) @@ -3509,8 +3508,11 @@ #if USE_IDENT static aclCheck_t identChecklist; #endif - commSetSelect(sock, COMM_SELECT_READ, httpAccept, NULL, 0); - while (max-- && !httpAcceptDefer(sock, NULL)) { + while (max--) { + if (! httpCheckAcceptDefer(sock, NULL)) { + commDeferReadUntil(sock, 1, httpAccept, NULL); + return; + } memset(&peer, '\0', sizeof(struct sockaddr_in)); memset(&me, '\0', sizeof(struct sockaddr_in)); if ((fd = comm_accept(sock, &peer, &me)) < 0) { @@ -3547,6 +3549,7 @@ assert(N); (*N)++; } + commSetSelect(sock, COMM_SELECT_READ, httpAccept, NULL, 0); } #if USE_SSL @@ -3615,8 +3618,11 @@ #if USE_IDENT static aclCheck_t identChecklist; #endif - commSetSelect(sock, COMM_SELECT_READ, httpsAccept, https_port, 0); - while (max-- && !httpAcceptDefer(sock, NULL)) { + while (max--) { + if (! httpCheckAcceptDefer(sock, NULL)) { + commDeferReadUntil(sock, 1, httpsAccept, NULL); + return; + } memset(&peer, '\0', sizeof(struct sockaddr_in)); memset(&me, '\0', sizeof(struct sockaddr_in)); if ((fd = comm_accept(sock, &peer, &me)) < 0) { @@ -3664,6 +3670,7 @@ clientdbEstablished(peer.sin_addr, 1); (*N)++; } + commSetSelect(sock, COMM_SELECT_READ, httpsAccept, https_port, 0); } #endif /* USE_SSL */ @@ -3815,11 +3822,6 @@ continue; comm_listen(fd); commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0); - /* - * We need to set a defer handler here so that we don't - * peg the CPU with select() when we hit the FD limit. - */ - commSetDefer(fd, httpAcceptDefer, NULL); debug(1, 1) ("Accepting HTTP connections at %s, port %d, FD %d.\n", inet_ntoa(s->s.sin_addr), (int) ntohs(s->s.sin_port), @@ -3856,7 +3858,6 @@ https_port->sslContext = sslCreateContext(s->cert, s->key, s->version, s->cipher, s->options); comm_listen(fd); commSetSelect(fd, COMM_SELECT_READ, httpsAccept, https_port, 0); - commSetDefer(fd, httpAcceptDefer, NULL); debug(1, 1) ("Accepting HTTPS connections at %s, port %d, FD %d.\n", inet_ntoa(s->s.sin_addr), (int) ntohs(s->s.sin_port),