Commit | Line | Data |
26ab719a |
1 | package DBIx::Class::Storage::DBI::Replicated::Balancer; |
2 | |
3 | use Moose; |
4 | use List::Util qw(shuffle); |
5 | |
6 | =head1 NAME |
7 | |
8 | DBIx::Class::Storage::DBI::Replicated::Balancer; A Software Load Balancer |
9 | |
10 | =head1 SYNOPSIS |
11 | |
12 | This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. You |
13 | shouldn't need to create instances of this class. |
14 | |
15 | =head1 DESCRIPTION |
16 | |
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. |
20 | |
21 | =head1 ATTRIBUTES |
22 | |
23 | This class defines the following attributes. |
24 | |
25 | =head1 METHODS |
26 | |
27 | This class defines the following methods. |
28 | |
29 | =head2 next_storage ($pool) |
30 | |
31 | Given a pool object, return the next replicant that will serve queries. The |
32 | default behavior is to randomize but you can write your own subclasses of |
33 | L<DBIx::Class::Storage::DBI::Replicated::Balancer> to support other balance |
34 | systems. |
35 | |
36 | =cut |
37 | |
38 | sub 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 | |
48 | John Napiorkowski <john.napiorkowski@takkle.com> |
49 | |
50 | =head1 LICENSE |
51 | |
52 | You may distribute this code under the same terms as Perl itself. |
53 | |
54 | =cut |
55 | |
56 | 1; |