From: hno <> Date: Sat, 3 Apr 2004 21:25:59 +0000 (+0000) Subject: Bug #571: Limit use of persistent connections when filedescriptor usage is high X-Git-Tag: SQUID_3_0_PRE4~1129 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a1ca9253049b2af35e71febfa8b17f0d728750c5;p=thirdparty%2Fsquid.git Bug #571: Limit use of persistent connections when filedescriptor usage is high Under high usage a lot of filedescriptors may be idle persistent connections, causing a shortage of filedescriptors for handling new requests. --- diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 6850a4762d..a8cb02ca42 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -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); diff --git a/src/fd.cc b/src/fd.cc index 77b47f1593..4fe2d3fb0c 100644 --- 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) diff --git a/src/pconn.cc b/src/pconn.cc index 3e386c47f5..6bbc8300ee 100644 --- a/src/pconn.cc +++ b/src/pconn.cc @@ -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; diff --git a/src/protos.h b/src/protos.h index 7895c7de31..38bd516ab5 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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);