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

Download:
MongoDB-Async-0.503.2.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.2   Source   Latest Release: MongoDB-Async-0.702.3

NAME ^

MongoDB::Async::Pool - Pool of connections

SYNOPSIS ^

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;

METHODS ^

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

Creates pool of MongoDB::Async::Connection objects

$pool->get;

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_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

->connections_in_use

->connections_in_pool

syntax highlighting: