From: wessels <> Date: Thu, 28 May 1998 02:31:31 +0000 (+0000) Subject: Changes to comm_*_incoming() X-Git-Tag: SQUID_3_0_PRE1~3239 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ba4f8e5a82791a0fe38afcda497e01b082180c90;p=thirdparty%2Fsquid.git Changes to comm_*_incoming() Now, there is a single comm_incoming() function. This does NOT use select/poll. It just calls the read handlers directly for HTTP and ICP sockets, and relies on them to properly handle EWOULDBLOCK and friends. The rate at which comm_incoming gets called is configurable with 'incoming_min_rate' and 'incoming_max_rate'. Note, these are kind of "backwards" (being rates) and they indicate how many other FD's to process before calling comm_incoming(). When the load is none or low, we call comm_incoming at the 'min_rate' which defaults to once every 16 FDs. During high loads, 'max_rate' takes effect and the default is every 2nd FD. Also added a histogram to count how many connections/messages are processed per call to comm_incoming. This also percipitated some StatHist.c changes. --- diff --git a/src/StatHist.cc b/src/StatHist.cc index 1fec8723e8..a39e7e4d5e 100644 --- a/src/StatHist.cc +++ b/src/StatHist.cc @@ -1,6 +1,6 @@ /* - * $Id: StatHist.cc,v 1.8 1998/04/27 17:25:03 rousskov Exp $ + * $Id: StatHist.cc,v 1.9 1998/05/27 20:31:31 wessels Exp $ * * DEBUG: section 62 Generic Histogram * AUTHOR: Duane Wessels @@ -47,9 +47,7 @@ static void statHistInit(StatHist * H, int capacity, hbase_f val_in, hbase_f val_out, double min, double max); static int statHistBin(const StatHist * H, double v); static double statHistVal(const StatHist * H, int bin); -static void statHistBinDumper(StoreEntry * sentry, int idx, double val, double size, int count); - - +static StatHistBinDumper statHistBinDumper; /* low level init, higher level functions has less params */ static void @@ -194,7 +192,7 @@ statHistBinDumper(StoreEntry * sentry, int idx, double val, double size, int cou } void -statHistDump(const StatHist * H, StoreEntry * sentry, StatHistBinDumper bd) +statHistDump(const StatHist * H, StoreEntry * sentry, StatHistBinDumper *bd) { int i; double left_border = H->min; @@ -232,6 +230,7 @@ Null(double x) { return x; } + void statHistEnumInit(StatHist * H, int last_enum) { @@ -239,9 +238,22 @@ statHistEnumInit(StatHist * H, int last_enum) } void -statHistIntDumper(StoreEntry * sentry, int idx, double val, double size, int count) +statHistEnumDumper(StoreEntry * sentry, int idx, double val, double size, int count) { if (count) storeAppendPrintf(sentry, "%2d\t %5d\t %5d\n", idx, (int) val, count); } + +void +statHistIntInit(StatHist * H, int n) +{ + statHistInit(H, n, &Null, &Null, 0, n-1); +} + +void +statHistIntDumper(StoreEntry * sentry, int idx, double val, double size, int count) +{ + if (count) + storeAppendPrintf(sentry, "%9d\t%9d\n", (int) val, count); +} diff --git a/src/cf.data.pre b/src/cf.data.pre index 29dca93bcb..8022ac2d20 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -2155,4 +2155,16 @@ DOC_START queried only when Squid starts up, not for every request. DOC_END +NAME: incoming_min_rate +TYPE: int +LOC: Config.incoming_rate.min +DEFAULT: 16 +DOC_NONE + +NAME: incoming_max_rate +TYPE: int +LOC: Config.incoming_rate.max +DEFAULT: 2 +DOC_NONE + EOF diff --git a/src/client_side.cc b/src/client_side.cc index 173fcdc91d..187df63419 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.315 1998/05/27 18:35:22 wessels Exp $ + * $Id: client_side.cc,v 1.316 1998/05/27 20:31:33 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -75,6 +75,7 @@ static HttpReply *clientConstructProxyAuthReply(clientHttpRequest * http); static int clientCachable(clientHttpRequest * http); static int clientHierarchical(clientHttpRequest * http); static int clientCheckContentLength(request_t * r); +static int httpAcceptDefer(void); static int checkAccelOnly(clientHttpRequest * http) @@ -2119,8 +2120,8 @@ requestTimeout(int fd, void *data) } } -int -httpAcceptDefer(int fdnotused, void *notused) +static int +httpAcceptDefer(void) { static time_t last_warn = 0; if (fdNFree() >= RESERVED_FD) @@ -2134,14 +2135,15 @@ httpAcceptDefer(int fdnotused, void *notused) /* Handle a new connection on HTTP socket. */ void -httpAccept(int sock, void *notused) +httpAccept(int sock, void *data) { + int *N = data; int fd = -1; ConnStateData *connState = NULL; struct sockaddr_in peer; struct sockaddr_in me; int max = 10; - while (max-- && !httpAcceptDefer(sock, notused)) { + while (max-- && !httpAcceptDefer()) { memset(&peer, '\0', sizeof(struct sockaddr_in)); memset(&me, '\0', sizeof(struct sockaddr_in)); commSetSelect(sock, COMM_SELECT_READ, httpAccept, NULL, 0); @@ -2169,6 +2171,7 @@ httpAccept(int sock, void *notused) commSetTimeout(fd, Config.Timeout.request, requestTimeout, connState); commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, connState, 0); commSetDefer(fd, clientReadDefer, connState); + (*N)++; } } @@ -2355,7 +2358,7 @@ clientHttpConnectionsOpen(void) continue; comm_listen(fd); commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0); - commSetDefer(fd, httpAcceptDefer, NULL); + /*commSetDefer(fd, httpAcceptDefer, NULL);*/ debug(1, 1) ("Accepting HTTP connections on port %d, FD %d.\n", (int) u->i, fd); HttpSockets[NHttpSockets++] = fd; diff --git a/src/comm.cc b/src/comm.cc index 35a6267aad..d5725d91fc 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,7 +1,7 @@ /* - * $Id: comm.cc,v 1.258 1998/05/20 22:07:10 wessels Exp $ + * $Id: comm.cc,v 1.259 1998/05/27 20:31:34 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -118,6 +118,10 @@ #define MAX_POLL_TIME 1000 #endif +#define commCheckIncoming \ + ((++incoming_counter & \ + (lastinc > 0 ? Config.incoming_rate.max : Config.incoming_rate.min)) == 0) + typedef struct { char *host; u_short port; @@ -133,7 +137,7 @@ typedef struct { } ConnectStateData; /* STATIC */ -static int polledinc = 0; +static int incame = 0; static int commBind(int s, struct in_addr, u_short port); #if !HAVE_POLL static int examine_select(fd_set *, fd_set *); @@ -141,11 +145,7 @@ static int examine_select(fd_set *, fd_set *); static void checkTimeouts(void); static void commSetReuseAddr(int); static void commSetNoLinger(int); -#if HAVE_POLL -static void comm_poll_incoming(void); -#else -static void comm_select_incoming(void); -#endif +static void comm_incoming(void); static void CommWriteStateCallbackAndFree(int fd, int code); #ifdef TCP_NODELAY static void commSetTcpNoDelay(int); @@ -741,6 +741,7 @@ commDeferRead(int fd) return F->defer_check(fd, F->defer_data); } +#if OLD_CODE #if HAVE_POLL /* poll() version by: @@ -816,7 +817,6 @@ comm_poll_incoming(void) } /* TO FIX: repoll ICP connection here */ } - #else static void @@ -891,6 +891,25 @@ comm_select_incoming(void) } #endif +#endif /* OLD_CODE */ + +static void +comm_incoming(void) +{ + int j; + incame = 0; + if (theInIcpConnection > 0) + icpHandleUdp(theInIcpConnection, &incame); + if (theInIcpConnection != theOutIcpConnection) + icpHandleUdp(theOutIcpConnection, &incame); + for (j = 0; j < NHttpSockets; j++) { + if (HttpSockets[j] < 0) + continue; + httpAccept(HttpSockets[j], &incame); + } + statHistCount(&Counter.comm_incoming, incame); +} + static int fdIsHttpOrIcp(int fd) { @@ -941,7 +960,7 @@ comm_poll(int msec) #if USE_ASYNC_IO aioCheckCallbacks(); #endif - comm_poll_incoming(); + comm_incoming(); nfds = 0; maxfd = Biggest_FD + 1; for (i = 0; i < maxfd; i++) { @@ -1000,8 +1019,8 @@ comm_poll(int msec) fd_table[fd].read_handler = NULL; hdl(fd, fd_table[fd].read_data); } - if ((++incoming_counter & 15) == 0) - comm_poll_incoming(); + if (commCheckIncoming) + comm_incoming(); } if (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) { debug(5, 5) ("comm_poll: FD %d ready for writing\n", fd); @@ -1009,8 +1028,8 @@ comm_poll(int msec) fd_table[fd].write_handler = NULL; hdl(fd, fd_table[fd].write_data); } - if ((++incoming_counter & 15) == 0) - comm_poll_incoming(); + if (commCheckIncoming) + comm_incoming(); } if (revents & POLLNVAL) { close_handler *ch; @@ -1037,7 +1056,7 @@ comm_poll(int msec) if (F->open != 0) fd_close(fd); } - lastinc = polledinc; + lastinc = incame; } return COMM_OK; } while (timeout > current_dtime); @@ -1088,7 +1107,7 @@ comm_select(int msec) else setSocketShutdownLifetimes(1); } - comm_select_incoming(); + comm_incoming(); nfds = 0; maxfd = Biggest_FD + 1; for (i = 0; i < maxfd; i++) { @@ -1153,8 +1172,8 @@ comm_select(int msec) fd_table[fd].read_handler = NULL; hdl(fd, fd_table[fd].read_data); } - if ((++incoming_counter & 15) == 0) - comm_select_incoming(); + if (commCheckIncoming) + comm_incoming(); } if (FD_ISSET(fd, &writefds)) { debug(5, 5) ("comm_select: FD %d ready for writing\n", fd); @@ -1163,10 +1182,10 @@ comm_select(int msec) fd_table[fd].write_handler = NULL; hdl(fd, fd_table[fd].write_data); } - if ((++incoming_counter & 15) == 0) - comm_select_incoming(); + if (commCheckIncoming) + comm_incoming(); } - lastinc = polledinc; + lastinc = incame; } return COMM_OK; } while (timeout > current_dtime); diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 630171285f..74d1548fda 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -298,8 +298,9 @@ icpPktDump(icp_common_t * pkt) #endif void -icpHandleUdp(int sock, void *datanotused) +icpHandleUdp(int sock, void *data) { + int *N = data; struct sockaddr_in from; int from_len; LOCAL_ARRAY(char, buf, SQUID_UDP_SO_RCVBUF); @@ -332,6 +333,7 @@ icpHandleUdp(int sock, void *datanotused) sock, xstrerror()); break; } + (*N)++; icpCount(buf, RECV, (size_t) len, 0); buf[len] = '\0'; debug(12, 4) ("icpHandleUdp: FD %d: received %d bytes from %s.\n", @@ -382,9 +384,10 @@ icpConnectionsOpen(void) if (theInIcpConnection < 0) fatal("Cannot open ICP Port"); commSetSelect(theInIcpConnection, - COMM_SELECT_READ, - icpHandleUdp, - NULL, 0); + COMM_SELECT_READ, + icpHandleUdp, + NULL, + 0); for (s = Config.mcast_group_list; s; s = s->next) ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL); debug(12, 1) ("Accepting ICP messages on port %d, FD %d.\n", @@ -403,7 +406,8 @@ icpConnectionsOpen(void) commSetSelect(theOutIcpConnection, COMM_SELECT_READ, icpHandleUdp, - NULL, 0); + NULL, + 0); debug(12, 1) ("Outgoing ICP messages on port %d, FD %d.\n", (int) port, theOutIcpConnection); fd_note(theOutIcpConnection, "Outgoing ICP socket"); diff --git a/src/protos.h b/src/protos.h index 6cc254215a..0e509aaeb5 100644 --- a/src/protos.h +++ b/src/protos.h @@ -412,7 +412,6 @@ extern void *icpCreateMessage(icp_opcode opcode, extern int icpUdpSend(int, const struct sockaddr_in *, icp_common_t *, log_type, int); extern PF icpHandleUdp; extern PF httpAccept; -extern DEFER httpAcceptDefer; #ifdef SQUID_SNMP extern PF snmpHandleUdp; @@ -600,7 +599,8 @@ extern double statHistDeltaMedian(const StatHist * A, const StatHist * B); extern void statHistDump(const StatHist * H, StoreEntry * sentry, StatHistBinDumper bd); extern void statHistLogInit(StatHist * H, int capacity, double min, double max); extern void statHistEnumInit(StatHist * H, int last_enum); -extern void statHistIntDumper(StoreEntry * sentry, int idx, double val, double size, int count); +extern StatHistBinDumper statHistEnumDumper; +extern StatHistBinDumper statHistIntDumper; /* MemMeter */ diff --git a/src/stat.cc b/src/stat.cc index 2fbb02d1a8..048567d8e6 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.255 1998/05/26 17:37:48 wessels Exp $ + * $Id: stat.cc,v 1.256 1998/05/27 20:31:37 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -138,6 +138,7 @@ static OBJH statDigestBlob; static OBJH statAvg5min; static OBJH statAvg60min; static OBJH statUtilization; +static OBJH statCountersHistograms; #ifdef XMALLOC_STATISTICS static void info_get_mallstat(int, int, StoreEntry *); @@ -815,6 +816,9 @@ statInit(void) "Display cache metrics graphically", statGraphDump, 0); #endif + cachemgrRegister("histograms", + "Full Histogram Counts", + statCountersHistograms, 0); } static void @@ -879,6 +883,7 @@ statCountersInitSpecial(StatCounters * C) * Cache Digest Stuff */ statHistEnumInit(&C->cd.on_xition_count, CacheDigestHashFuncCount); + statHistEnumInit(&C->comm_incoming, 20); } /* add special cases here as they arrive */ @@ -894,6 +899,7 @@ statCountersClean(StatCounters * C) statHistClean(&C->icp.reply_svc_time); statHistClean(&C->dns.svc_time); statHistClean(&C->cd.on_xition_count); + statHistClean(&C->comm_incoming); } /* add special cases here as they arrive */ @@ -915,11 +921,13 @@ statCountersCopy(StatCounters * dest, const StatCounters * orig) statHistCopy(&dest->icp.reply_svc_time, &orig->icp.reply_svc_time); statHistCopy(&dest->dns.svc_time, &orig->dns.svc_time); statHistCopy(&dest->cd.on_xition_count, &orig->cd.on_xition_count); + statHistCopy(&dest->comm_incoming, &orig->comm_incoming); } static void statCountersHistograms(StoreEntry * sentry) { + StatCounters *f = &Counter; #if TOO_MUCH_OUTPUT storeAppendPrintf(sentry, "client_http.all_svc_time histogram:\n"); statHistDump(&f->client_http.all_svc_time, sentry, NULL); @@ -936,6 +944,8 @@ statCountersHistograms(StoreEntry * sentry) storeAppendPrintf(sentry, "dns.svc_time histogram:\n"); statHistDump(&f->dns.svc_time, sentry, NULL); #endif + storeAppendPrintf(sentry, "comm_incoming histogram:\n"); + statHistDump(&f->comm_incoming, sentry, statHistIntDumper); } static void diff --git a/src/structs.h b/src/structs.h index 3060996a3a..ce72dbe018 100644 --- a/src/structs.h +++ b/src/structs.h @@ -355,6 +355,10 @@ struct _SquidConfig { struct { size_t limit; } MemPools; + struct { + int min; + int max; + } incoming_rate; }; struct _SquidConfig2 { @@ -1256,6 +1260,7 @@ struct _StatCounters { int select_loops; double cputime; struct timeval timestamp; + StatHist comm_incoming; }; struct _tlv { diff --git a/src/typedefs.h b/src/typedefs.h index 5481e0f6a8..b19116179f 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -156,7 +156,7 @@ typedef void SIGHDLR(int sig); typedef void STVLDCB(void *, int, int); typedef double (*hbase_f) (double); -typedef void (*StatHistBinDumper) (StoreEntry *, int idx, double val, double size, int count); +typedef void StatHistBinDumper(StoreEntry *, int idx, double val, double size, int count); /* append/vprintf's for Packer */ typedef void (*append_f) (void *, const char *buf, int size);