added some advice to debugging replicants so that we can see a replicant dsn, got...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / Balancer.pm
CommitLineData
26ab719a 1package DBIx::Class::Storage::DBI::Replicated::Balancer;
2
3use Moose;
4use List::Util qw(shuffle);
5
6=head1 NAME
7
8DBIx::Class::Storage::DBI::Replicated::Balancer; A Software Load Balancer
9
10=head1 SYNOPSIS
11
12This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. You
13shouldn't need to create instances of this class.
14
15=head1 DESCRIPTION
16
17Given a pool (L<DBIx::Class::Storage::DBI::Replicated::Pool>) of replicated
18database's (L<DBIx::Class::Storage::DBI::Replicated::Replicant>), defines a
19method by which query load can be spread out across each replicant in the pool.
20
21=head1 ATTRIBUTES
22
23This class defines the following attributes.
24
25=head1 METHODS
26
27This class defines the following methods.
28
29=head2 next_storage ($pool)
30
31Given a pool object, return the next replicant that will serve queries. The
32default behavior is to randomize but you can write your own subclasses of
33L<DBIx::Class::Storage::DBI::Replicated::Balancer> to support other balance
34systems.
35
36=cut
37
38sub next_storage {
39 my $self = shift @_;
40 my $pool = shift @_;
41
50336325 42 return (shuffle($pool->active_replicants))[0];
26ab719a 43}
44
45
46=head1 AUTHOR
47
48John Napiorkowski <john.napiorkowski@takkle.com>
49
50=head1 LICENSE
51
52You may distribute this code under the same terms as Perl itself.
53
54=cut
55
561;