Jay Savage wrote:
>
> This sort of thing is unfortunately application specific, and depends
> a lot on what your goal is. If you do a web search for wieghted round
> robin or load balancing, you'll get a lot of food for thought. If you
> really need to do careful scheduling--say for load balancing--you'll
> need to take into account not just requests but open connections, and
> the (unfortunately C, I think) code in the wikipedia weighted round
> robin entry is reasonable.
>
> On the other hand, if all you just need to ensure an *average*
> response time over a significant number of iterations, and your goal
> is statistical distribution not real-world load managment, randomizing
> will serve you just as well and be much easier to implement:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
> use List::Util qw(shuffle);
>
> my %weights = ( 'foo' => 12,
> 'bar' => 7,
> 'baz' => 2,
> 'quux' => 6,
> 'zip' => 1);
>
> my @a;
>
> while (1) {
> while (my($k, $v) = each %weights) {
> push(@a, $k) for 1..$v;
Or without the for modifier:
push @a, ( $k ) x $v;
> }
>
> foreach (shuffle(@a)) {
> # do something
> }
> }
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>