httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Jagielski <...@jaguNET.com>
Subject Simplified lbfactor setup for proxy_balancer
Date Wed, 15 Dec 2004 18:01:20 GMT
IMO the current setting for how proxy_balancer handles
lbfactor isn't intuitive... For example, if I
setup 2 members, one with a lbfactor of 1 and another
with 2 (eg: a lbfactor=1 ; b lbfactor=2) then one
would expect 'b' handle twice the amount of traffic
than 'a'. Now if set to 33 and 66, then it works
as expected, and yes, it is kind of assumed
that we're talking percentages. But that's
painful, IMO.

Instead, I want to be able to have things
like

    a lbfactor=1
    b lbfactor=5
    c lbfactor=2
    d lbfactor=1

and have the balancer do the right thing
so that, assuming 100 hits, a gets ~ 11,
d gets ~ 11, c gets ~ 22 and b gets ~55.

That way the admin doesn't need to worry
about percentages or anything; everything is
normalized, which makes things *much* cleaner.

See http://www.apache.org/~jim/pbtest.pl for a
test script which implements the algo.

As such, I propose the following patch:

Index: modules/proxy/proxy_balancer.c
===================================================================
--- modules/proxy/proxy_balancer.c      (revision 111867)
+++ modules/proxy/proxy_balancer.c      (working copy)
@@ -27,7 +27,6 @@
                                   proxy_balancer *balancer)
  {
      int i;
-    int median, ffactor = 0;
      proxy_worker *workers;

      workers = (proxy_worker *)balancer->workers->elts;
@@ -42,39 +41,8 @@
      /* Recalculate lbfactors */
      for (i = 0; i < balancer->workers->nelts; i++) {
          /* Set to the original configuration */
-        workers[i].s->lbfactor = workers[i].lbfactor;
-        ffactor += workers[i].s->lbfactor;
+        workers[i].s->lbstatus = workers[i].s->lbfactor = 
workers[i].lbfactor;
      }
-    if (ffactor < 100) {
-        int z = 0;
-        for (i = 0; i < balancer->workers->nelts; i++) {
-            if (workers[i].s->lbfactor == 0)
-                ++z;
-        }
-        if (z) {
-            median = (100 - ffactor) / z;
-            for (i = 0; i < balancer->workers->nelts; i++) {
-                if (workers[i].s->lbfactor == 0)
-                    workers[i].s->lbfactor = median;
-            }
-        }
-        else {
-            median = (100 - ffactor) / balancer->workers->nelts;
-            for (i = 0; i < balancer->workers->nelts; i++)
-                workers[i].s->lbfactor += median;
-        }
-    }
-    else if (ffactor > 100) {
-        median = (ffactor - 100) / balancer->workers->nelts;
-        for (i = 0; i < balancer->workers->nelts; i++) {
-            if (workers[i].s->lbfactor > median)
-                workers[i].s->lbfactor -= median;
-        }
-    }
-    for (i = 0; i < balancer->workers->nelts; i++) {
-        /* Update the status entires */
-        workers[i].s->lbstatus = workers[i].s->lbfactor;
-    }
      return 0;
  }

@@ -461,51 +429,23 @@
      return OK;
  }

-static void recalc_factors(proxy_balancer *balancer,
-                           proxy_worker *fixed)
+static void recalc_factors(proxy_balancer *balancer)
  {
      int i;
-    int median, ffactor = 0;
      proxy_worker *workers;


      /* Recalculate lbfactors */
      workers = (proxy_worker *)balancer->workers->elts;
      /* Special case if there is only one worker it's
-     * load factor will always be 100
+     * load factor will always be 1
       */
      if (balancer->workers->nelts == 1) {
-        workers->s->lbstatus = workers->s->lbfactor = 100;
+        workers->s->lbstatus = workers->s->lbfactor = 1;
          return;
      }
      for (i = 0; i < balancer->workers->nelts; i++) {
-        if (workers[i].s->lbfactor > 100)
-            workers[i].s->lbfactor = 100;
-        ffactor += workers[i].s->lbfactor;
-    }
-    if (ffactor < 100) {
-        median = (100 - ffactor) / (balancer->workers->nelts - 1);
-        for (i = 0; i < balancer->workers->nelts; i++) {
-            if (&(workers[i]) != fixed)
-                workers[i].s->lbfactor += median;
-        }
-    }
-    else if (fixed->s->lbfactor < 100) {
-        median = (ffactor - 100) / (balancer->workers->nelts - 1);
-        for (i = 0; i < balancer->workers->nelts; i++) {
-            if (workers[i].s->lbfactor > median &&
-                &(workers[i]) != fixed)
-                workers[i].s->lbfactor -= median;
-        }
-    }
-    else {
-        median = (ffactor - 100) / balancer->workers->nelts;
-        for (i = 0; i < balancer->workers->nelts; i++) {
-            workers[i].s->lbfactor -= median;
-        }
-    }
-    for (i = 0; i < balancer->workers->nelts; i++) {
-        /* Update the status entires */
+        /* Update the status entries */
          workers[i].s->lbstatus = workers[i].s->lbfactor;
      }
  }
@@ -595,10 +535,10 @@
          const char *val;
          if ((val = apr_table_get(params, "lf"))) {
              int ival = atoi(val);
-            if (ival > 1) {
+            if (ival >= 1 && ival <= 100) {
                  wsel->s->lbfactor = ival;
                  if (bsel)
-                    recalc_factors(bsel, wsel);
+                    recalc_factors(bsel);
              }
          }
          if ((val = apr_table_get(params, "wr"))) {
Index: modules/proxy/mod_proxy.c
===================================================================
--- modules/proxy/mod_proxy.c   (revision 111867)
+++ modules/proxy/mod_proxy.c   (working copy)
@@ -92,7 +92,7 @@
      int ival;
      if (!strcasecmp(key, "loadfactor")) {
          /* Worker load factor. Used with BalancerMamber
-         * It is a number between 1 and 100 in percents.
+         * It is a number between 1 and 100.
           */
          worker->lbfactor = atoi(val);
          if (worker->lbfactor < 1 || worker->lbfactor > 100)


Mime
View raw message