On 07/31/2006 09:53 PM, Jim Jagielski wrote:
> Ruediger Pluem wrote:
> 
>>
>>Shouldn't that be "while (cur_lbset <= max_lbset && !mycandidate);"
>>(same question also for the other algorithm)?
>>I guess otherwise we would not check for the workers with the lbset max_lbset.
>>
> 
> 
> No, since we do the test at the end, after we've incremented.
> If the current set is 3 and the max is 3, we want to stop.

Maybe I am confused, but we have not run the loop with current set 3 as we have 
just incremented
at at the end.

So I try an example (maybe I prove myself wrong and make a fool out of me, but 
that would help also :-)

Let's assume the maximum lbset is 1

1. We start the outer while loop with cur_lbset and max_lbset 0
2. In the inner while loop
   1. we iterate over all workers of the balancer, but consider only those
      who are not standby and who have an lbset of 0
   2. we iterate over all workers of the balancer, but consider only those
      who are standby and who have an lbset of 0
3. Now we leave the inner while loop and lets assume that we found no candidate
4. Now we increase cur_lbset to 1
5. Now we have to leave the outer while loop, because cur_lbset < max_lbset is
   not true because cur_lbset = max_lbset

So we did not check for the workers with lbset 1.

BTW: Don't we need to reset checked_standby and checking_standby to zero in
     the outer while loop?



+    do {
+        while (!mycandidate && !checked_standby) {
+            worker = (proxy_worker *)balancer->workers->elts;
+            for (i = 0; i < balancer->workers->nelts; i++, worker++) {
+                if (!checking_standby) {    /* first time through */
+                    if (worker->s->lbset > max_lbset)
+                        max_lbset = worker->s->lbset;
+                }
+                if (worker->s->lbset > cur_lbset)
+                    continue;
+                if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : 
PROXY_WORKER_IS_STANDBY(worker)) )
+                    continue;
+                /* If the worker is in error state run
+                 * retry on that worker. It will be marked as
+                 * operational if the retry timeout is elapsed.
+                 * The worker might still be unusable, but we try
+                 * anyway.
+                 */
+                if (!PROXY_WORKER_IS_USABLE(worker))
+                    ap_proxy_retry_worker("BALANCER", worker, r->server);
+                /* Take into calculation only the workers that are
+                 * not in error state or not disabled.
+                 */
+                if (PROXY_WORKER_IS_USABLE(worker)) {
+                    mytraffic = (worker->s->transferred/worker->s->lbfactor) +
+                                (worker->s->read/worker->s->lbfactor);
+                    if (!mycandidate || mytraffic < curmin) {
+                        mycandidate = worker;
+                        curmin = mytraffic;
+                    }
                 }
             }
+            checked_standby = checking_standby++;
         }
-        checked_standby = checking_standby++;
-    }
+        cur_lbset++;
+    } while (cur_lbset < max_lbset && !mycandidate);

Regards

Rüdiger

Reply via email to