MongoDBx::Class::ConnectionPool::Backup(3) A simple connection pool with a backup connection


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 => 'backup'); # max_conns defaults to 100
# or, if you need to pass attributes to MongoDB::Connection->new():
my $pool = $dbx->pool(max_conns => 200, type => 'backup', 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 ...


MongoDBx::Class::ConnectionPool::Backup is an implementation of the MongoDBx::Class::ConnectionPool Moose role. In this implementation, the pool has a maximum number of connections. Whenever someone makes a request for a connection, an existing connection is taken out of the pool and returned (or created if none are available and the maximum has not been reached). When the requester is done with the connection, they are expected to return the connection to the pool. If a connection is not available for the requester (i.e. the maximum has been reached and all connections are used), a backup connection is returned. This backup connection can be shared by multiple requesters, but the pool's main connections cannot.

This pool is most appropriate for larger pools where you do not wish to share connections between clients, but want to ensure that on the rare occasions that all connections are used, requests will still be honored.




The following attributes are added:


The backup MongoDBx::Class::Connection object.



Returns a connection from the pool to a requester. If a connection is not available but the maximum has not been reached, a new connection is made, otherwise the backup connection is returned.

return_conn( $conn )

Returns a connection to the pool. If a client attempts to return the backup connection, nothing will happen (the backup connection is always saved).



Called by Moose after object initiation.


Ido Perlmuter, "<ido at>"


Please report any bugs or feature requests to "bug-mongodbx-class at", or through the web interface at <>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

        perldoc MongoDBx::Class::ConnectionPool::Backup

You can also look for information at:


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 for more information.