CARP fix for beta23

From: Eric Stern <estern@dont-contact.us>
Date: Tue, 4 Aug 1998 16:22:00 -0400 (EDT)

CARP support got broken during its inclusion into beta23 somehow.
(Duane? :) )

So, here's a fix. It also fixes a bug I found in the load_factor code
(this only showed up if you were using differing load factors).
Everything seems to be working to spec now.

Patch is attached at bottom.
/-----------------------------------------------------------------------/
/ Eric Stern - PacketStorm Technologies - (519) 837-0824 /
/ http://www.packetstorm.on.ca /
/ WebSpeed - a transparent web caching server - available now! /
/-----------------------------------------------------------------------/

--- squid-1.2.beta23/src/carp.c Wed Jul 22 16:37:04 1998
+++ squid-1.2.beta23-carp/src/carp.c Tue Aug 4 15:39:14 1998
@@ -42,37 +42,40 @@
     /* calculate load factors */
     int K = 0;
     float a = 0.0;
- float X;
- float Xn;
- float n;
+ float Xn,P_last,X_last;
     int k;
     peer *p;
     for (p = Config.peers; p; p = p->next) {
         a += p->carp.load_factor;
         K++;
     }
- if (a == 0.0)
- /* CARP load factors not configured */
- return;
+ if (a == 0.0) { // no load-factors configured
+ for (p = Config.peers;p;p = p->next)
+ p->carp.load_multiplier = 1; // so set them all to even load
+ return;
+ }
     /*
      * sum of carp-load-factor's for all cache_peer's in squid.conf
      * must equal 1.0
      */
     assert(a == 1.0);
     k = 1;
- n = 0;
- Xn = 0;
- for (p = Config.peers; p; p = p->next) {
- X = pow(K * p->carp.load_factor, 1 / K);
- if (Xn == 0)
- Xn = X;
- else
- Xn *= X;
- p->carp.load_multiplier = ((K - k + 1) * (p->carp.load_factor - n)) / Xn
- ;
+ P_last = 0;
+ p = Config.peers;
+ p->carp.load_multiplier = pow (K*p->carp.load_factor, 1/K);
+ Xn = p->carp.load_multiplier;
+ P_last = p->carp.load_factor;
+ X_last = p->carp.load_multiplier;
+ if (p->next)
+ for (p=p->next; p; p = p->next) {
+ p->carp.load_multiplier = ((K-k+1)*(p->carp.load_factor-P_last))/Xn;
+ p->carp.load_multiplier += pow(X_last, K-k+1);
+ p->carp.load_multiplier = pow(p->carp.load_multiplier,1/(K-k+1));
+ Xn *= p->carp.load_multiplier;
+ X_last = p->carp.load_multiplier;
         k++;
- n = p->carp.load_factor;
- }
+ P_last = p->carp.load_factor;
+ }
 }
 
 peer *
@@ -85,15 +88,14 @@
     unsigned long combined_hash;
     unsigned long high_score = 0;
     const char *url = urlCanonical(request);
+
     /* calculate url hash */
     debug(44, 2) ("carpSelectParent: CARP Calculating hash for %s\n", url);
     for (c = url; *c != 0; c++)
         url_hash += (url_hash << 19) + *c;
     /* select peer */
     for (tp = Config.peers; tp; tp = tp->next) {
- if (p->carp.load_factor == 0.0)
- continue;
- assert(p->type == PEER_PARENT);
+ assert(tp->type == PEER_PARENT);
         combined_hash = (url_hash ^ tp->carp.hash);
         combined_hash += combined_hash * 0x62531965;
         combined_hash = combined_hash << 21;
Received on Tue Jul 29 2003 - 13:15:51 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:11:50 MST