MongoDB::Async::Pool - Pool of connections
You can't use one connection in several coro's because one coro can try send query while other coro waiting for response from already running query. Creating new connection for every coroutine might be slow, so this module caches connections for you.
my $pool = MongoDB::Async::Pool->new({}, { timeout => 0, max_conns => 50 }); async { my $big_data = $pool->get->testdb->testcoll->find({ giveme => 'large dataset'})->data; }; async { my $big_data = $pool->get->testdb->testcoll->find({ giveme => 'another large dataset'})->data; }; #it's good idea to cache connection in variable if you going to use it several times async { my $connection = $pool->get; # do queries }; EV::run;
Creates pool of MongoDB::Async::Connection objects
Returns MongoDB::Async::MongoClient object from pool or creates new connection if pool is empty. Might block current coro until some coro return connection if pool is empty and "max_conns" connections currently in use. You needn't think about returning object to pool, it`ll be returned on DESTROY
ATTRIBUTES:
Max connection count. ->get will block current coroutine when max_conns reached. Not recomended to change it in runtime. Default: 0 - no limit
To install MongoDB::Async, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MongoDB::Async
CPAN shell
perl -MCPAN -e shell install MongoDB::Async
For more information on module installation, please visit the detailed CPAN module installation guide.