# Re: updated load balancing qmail-qmqpc.c mods

```
I like the idea of statically listing them, but as you mentioned it is not
very scalable. The shuffling can be very expensive. I believe it would grow
with N^2. Instead of shuffling, just plain random sampling would be better
computationally. See me previous posting.

I think this is a "profile, don't speculate" scenario.

JES

Frank D. Cringle writes:

> "Austad, Jay" <[EMAIL PROTECTED]> writes:
> > From: JuanE [mailto:[EMAIL PROTECTED]]
> >> Assume you have 4 servers A, B, C, D, and that server C is down. When your
> >> random seed hits server A, B or D (with probability 1/4, respectively) the
> >> message will go through fine. When your random seeds hits server C (again
> >> with p=1/4), you will realize that it is down and proceed to D. So in
> >> effect you will hit servers A and B with probability 1/4 each, and server D
> >> with probability 1/2. This is not very good load balancing, because
>
> > You are correct.  However, since qmail-qmqpc does not continually run, it is
> > not possible to do a non-random round robin (as far as I know).
>
> Choose a permutation of the server list at random.  Then step through
> this list until you hit a good server or exhaust the list.
>
>  1. A B C D
>  2. A B D C
>  3. A C B D
>  4. A C D B
>  ....
> 24. D C B A
>
> If your random number is 4, you try A, then C, then D and finally B.
>
> If the number of servers is reasonably small, say up to 7, you could
> enumerate all permutations as a static array in the code and then use
> a random index into the array to determine the order.  Generating a
> random permutation algorithmically is not too easy.  You can either
> approximate by shuffling or make a direct choice using some bignum
> arithmetic described in "Permutation Generation Methods", Robert
> Sedgewick, Computing Surveys, Vol. 9, No. 2, June 1997.
>
> --
> Frank Cringle,      [EMAIL PROTECTED]
> voice: (+49 2304) 467101; fax: 943357
>

```