This patch is generated from the satellite-20020623 branch of HEAD-20020623 in squid Tue Sep 9 11:57:35 2003 GMT See http://devel.squid-cache.org/ Index: squid/src/cache_cf.c diff -u squid/src/cache_cf.c:1.44 squid/src/cache_cf.c:1.1.1.4.2.1.6.7 --- squid/src/cache_cf.c:1.44 Sat Apr 13 16:09:15 2002 +++ squid/src/cache_cf.c Sun Jun 16 13:31:59 2002 @@ -1435,6 +1435,7 @@ p->http_port = CACHE_HTTP_PORT; p->icp.port = CACHE_ICP_PORT; p->weight = 1; + p->basetime = 0; p->stats.logged_state = PEER_ALIVE; if ((token = strtok(NULL, w_space)) == NULL) self_destruct(); @@ -1451,12 +1452,16 @@ p->options.proxy_only = 1; } else if (!strcasecmp(token, "no-query")) { p->options.no_query = 1; + } else if (!strcasecmp(token, "background-ping")) { + p->options.background_ping = 1; } else if (!strcasecmp(token, "no-digest")) { p->options.no_digest = 1; } else if (!strcasecmp(token, "multicast-responder")) { p->options.mcast_responder = 1; } else if (!strncasecmp(token, "weight=", 7)) { p->weight = atoi(token + 7); + } else if (!strncasecmp(token, "basetime=", 9)) { + p->basetime = atoi(token + 9); } else if (!strcasecmp(token, "closest-only")) { p->options.closest_only = 1; } else if (!strncasecmp(token, "ttl=", 4)) { @@ -1469,6 +1474,8 @@ p->options.default_parent = 1; } else if (!strcasecmp(token, "round-robin")) { p->options.roundrobin = 1; + } else if (!strcasecmp(token, "weighted-round-robin")) { + p->options.weighted_roundrobin = 1; #if USE_HTCP } else if (!strcasecmp(token, "htcp")) { p->options.htcp = 1; Index: squid/src/cf.data.pre diff -u squid/src/cf.data.pre:1.66 squid/src/cf.data.pre:1.1.1.4.2.1.6.14 --- squid/src/cf.data.pre:1.66 Sun Jun 23 06:38:03 2002 +++ squid/src/cf.data.pre Sun Jun 23 07:37:10 2002 @@ -262,10 +262,13 @@ options: proxy-only weight=n + basetime=n ttl=n no-query + background-ping default round-robin + weighted-round-robin multicast-responder closest-only no-digest @@ -284,6 +287,12 @@ The weight must be an integer. The default weight is 1, larger weights are favored more. + use 'basetime=n' to specify a base amount to + be subtracted from round trip times of parents. + It is subtraced before devision by weight in calculating + which parent to fectch from. If the rtt is less than the + base time then the rtt is set to a minimal value. + use 'ttl=n' to specify a IP multicast TTL to use when sending an ICP queries to this address. Only useful when sending to a multicast group. @@ -294,6 +303,11 @@ use 'no-query' to NOT send ICP queries to this neighbor. + use 'background-ping' to only send ICP queries to this + neighbor infrequently. This is used to keep the neighbor + round trip time updated and is usually used in + conjunction with weighted-round-robin. + use 'default' if this is a parent cache which can be used as a "last-resort." You should probably only use 'default' in situations where you cannot @@ -303,6 +317,12 @@ should be used in a round-robin fashion in the absence of any ICP queries. + use 'weighted-round-robin' to define a set of parents + which should be used in a round-robin fashion with the + frequency of each parent being based on the round trip + time. Closer parents are used more often. + Usually used for background-ping parents. + 'multicast-responder' indicates that the named peer is a member of a multicast group. ICP queries will not be sent directly to the peer, but ICP replies @@ -535,6 +555,16 @@ acl QUERY urlpath_regex cgi-bin \? no_cache deny QUERY NOCOMMENT_END +DOC_END + +NAME: background_ping_rate +COMMENT: time-units +TYPE: time_t +DEFAULT: 10 seconds +LOC: Config.backgroundPingRate +DOC_START + Controls how often the ICP pings are sent to siblings that + have background-ping set. DOC_END Index: squid/src/defines.h diff -u squid/src/defines.h:1.21 squid/src/defines.h:1.1.1.4.2.1.6.7 --- squid/src/defines.h:1.21 Fri Jun 21 06:00:26 2002 +++ squid/src/defines.h Sun Jun 23 07:34:03 2002 @@ -166,6 +166,7 @@ #define PEER_MAX_ADDRESSES 10 #define RTT_AV_FACTOR 50 +#define RTT_BACKGROUND_AV_FACTOR 25 /* Background pings need a smaller factor since they are sent less frequently */ #define PEER_DEAD 0 #define PEER_ALIVE 1 Index: squid/src/neighbors.c diff -u squid/src/neighbors.c:1.16 squid/src/neighbors.c:1.1.1.4.2.1.6.8 --- squid/src/neighbors.c:1.16 Sat Apr 13 16:09:17 2002 +++ squid/src/neighbors.c Sun Jun 16 13:32:04 2002 @@ -171,6 +171,8 @@ return 0; if (p->options.no_query) return 0; + if (p->options.background_ping && (squid_curtime - p->stats.last_query < Config.backgroundPingRate)) + return 0; if (p->options.mcast_responder) return 0; if (p->n_addresses == 0) @@ -185,8 +187,9 @@ /* Ping dead peers every timeout interval */ if (squid_curtime - p->stats.last_query > Config.Timeout.deadPeer) return 1; - if (!neighborUp(p)) - return 0; + if (p->icp.port == echo_port) + if (!neighborUp(p)) + return 0; return 1; } @@ -275,6 +278,42 @@ return q; } +peer * +getWeightedRoundRobinParent(request_t * request) +{ + peer *p; + peer *q = NULL; + int weighted_rtt; + for (p = Config.peers; p; p = p->next) { + if (!p->options.weighted_roundrobin) + continue; + if (neighborType(p, request) != PEER_PARENT) + continue; + if (!peerHTTPOkay(p, request)) + continue; + if (q && q->rr_count < p->rr_count) + continue; + q = p; + } + if (q && q->rr_count>1000000) + for (p = Config.peers; p; p = p->next) { + if (!p->options.weighted_roundrobin) + continue; + if (neighborType(p, request) != PEER_PARENT) + continue; + p->rr_count=0; + } + if (q) { + weighted_rtt=(q->stats.rtt- q->basetime)/q->weight; + + if (weighted_rtt<1) weighted_rtt=1; + q->rr_count+= weighted_rtt; + debug(15, 3) ("getWeightedRoundRobinParent: weighted_rtt %d\n", (int)weighted_rtt); + } + debug(15, 3) ("getWeightedRoundRobinParent: returning %s\n", q ? q->host : "NULL"); + return q; +} + /* This gets called every 5 minutes to clear the round-robin counter. */ void peerClearRR(void *data) @@ -691,7 +730,7 @@ static void neighborUpdateRtt(peer * p, MemObject * mem) { - int rtt; + int rtt, rtt_av_factor; if (!mem) return; if (!mem->start_ping.tv_sec) @@ -699,8 +738,10 @@ rtt = tvSubMsec(mem->start_ping, current_time); if (rtt < 1 || rtt > 10000) return; + rtt_av_factor = RTT_AV_FACTOR; + if (p->options.weighted_roundrobin) rtt_av_factor = RTT_BACKGROUND_AV_FACTOR; p->stats.rtt = intAverage(p->stats.rtt, rtt, - p->stats.pings_acked, RTT_AV_FACTOR); + p->stats.pings_acked, rtt_av_factor); } #if USE_HTCP @@ -1184,6 +1225,8 @@ static void peerCountHandleIcpReply(peer * p, peer_t type, protocol_t proto, void *hdrnotused, void *data) { + int rtt_av_factor; + ps_state *psstate = data; StoreEntry *fake = psstate->entry; MemObject *mem = fake->mem_obj; @@ -1192,7 +1235,9 @@ assert(fake); assert(mem); psstate->ping.n_recv++; - p->stats.rtt = intAverage(p->stats.rtt, rtt, psstate->ping.n_recv, RTT_AV_FACTOR); + rtt_av_factor = RTT_AV_FACTOR; + if (p->options.weighted_roundrobin) rtt_av_factor = RTT_BACKGROUND_AV_FACTOR; + p->stats.rtt = intAverage(p->stats.rtt, rtt, psstate->ping.n_recv, rtt_av_factor); } static void @@ -1214,12 +1259,16 @@ storeAppendPrintf(sentry, " proxy-only"); if (p->options.no_query) storeAppendPrintf(sentry, " no-query"); + if (p->options.background_ping) + storeAppendPrintf(sentry, " background-ping"); if (p->options.no_digest) storeAppendPrintf(sentry, " no-digest"); if (p->options.default_parent) storeAppendPrintf(sentry, " default"); if (p->options.roundrobin) storeAppendPrintf(sentry, " round-robin"); + if (p->options.weighted_roundrobin) + storeAppendPrintf(sentry, " weighted-round-robin"); if (p->options.mcast_responder) storeAppendPrintf(sentry, " multicast-responder"); if (p->options.closest_only) Index: squid/src/peer_select.c diff -u squid/src/peer_select.c:1.14 squid/src/peer_select.c:1.1.1.4.2.1.6.6 --- squid/src/peer_select.c:1.14 Sat Apr 13 16:09:17 2002 +++ squid/src/peer_select.c Sun Jun 16 13:32:05 2002 @@ -445,6 +445,8 @@ #endif } else if ((p = getRoundRobinParent(request))) { code = ROUNDROBIN_PARENT; + } else if ((p = getWeightedRoundRobinParent(request))) { + code = ROUNDROBIN_PARENT; } else if ((p = getFirstUpParent(request))) { code = FIRSTUP_PARENT; } else if ((p = getAnyParent(request))) { @@ -534,7 +536,9 @@ /* set FIRST_MISS if there is no CLOSEST parent */ if (ps->closest_parent_miss.sin_addr.s_addr != any_addr.s_addr) return; - rtt = tvSubMsec(ps->ping.start, current_time) / p->weight; + rtt = (tvSubMsec(ps->ping.start, current_time) - p->basetime) / p->weight; + if (rtt < 1) + rtt = 1; if (ps->first_parent_miss.sin_addr.s_addr == any_addr.s_addr || rtt < ps->ping.w_rtt) { ps->first_parent_miss = p->in_addr; @@ -622,7 +626,9 @@ /* set FIRST_MISS if there is no CLOSEST parent */ if (ps->closest_parent_miss.sin_addr.s_addr != any_addr.s_addr) return; - rtt = tvSubMsec(ps->ping.start, current_time) / p->weight; + rtt = (tvSubMsec(ps->ping.start, current_time) - p->basetime) / p->weight; + if (rtt < 1) + rtt = 1; if (ps->first_parent_miss.sin_addr.s_addr == any_addr.s_addr || rtt < ps->ping.w_rtt) { ps->first_parent_miss = p->in_addr; Index: squid/src/protos.h diff -u squid/src/protos.h:1.57 squid/src/protos.h:1.1.1.4.2.1.6.11 --- squid/src/protos.h:1.57 Sun Jun 23 06:38:03 2002 +++ squid/src/protos.h Sun Jun 23 07:34:03 2002 @@ -664,6 +664,7 @@ extern peer *peerFindByNameAndPort(const char *, unsigned short); extern peer *getDefaultParent(request_t * request); extern peer *getRoundRobinParent(request_t * request); +extern peer *getWeightedRoundRobinParent(request_t * request); EVH peerClearRR; extern peer *getAnyParent(request_t * request); extern lookup_t peerDigestLookup(peer * p, request_t * request); Index: squid/src/structs.h diff -u squid/src/structs.h:1.60 squid/src/structs.h:1.1.1.4.2.1.6.13 --- squid/src/structs.h:1.60 Sun Jun 23 06:38:03 2002 +++ squid/src/structs.h Sun Jun 23 07:34:03 2002 @@ -393,6 +393,7 @@ time_t negativeDnsTtl; time_t positiveDnsTtl; time_t shutdownLifetime; + time_t backgroundPingRate; struct { time_t read; time_t lifetime; @@ -1264,9 +1265,11 @@ struct { unsigned int proxy_only:1; unsigned int no_query:1; + unsigned int background_ping:1; unsigned int no_digest:1; unsigned int default_parent:1; unsigned int roundrobin:1; + unsigned int weighted_roundrobin:1; unsigned int mcast_responder:1; unsigned int closest_only:1; #if USE_HTCP @@ -1282,6 +1285,7 @@ #endif } options; int weight; + int basetime; struct { double avg_n_members; int n_times_counted; squid-satellite-20020623-HEAD-20020623.new squid-satellite-20020623-HEAD-20020623 differ: char 86, line 2