From: wessels <> Date: Mon, 5 Jan 1998 07:45:43 +0000 (+0000) Subject: - Changed algorithm for determining alive/dead state of peers. X-Git-Tag: SQUID_3_0_PRE1~4265 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc83597742c1d42c38c1bfa5ee6ae2ba00c3a661;p=thirdparty%2Fsquid.git - Changed algorithm for determining alive/dead state of peers. Instead of using a fixed number of unacknowledged ICP replies, it is now based on timeouts. If there are no ICP replies received from a peer within 'dead_peer_timeout' seconds, then we call it dead. - Added calls to getCurrentTime() in comm_{select,poll}_incoming(). - Fixed shutdown bug when the incoming and outgoing ICP socket is the same file descriptor. --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 077c85a40b..9b80ee6330 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.240 1998/01/02 19:55:28 wessels Exp $ + * $Id: cache_cf.cc,v 1.241 1998/01/05 00:45:43 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -595,6 +595,7 @@ parse_peer(peer ** head) p->http_port = CACHE_HTTP_PORT; p->icp_port = CACHE_ICP_PORT; p->weight = 1; + p->stats.logged_state = PEER_ALIVE; if ((token = strtok(NULL, w_space)) == NULL) self_destruct(); p->host = xstrdup(token); diff --git a/src/cf.data.pre b/src/cf.data.pre index 7f7d2120bc..c96c3091a4 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -328,6 +328,22 @@ DOC_START neighbor_timeout 2 seconds DOC_END +NAME: dead_peer_timeout +COMMENT: (seconds) +DEFAULT: 10 seconds +TYPE: time_t +LOC: Config.Timeout.deadPeer +DOC_START + This controls how long Squid waits to declare a peer cache + as "dead." If there are no ICP replies received in this + amount of time, Squid will declare the peer dead and not + expect to receive any further ICP replies. However, it + continues to send ICP queries, and will mark the peer as + alive upon receipt of the first subsequent ICP reply. + +dead_peer_timeout 10 seconds +DOC_END + NAME: hierarchy_stoplist TYPE: wordlist diff --git a/src/comm.cc b/src/comm.cc index dfd7f01d8b..9e32cf14bf 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.218 1998/01/02 16:30:14 wessels Exp $ + * $Id: comm.cc,v 1.219 1998/01/05 00:45:45 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -722,6 +722,9 @@ comm_poll_incoming(void) } if (!nfds) return; +#if !ALARM_UPDATES_TIME + getCurrentTime(); +#endif polledinc = poll(pfds, nfds, 0); if (polledinc < 1) { polledinc = 0; @@ -789,6 +792,9 @@ comm_select_incoming(void) } if (maxfd++ == 0) return; +#if !ALARM_UPDATES_TIME + getCurrentTime(); +#endif polledinc = select(maxfd, &read_mask, &write_mask, NULL, &zero_tv); if (polledinc < 1) { polledinc = 0; diff --git a/src/defines.h b/src/defines.h index 2cb866fcab..7ad048c641 100644 --- a/src/defines.h +++ b/src/defines.h @@ -161,6 +161,9 @@ #define PEER_COUNTING 2 #define ICP_AUTH_SIZE (2) /* size of authenticator field */ +#define PEER_DEAD 0 +#define PEER_ALIVE 1 + #define ICON_MENU "anthony-dir.gif" #define ICON_DIRUP "anthony-dirup.gif" #define ICON_LINK "anthony-link.gif" diff --git a/src/main.cc b/src/main.cc index 370e3abd38..12378d6130 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.200 1998/01/02 06:56:52 wessels Exp $ + * $Id: main.cc,v 1.201 1998/01/05 00:45:46 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -331,8 +331,10 @@ serverConnectionsOpen(void) void serverConnectionsClose(void) { - /* NOTE, this function will be called repeatedly while shutdown - * is pending */ + /* + * NOTE, this function will be called repeatedly while shutdown + * is pending + */ int i; for (i = 0; i < NHttpSockets; i++) { if (HttpSockets[i] >= 0) { @@ -343,28 +345,35 @@ serverConnectionsClose(void) } NHttpSockets = 0; if (theInIcpConnection > -1) { - /* NOTE, don't close outgoing ICP connection, we need to write to - * it during shutdown */ + /* + * NOTE, don't close outgoing ICP connection, we need to write + * to it during shutdown. + */ debug(1, 1) ("FD %d Closing ICP connection\n", theInIcpConnection); - if (theInIcpConnection != theOutIcpConnection) + if (theInIcpConnection != theOutIcpConnection) { comm_close(theInIcpConnection); - else + assert(theOutIcpConnection > -1); + /* + * Normally we only write to the outgoing ICP socket, but + * we also have a read handler there to catch messages sent + * to that specific interface. During shutdown, we must + * disable reading on the outgoing socket. + */ + commSetSelect(theOutIcpConnection, + COMM_SELECT_READ, + NULL, + NULL, + 0); + } else { commSetSelect(theInIcpConnection, COMM_SELECT_READ, NULL, NULL, 0); + } theInIcpConnection = -1; } - /* - * Normally we only write to the outgoing ICP socket, but we - * also have a read handler there to catch messages sent to that - * specific interface. During shutdown, we must disable reading - * on the outgoing socket. - */ - if (theOutIcpConnection > -1) - commSetSelect(theOutIcpConnection, COMM_SELECT_READ, NULL, NULL, 0); if (icmp_sock > -1) icmpClose(); #ifdef SQUID_SNMP diff --git a/src/neighbors.cc b/src/neighbors.cc index 8a5c0df197..2f0aabaa06 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,5 +1,5 @@ /* - * $Id: neighbors.cc,v 1.170 1998/01/02 21:59:47 wessels Exp $ + * $Id: neighbors.cc,v 1.171 1998/01/05 00:45:47 wessels Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -462,12 +462,13 @@ neighborsUdpPing(request_t * request, } queries_sent++; - p->stats.ack_deficit++; p->stats.pings_sent++; - debug(15, 3) ("neighborsUdpPing: %s: ack_deficit = %d\n", - p->host, p->stats.ack_deficit); if (p->type == PEER_MULTICAST) { - p->stats.ack_deficit = 0; + /* + * set a bogus last_reply time so neighborUp() never + * says a multicast peer is dead. + */ + p->stats.last_reply = squid_curtime; (*exprep) += p->mcast.n_replies_expected; } else if (neighborUp(p)) { /* its alive, expect a reply from it */ @@ -475,12 +476,14 @@ neighborsUdpPing(request_t * request, } else { /* Neighbor is dead; ping it anyway, but don't expect a reply */ /* log it once at the threshold */ - if ((p->stats.ack_deficit == HIER_MAX_DEFICIT)) { + if (p->stats.logged_state == PEER_ALIVE) { debug(15, 0) ("Detected DEAD %s: %s/%d/%d\n", neighborTypeStr(p), p->host, p->http_port, p->icp_port); + p->stats.logged_state = PEER_DEAD; } } + p->stats.last_query = squid_curtime; } if ((first_ping = first_ping->next) == NULL) first_ping = Config.peers; @@ -523,13 +526,13 @@ neighborAlive(peer * p, const MemObject * mem, const icp_common_t * header) { int rtt; int n; - /* Neighbor is alive, reset the ack deficit */ - if (p->stats.ack_deficit >= HIER_MAX_DEFICIT) { + if (p->stats.logged_state == PEER_DEAD) { debug(15, 0) ("Detected REVIVED %s: %s/%d/%d\n", neighborTypeStr(p), p->host, p->http_port, p->icp_port); + p->stats.logged_state = PEER_ALIVE; } - p->stats.ack_deficit = 0; + p->stats.last_reply = squid_curtime; n = ++p->stats.pings_acked; if ((icp_opcode) header->opcode <= ICP_END) p->stats.counts[header->opcode]++; @@ -732,7 +735,9 @@ neighborUp(const peer * p) { if (!p->tcp_up) return 0; - if (p->stats.ack_deficit >= HIER_MAX_DEFICIT) + if (squid_curtime - p->stats.last_query > Config.Timeout.deadPeer) + return 1; + if (p->stats.last_query - p->stats.last_reply >= Config.Timeout.deadPeer) return 0; return 1; } diff --git a/src/stat.cc b/src/stat.cc index 072faa57e2..ee48f62590 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.179 1997/12/03 01:31:40 wessels Exp $ + * $Id: stat.cc,v 1.180 1998/01/05 00:45:48 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -406,7 +406,10 @@ dump_peers(StoreEntry * sentry, peer * peers) storeAppendPrintf(sentry, "{Status : %s}\n", neighborUp(e) ? "Up" : "Down"); storeAppendPrintf(sentry, "{AVG RTT : %d msec}\n", e->stats.rtt); - storeAppendPrintf(sentry, "{ACK DEFICIT: %8d}\n", e->stats.ack_deficit); + storeAppendPrintf(sentry, "{LAST QUERY : %8d seconds ago}\n", + (int) (squid_curtime - e->stats.last_query)); + storeAppendPrintf(sentry, "{LAST REPLY : %8d seconds ago}\n", + (int) (squid_curtime - e->stats.last_reply)); storeAppendPrintf(sentry, "{PINGS SENT : %8d}\n", e->stats.pings_sent); storeAppendPrintf(sentry, "{PINGS ACKED: %8d %3d%%}\n", e->stats.pings_acked, diff --git a/src/structs.h b/src/structs.h index 34a838ef1f..8c0d7f6fb8 100644 --- a/src/structs.h +++ b/src/structs.h @@ -172,6 +172,7 @@ struct _SquidConfig { time_t request; time_t pconn; time_t siteSelect; + time_t deadPeer; } Timeout; size_t maxRequestSize; struct { @@ -629,13 +630,15 @@ struct _peer { struct { int pings_sent; int pings_acked; - int ack_deficit; int fetches; int rtt; int counts[ICP_END]; int ignored_replies; int n_keepalives_sent; int n_keepalives_recv; + time_t last_query; + time_t last_reply; + int logged_state; /* so we can print dead/revived msgs */ } stats; u_short icp_port; u_short http_port;