]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #571: Limit use of persistent connections when filedescriptor usage is high
authorhno <>
Sat, 3 Apr 2004 21:25:59 +0000 (21:25 +0000)
committerhno <>
Sat, 3 Apr 2004 21:25:59 +0000 (21:25 +0000)
Under high usage a lot of filedescriptors may be idle persistent connections,
causing a shortage of filedescriptors for handling new requests.

src/client_side_reply.cc
src/fd.cc
src/pconn.cc
src/protos.h

index 6850a4762d99253394413f730622dfd9bfd570ee..a8cb02ca428dbaaa132a7a8e4f1de0bcfc3f8fe1 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_reply.cc,v 1.67 2003/09/01 03:49:38 robertc Exp $
+ * $Id: client_side_reply.cc,v 1.68 2004/04/03 14:25:59 hno Exp $
  *
  * DEBUG: section 88    Client-side Reply Routines
  * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
@@ -1394,6 +1394,11 @@ clientReplyContext::buildReplyHeader()
         request->flags.proxy_keepalive = 0;
     }
 
+    if (fdUsageHigh()) {
+        debug(88, 3) ("clientBuildReplyHeader: Not many unused FDs, can't keep-alive\n");
+        request->flags.proxy_keepalive = 0;
+    }
+
     /* Append VIA */
     {
         LOCAL_ARRAY(char, bbuf, MAX_URL + 32);
index 77b47f1593c4fd0d871d720e3f46a8e6cc5d5a15..4fe2d3fb0cef8d62d206307ae53d69221c574b26 100644 (file)
--- a/src/fd.cc
+++ b/src/fd.cc
@@ -1,6 +1,6 @@
 
 /*
- * $Id: fd.cc,v 1.49 2003/11/09 17:11:11 hno Exp $
+ * $Id: fd.cc,v 1.50 2004/04/03 14:25:59 hno Exp $
  *
  * DEBUG: section 51    Filedescriptor Functions
  * AUTHOR: Duane Wessels
@@ -259,6 +259,20 @@ fdNFree(void)
     return Squid_MaxFD - Number_FD - Opening_FD;
 }
 
+int
+fdUsageHigh(void)
+{
+    int nrfree = fdNFree();
+
+    if (nrfree < (RESERVED_FD << 1))
+        return 1;
+
+    if (nrfree < (Number_FD >> 2))
+        return 1;
+
+    return 0;
+}
+
 /* Called when we runs out of file descriptors */
 void
 fdAdjustReserved(void)
index 3e386c47f53b43491e6b20b789d7845b573fef53..6bbc8300eedf6e2aa0d1cb8c628b38d8ee1e3543 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: pconn.cc,v 1.41 2003/08/16 10:04:34 adrian Exp $
+ * $Id: pconn.cc,v 1.42 2004/04/03 14:25:59 hno Exp $
  *
  * DEBUG: section 48    Persistent Connections
  * AUTHOR: Duane Wessels
@@ -252,7 +252,7 @@ pconnPush(int fd, const char *host, u_short port, const char *domain)
     LOCAL_ARRAY(char, key, SQUIDHOSTNAMELEN + 10);
     LOCAL_ARRAY(char, desc, FD_DESC_SZ);
 
-    if (fdNFree() < (RESERVED_FD << 1)) {
+    if (fdUsageHigh()) {
         debug(48, 3) ("pconnPush: Not many unused FDs\n");
         comm_close(fd);
         return;
index 7895c7de31a79c80d325679bdd3c413f5a7b4c59..38bd516ab5ff212af0468b471d44d06a499cbe50 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.493 2003/10/16 21:40:16 robertc Exp $
+ * $Id: protos.h,v 1.494 2004/04/03 14:25:59 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -248,6 +248,7 @@ SQUIDCEXTERN void fd_bytes(int fd, int len, unsigned int type);
 SQUIDCEXTERN void fdFreeMemory(void);
 SQUIDCEXTERN void fdDumpOpen(void);
 SQUIDCEXTERN int fdNFree(void);
+SQUIDCEXTERN int fdUsageHigh(void);
 SQUIDCEXTERN void fdAdjustReserved(void);
 
 SQUIDCEXTERN fileMap *file_map_create(void);