| DBIx::Class::Storage::DBI::Replicated::Balancer - A Software Load Balancer |
DBIx::Class::Storage::DBI::Replicated::Balancer - A Software Load Balancer
This role is used internally by the DBIx::Class::Storage::DBI::Replicated manpage.
=head1 DESCRIPTION
Given a pool (the DBIx::Class::Storage::DBI::Replicated::Pool manpage) of replicated database's (the DBIx::Class::Storage::DBI::Replicated::Replicant manpage), defines a method by which query load can be spread out across each replicant in the pool.
This class defines the following attributes.
If auto_validate has some sort of value, run the validate_replicants every $seconds. Be careful with this, because if you set it to 0 you will end up validating every query.
The the DBIx::Class::Storage::DBI manpage object that is the master database all the replicants are trying to follow. The balancer needs to know it since it's the ultimate fallback.
The the DBIx::Class::Storage::DBI::Replicated::Pool manpage object that we are trying to balance.
Replicant storages (slaves) handle all read only traffic. The assumption is that your database will become readbound well before it becomes write bound and that being able to spread your read only traffic around to multiple databases is going to help you to scale traffic.
This attribute returns the next slave to handle a read request. Your pool attribute has methods to help you shuffle through all the available replicants via it's balancer object.
This class defines the following methods.
Lazy builder for the current_replicant_storage attribute.
This method should be defined in the class which consumes this role.
Given a pool object, return the next replicant that will serve queries. The default behavior is to grap the first replicant it finds but you can write your own subclasses of the DBIx::Class::Storage::DBI::Replicated::Balancer manpage to support other balance systems.
This returns from the pool of active replicants. If there are no active replicants, then you should have it return the master as an ultimate fallback.
Advice on next storage to add the autovalidation. We have this broken out so that it's easier to break out the auto validation into a role.
This also returns the master in the case that none of the replicants are active or just just forgot to create them :)
Rolls the Storage to whatever is next in the queue, as defined by the Balancer.
Advice on the select attribute. Each time we use a replicant we need to change it via the storage pool algorithm. That way we are spreading the load evenly (hopefully) across existing capacity.
Advice on the select_single attribute. Each time we use a replicant we need to change it via the storage pool algorithm. That way we are spreading the load evenly (hopefully) across existing capacity.
Advice on the current_replicant_storage attribute. Each time we use a replicant we need to change it via the storage pool algorithm. That way we are spreading the load evenly (hopefully) across existing capacity.
Given an identifier, find the most correct storage object to handle the query.
John Napiorkowski <john.napiorkowski@takkle.com>
You may distribute this code under the same terms as Perl itself.
| DBIx::Class::Storage::DBI::Replicated::Balancer - A Software Load Balancer |