Ivan Ratnikov > MongoDB-Async-0.702.3 > MongoDB::Async::Pool



Annotate this POD

View/Report Bugs
Module Version: 0.2   Source  


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


new({ MongoDB::Async::MongoClient args }, { MongoDB::Async::Pool attrs });

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


->max_conns , ->max_conns(new value)

Max connection count. ->get will block current coroutine when max_conns reached. Not recomended to change it in runtime. Default: 0 - no limit

->timeout , ->timeout(new value) One unused connection will be closed every "timeout" sec. 0 - don`t close Default: 10. Requries running EV::loop



syntax highlighting: