Even if one server is getting hit multiple times in a row, I don't think it
will matter. I put in 10 servers in my qmqpservers file and some well
placed printf's in qmqpc and ran it 100,000 times several times through.
Each server was getting picked about 10% of the time +/- 1% or so. If we're
sending millions of messages, this +/- 1% isn't going to make a significant
difference.
I could just use the following code to shuffle the array instead of just
rotating it:
void Shuffle(void *array, int n, size_t size)
{
int f,g;
char *temp,*p;
temp=malloc(size);
p=array;
for(f=0;f<n;f++) {
g=random(f);
memcpy(temp,&p[g*size]);
memcpy(&p[g*size],&p[f*size]);
memcpy(&p[f*size],temp);
}
free(temp);
}
-----Original Message-----
From: Michael T. Babcock [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 02, 2000 8:58 AM
To: JuanE; [EMAIL PROTECTED]
Subject: Re: updated load balancing qmail-qmqpc.c mods
Again, its unnecessary and does not add anything to the 'system' of
distributing load across servers. Distributing in a true round-robin
fashion is sufficient if the servers are of equal quality (and/or drop
connections sooner if they are not). True round-robin distribution cannot
easily be accomplished (without shared memory or a temporary file) and so
picking a random starting point is the closest that can be achieved. Using
random servers each time though, especially from a near-true random number
source, could cause one server to be hit 3 or 4 (or, technically, an
infinite number of) times in a row. There is no need to go to the expense
of randomly computing each successive server (for example:)
#1 #2 #3 #4 #5
1 3 4 1 2
2 4 1 2 3
3 1 3 4
4 4 1
1 2
2
"1,3,4,1,2" were picked as my random numbers and the number of messages sent
out in a round varying ... each server was hit almost evenly:
1 xxxxxx
2 xxxxx
3 xxxx
4 xxxxx
(Disclaimer: My old stats teacher would kill me for this insufficiently long
example and lack of mathematical proof)
----- Original Message -----
From: "JuanE" <[EMAIL PROTECTED]>
> A small modification to what you have done can get rid of the problem of
> banging one server. Instead of just sampling a random starting point for
> the search, just get a random number between 1 and N (N being the number
of
> servers) and if that server is down just sample again until you find a
> server that's up. This way, you will redistribute the load randomly to all
> servers and not just the next one on the list.