MongoDBx::Class::ConnectionPool::Rotated - A simple connection pool with rotated connections
version 1.030002
# create a MongoDBx::Class object normally: use MongoDBx::Class; my $dbx = MongoDBx::Class->new(namespace => 'MyApp::Model::DB'); # instead of connection, create a pool my $pool = $dbx->pool(max_conns => 200, type => 'rotated'); # max_conns defaults to 100 # or, if you need to pass attributes to MongoDB::Connection->new(): my $pool = $dbx->pool(max_conns => 200, type => 'rotated', params => { host => $host, username => $username, password => $password, }); # get a connection from the pool on a per-request basis my $conn = $pool->get_conn; # ... do stuff with $conn and return it when done ... $pool->return_conn($conn); # not really needed, but good practice for future proofing and quick pool type switching
MongoDBx::Class::ConnectionPool::Rotated is an implementation of the MongoDBx::Class::ConnectionPool Moose role. In this implementation, the pool has a maximum number of connections. An index is kept, and whenever someone makes a request for a connection, the connection at the current index is returned (but not taken out of the pool, as opposed to backup pools), and the index is raised. If a connection does not exist yet at the current index and the maximum has not been reached, a new connections is created, added to the pool and returned. If the maximum has been reached and the index is at the end, it is rotated to the beginning, and the first connection in the pool is returned. Therefore, every connection in the pool can be shared by an unlimited number of requesters.
This pool is most appropriate for smaller pools where you want to distribute the workload between a set of connections and you don't mind sharing.
MongoDBx::Class::ConnectionPool
Returns the connection at the current index and raises the index. If no connection is available at that index and the maximum has not been reached yet, a new connection will be created. If the index is at the end, it is returned to the beginning and the first connection from the pool is returned.
Doesn't do anything in this implementation but required by MongoDBx::Class::ConnectionPool.
Ido Perlmuter, <ido at ido50.net>
<ido at ido50.net>
Please report any bugs or feature requests to bug-mongodbx-class at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MongoDBx-Class. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-mongodbx-class at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc MongoDBx::Class::ConnectionPool::Rotated
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MongoDBx::Class
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/MongoDBx::Class
CPAN Ratings
http://cpanratings.perl.org/d/MongoDBx::Class
Search CPAN
http://search.cpan.org/dist/MongoDBx::Class/
MongoDBx::Class, MongoDB::Connection.
Copyright 2010-2014 Ido Perlmuter.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install MongoDBx::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MongoDBx::Class
CPAN shell
perl -MCPAN -e shell install MongoDBx::Class
For more information on module installation, please visit the detailed CPAN module installation guide.