From: wessels <> Date: Tue, 16 Apr 1996 01:20:23 +0000 (+0000) Subject: Added support for weighted neighbors X-Git-Tag: SQUID_3_0_PRE1~6171 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe113054472bb674a46fb50ba6387a9f6d29dbc2;p=thirdparty%2Fsquid.git Added support for weighted neighbors --- diff --git a/ChangeLog b/ChangeLog index 1ee62c74d5..96f1d89595 100644 --- a/ChangeLog +++ b/ChangeLog @@ -70,3 +70,4 @@ - Fixed memory leaks. - Check specifically for tm_gmtoff and set HAVE_TM_GMTOFF - Fixed memory problem for colon but no port ("http://foo.com:/") + - Added support for weighted neighbors. diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 363946ac12..9f52512010 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,4 +1,4 @@ -/* $Id: cache_cf.cc,v 1.38 1996/04/12 04:34:15 wessels Exp $ */ +/* $Id: cache_cf.cc,v 1.39 1996/04/15 19:20:23 wessels Exp $ */ /* DEBUG: Section 3 cache_cf: Configuration file parsing */ @@ -414,6 +414,7 @@ static void parseCacheHostLine() int ascii_port = CACHE_HTTP_PORT; int udp_port = CACHE_ICP_PORT; int proxy_only = 0; + int weight = 1; /* Parse a cache_host line */ if (!(hostname = strtok(NULL, w_space))) @@ -423,11 +424,16 @@ static void parseCacheHostLine() GetInteger(ascii_port); GetInteger(udp_port); - if ((token = strtok(NULL, w_space))) { - if (!strcasecmp(token, "proxy-only")) + while ((token = strtok(NULL, w_space))) { + if (!strcasecmp(token, "proxy-only")) { proxy_only = 1; + } else if (!strcasecmp(token, "weight=")) { + weight = atoi(token+7); + } else { + self_destruct(); + } } - neighbors_cf_add(hostname, type, ascii_port, udp_port, proxy_only); + neighbors_cf_add(hostname, type, ascii_port, udp_port, proxy_only, weight); } static void parseHostDomainLine() diff --git a/src/neighbors.cc b/src/neighbors.cc index 83c3a2efcf..389f7c034a 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,4 +1,4 @@ -/* $Id: neighbors.cc,v 1.17 1996/04/15 18:06:31 wessels Exp $ */ +/* $Id: neighbors.cc,v 1.18 1996/04/15 19:20:25 wessels Exp $ */ /* TODO: * - change 'neighbor' to 'sibling' @@ -348,10 +348,13 @@ int neighborsUdpPing(proto) struct sockaddr_in to_addr; edge *e = NULL; int i; + MemObject *m = entry->mem_obj; - entry->mem_obj->e_pings_n_pings = 0; - entry->mem_obj->e_pings_n_acks = 0; - entry->mem_obj->e_pings_first_miss = NULL; + m->e_pings_n_pings = 0; + m->e_pings_n_acks = 0; + m->e_pings_first_miss = NULL; + m->w_rtt = 0; + m->start_ping = current_time; if (friends->edges_head == (edge *) NULL) return 0; @@ -399,7 +402,7 @@ int neighborsUdpPing(proto) if (e->ack_deficit < HIER_MAX_DEFICIT) { /* consider it's alive. count it */ e->neighbor_up = 1; - entry->mem_obj->e_pings_n_pings++; + m->e_pings_n_pings++; } else { /* consider it's dead. send a ping but don't count it. */ e->neighbor_up = 0; @@ -443,7 +446,7 @@ int neighborsUdpPing(proto) debug(15, 6, "neighborsUdpPing: Source Ping is disabled.\n"); } } - return (entry->mem_obj->e_pings_n_pings); + return (m->e_pings_n_pings); } @@ -461,6 +464,8 @@ void neighborsUdpAck(fd, url, header, from, entry) StoreEntry *entry; { edge *e = NULL; + MemObject *m = entry->mem_obj; + int w_rtt; debug(15, 6, "neighborsUdpAck: url=%s (%d chars), header=0x%x, from=0x%x, ent=0x%x\n", url, strlen(url), header, from, entry); @@ -535,7 +540,7 @@ void neighborsUdpAck(fd, url, header, from, entry) /* If an edge is not found, count it as a MISS message. */ if (!e) { /* count it as a MISS message */ - entry->mem_obj->e_pings_n_acks++; + m->e_pings_n_acks++; return; } /* GOT a HIT here */ @@ -552,7 +557,7 @@ void neighborsUdpAck(fd, url, header, from, entry) return; } else if ((header->opcode == ICP_OP_MISS) || (header->opcode == ICP_OP_DECHO)) { /* everytime we get here, count it as a miss */ - entry->mem_obj->e_pings_n_acks++; + m->e_pings_n_acks++; if (e) e->misses++; @@ -562,12 +567,13 @@ void neighborsUdpAck(fd, url, header, from, entry) if (e) { debug(15, 6, "Got DECHO from non-cached cache:%s\n", inet_ntoa(e->in_addr.sin_addr)); - debug(15, 6, "Good."); if (e->type == EDGE_PARENT) { - if (entry->mem_obj->e_pings_first_miss == NULL) { - debug(15, 6, "OK. We got dumb-cached parent as the first miss here.\n"); - entry->mem_obj->e_pings_first_miss = e; + w_rtt = tvSubMsec(m->start_ping, current_time) / e->weight; + if (m->w_rtt == 0 || w_rtt < m->w_rtt) { + debug(15, 6, "Dumb-cache has minimum weighted RTT = %d\n", w_rtt); + m->e_pings_first_miss = e; + m->w_rtt = w_rtt; } } else { debug(15, 6, "Dumb Cached as a neighbor does not make sense.\n"); @@ -580,15 +586,16 @@ void neighborsUdpAck(fd, url, header, from, entry) debug(15, 6, "Count it anyway.\n"); } - } else { + } else if (e && e->type == EDGE_PARENT) { /* ICP_OP_MISS from a cache */ - if ((entry->mem_obj->e_pings_first_miss == NULL) && e && e->type == EDGE_PARENT) { - entry->mem_obj->e_pings_first_miss = e; - + w_rtt = tvSubMsec(m->start_ping, current_time) / e->weight; + if (m->w_rtt == 0 || w_rtt < m->w_rtt) { + m->e_pings_first_miss = e; + m->w_rtt = w_rtt; } } - if (entry->mem_obj->e_pings_n_acks == entry->mem_obj->e_pings_n_pings) { + if (m->e_pings_n_acks == m->e_pings_n_pings) { BIT_SET(entry->flag, ENTRY_DISPATCHED); entry->ping_status = DONE; debug(15, 6, "Receive MISSes from all neighbors and parents\n"); @@ -603,12 +610,13 @@ void neighborsUdpAck(fd, url, header, from, entry) } } -void neighbors_cf_add(host, type, ascii_port, udp_port, proxy_only) +void neighbors_cf_add(host, type, ascii_port, udp_port, proxy_only, weight) char *host; char *type; int ascii_port; int udp_port; int proxy_only; + int weight; { struct neighbor_cf *t, *u; @@ -618,6 +626,7 @@ void neighbors_cf_add(host, type, ascii_port, udp_port, proxy_only) t->ascii_port = ascii_port; t->udp_port = udp_port; t->proxy_only = proxy_only; + t->weight = weight; t->next = (struct neighbor_cf *) NULL; if (Neighbor_cf == (struct neighbor_cf *) NULL) { @@ -687,6 +696,7 @@ void neighbors_init() e->ascii_port = t->ascii_port; e->udp_port = t->udp_port; e->proxy_only = t->proxy_only; + e->weight = t->weight; e->host = t->host; e->domains = t->domains; e->neighbor_up = 1; diff --git a/src/tools.cc b/src/tools.cc index ee689c91c2..8d1a261afa 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,5 +1,5 @@ -/* $Id: tools.cc,v 1.31 1996/04/15 18:00:27 wessels Exp $ */ +/* $Id: tools.cc,v 1.32 1996/04/15 19:20:27 wessels Exp $ */ /* * DEBUG: Section 21 tools @@ -418,3 +418,11 @@ void reconfigure(sig) signal(sig, reconfigure); #endif } + +int tvSubMsec (t1, t2) + struct timeval t1; + struct timeval t2; +{ + return (t2.tv_sec - t1.tv_sec) * 1000 + + (t2.tv_usec - t1.tv_usec) / 1000; +}