Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Connection Pooling

by muk (Initiate)
on Oct 26, 2011 at 15:41 UTC ( [id://933919]=perlquestion: print w/replies, xml ) Need Help??

muk has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I am writing a perl module for connection pooling for a standalone application,I am new to perl ,can any body help me on how to go about this........

Thanks in advance........

Replies are listed 'Best First'.
Re: Connection Pooling
by moritz (Cardinal) on Oct 26, 2011 at 15:44 UTC

      Hi

      Thanks for replying

      Actually I am trying to build a package for connection pooling,I am working in a project where we are developing perl scripts to connect to DB2 database and perform some business logic in a unix environment.

      The actual requirement is instead of connecting to the database n number of times,get a connection from the database keep it in a pool and reuse it,so the performance can be improved.

      I tried this using resource pool but I am facing some issues,can you please advice on to which cpan module will be helpful.

Re: Connection Pooling
by mrstlee (Beadle) on Oct 26, 2011 at 16:38 UTC
    What sort of connections? TCP,other?
    If you want a server for multiple clients then the POE framework might work for you:
    POE
Re: Connection Pooling
by onelesd (Pilgrim) on Oct 26, 2011 at 23:34 UTC
    Please show samples of your code and/or anything showing research you've done on the topic.

      Hi

      Thanks for replying

      I wrote a package,the code is as below,it is working fine but the only issue is that every time there is a request a new factory is created.

      I want to know how to create the factory only once and reuse the connections in the pool.

      use ResourcePool; use ResourcePool::Factory; use ResourcePool::Factory::DBI; $db_timeOut = 120; # wait 60 seconds for connection #User credentials $data_source = 'dbi:DB2:databasename'; $username = 'username'; $auth = 'password'; eval{ # set alarm to timeout current operation local $SIG{ALRM} = \&input_timed_out; alarm $db_timeOut; $factory = ResourcePool::Factory::DBI->new($data_source,$user +name,$auth); $pool = ResourcePool->new($factory, Max => 2, MaxTry => 3, Sle +epOnFail => [30, 60] ,MaxExecTry => 3); }; alarm 0; # reset the alarm sub resource_pool { $resource = $pool->get(); return $resource ; } sub release_pool { $pool->free($resource); } sub input_timed_out { print "connection timed out hence exiting\n"; exit; }

        If it's opening new connections every time I'd look into why it's closing the connections in the first place.

        With 'Max' set to 2, $pool->get() should return undef when you try to exceed 2 connections.

        Set up a test where you attempt to get 3 resources simultaneously and watch the database logs to see what's going on with the connections.

Re: Connection Pooling
by Corion (Patriarch) on Oct 27, 2011 at 09:00 UTC

    As connection pooling always needs knowledge about the underlying protocol for each connection, you will need to tell us more. If it is a database or custom program where each client makes connections to a server, it is quite possible that connection pooling is even prohibited by the license terms of your vendor.

      Hi

      Thanks for replying

      Actually I am trying to build a package for connection pooling,I am working in a project where we are developing perl scripts to connect to DB2 database and perform some business logic in a unix environment.

      The actual requirement is instead of connecting to the database n number of times,get a connection from the database keep it in a pool where ever there is a request release a connection after using give it back to the pool,if the maximum limit is reached wait in a queue ,so the performance can be improved.

      I tried this using resource pool but I am facing some issues,is there any other way to implement this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://933919]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-24 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found