Commit | Line | Data |
cb6ec758 |
1 | package DBIx::Class::Storage::DBI::Replicated::Balancer::Random; |
2 | |
3 | use List::Util qw(shuffle); |
4 | use Moose; |
17b05c13 |
5 | with 'DBIx::Class::Storage::DBI::Replicated::Balancer'; |
cb6ec758 |
6 | |
7 | =head1 NAME |
8 | |
17b05c13 |
9 | DBIx::Class::Storage::DBI::Replicated::Balancer::Random; A 'random' Balancer |
cb6ec758 |
10 | |
11 | =head1 SYNOPSIS |
12 | |
13 | This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. You |
14 | shouldn't need to create instances of this class. |
15 | |
16 | =head1 DESCRIPTION |
17 | |
18 | Given a pool (L<DBIx::Class::Storage::DBI::Replicated::Pool>) of replicated |
19 | database's (L<DBIx::Class::Storage::DBI::Replicated::Replicant>), defines a |
20 | method by which query load can be spread out across each replicant in the pool. |
21 | |
22 | This Balancer uses L<List::Util> keyword 'shuffle' to randomly pick an active |
23 | replicant from the associated pool. This may or may not be random enough for |
24 | you, patches welcome. |
25 | |
26 | =head1 ATTRIBUTES |
27 | |
28 | This class defines the following attributes. |
29 | |
30 | =head1 METHODS |
31 | |
32 | This class defines the following methods. |
33 | |
34 | =head2 next_storage |
35 | |
36 | Returns an active replicant at random. Please note that due to the nature of |
37 | the word 'random' this means it's possible for a particular active replicant to |
38 | be requested several times in a row. |
39 | |
40 | =cut |
41 | |
42 | sub next_storage { |
64cdad22 |
43 | return (shuffle(shift->pool->active_replicants))[0]; |
cb6ec758 |
44 | } |
45 | |
cb6ec758 |
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; |