1 package DBIx::Class::Storage::DBI::Replicated::Balancer::Random;
4 with 'DBIx::Class::Storage::DBI::Replicated::Balancer';
8 DBIx::Class::Storage::DBI::Replicated::Balancer::Random - A 'random' Balancer
12 This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. You
13 shouldn't need to create instances of this class.
17 Given a pool (L<DBIx::Class::Storage::DBI::Replicated::Pool>) of replicated
18 database's (L<DBIx::Class::Storage::DBI::Replicated::Replicant>), defines a
19 method by which query load can be spread out across each replicant in the pool.
21 This Balancer uses L<List::Util> keyword 'shuffle' to randomly pick an active
22 replicant from the associated pool. This may or may not be random enough for
27 This class defines the following attributes.
31 This class defines the following methods.
35 Returns an active replicant at random. Please note that due to the nature of
36 the word 'random' this means it's possible for a particular active replicant to
37 be requested several times in a row.
43 my @active_replicants = $self->pool->active_replicants;
44 my $count_active_replicants = $#active_replicants +1;
45 my $random_replicant = int(rand($count_active_replicants));
47 return $active_replicants[$random_replicant];
52 John Napiorkowski <john.napiorkowski@takkle.com>
56 You may distribute this code under the same terms as Perl itself.
60 __PACKAGE__->meta->make_immutable;