Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

DB Connection pool

by Anonymous Monk
on May 06, 2002 at 23:43 UTC ( #164483=perlquestion: print w/replies, xml ) Need Help??

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

Monks My project is to write a daemon which will process a long list of SQL process against an Oracle DB.I need to run a defined set of SQL's paralelly to achieve efficiency.(Note: all the SQL's runs against the same DB). For this , I would like to have a DB connection pool thereby avoiding multiple connections to the DB.My questions is, how would I do it in perl or is there any modules whichis available to write a DB connection pool. FYI, this has nothing to do with mod_perl or Apache.Thanks for your help

Replies are listed 'Best First'.
Re: DB Connection pool
by gav^ (Curate) on May 07, 2002 at 00:42 UTC
    You might want to look at

    To quote:

    SQL Relay is a persistent database connection pooling, proxying and load balancing system for Unix and Linux supporting ODBC, Oracle, MySQL, mSQL, PostgreSQL, Sybase, MS SQL Server, IBM DB2, Interbase, Lago and SQLite with APIs for C, C++, Perl, Perl-DBD, Python, Python-DB, Zope, PHP, Ruby, Ruby-DBD and Java, command line clients, a GUI configuration tool and extensive documentation. The APIs support advanced database operations such as bind variables, multi-row fetches, client side result set caching and suspended transactions. It is ideal for speeding up database-driven web-based applications, accessing databases from unsupported platforms, migrating between databases, distributing access to replicated databases and throttling database access.
    Sounds interesting, thought I haven't had time to play with it yet.


Re: DB Connection pool
by perrin (Chancellor) on May 07, 2002 at 04:47 UTC
    First, connection pools do not avoid multiple connections to a database. What they do is limit the overall number of connections open at any given time and re-use them between parallel threads or processes. They may reduce the number of connections needed at one time, but only if some of the threads aren't doing any database work.

    Second, you don't need one. Just fork processes for the number of connections you want, connect separately in each (after the fork) and go. That's the most efficient you can get with this.

Re: DB Connection pool
by samtregar (Abbot) on May 07, 2002 at 01:01 UTC
    Are you sure this will help? Unless your database server has multiple processors it is unlikely that running multiple queries in parallel will be substantially faster than running the same queries serially.

    If you do have multiple processors on your database server, then my suggestion would be to fork() N processes to each do 1/N of the work (N = number of available processors). Each process can then establish a private database connection, saving you the trouble of dealing with connection pools.

    Of course, more complicated schemes are possible but they are unlikely to be worth the effort.


      Unless your database server has multiple processors it is unlikely that running multiple queries in parallel will be substantially faster than running the same queries serially.

      Not necessarily true. Compiling a large project (say, a linux kernel) on a single CPU machine completes substantially faster with two processes (make -j2 ...) than it does in a single process, as this allows the CPU to keep compiling in one process while the other waits for disk access.

      While I haven't tested whether this is also true of databases, I suspect that it is likely to be.

        My experience with databases is that they are far less I/O bound than many other tasks. As long as your machine has sufficient free RAM and your database is properly tuned, your queries should not be waiting for disk access often enough to matter.

        Of course, it's worth testing. It might be that the proper setting for N is actually 2 * number of available CPUs.


Re: DB Connection pool
by lachoy (Parson) on May 07, 2002 at 01:03 UTC

    The module ResourcePool might be useful here.

    M-x auto-bs-mode

Re: DB Connection pool
by samgold (Scribe) on May 07, 2002 at 01:38 UTC
    What do you mean by a defined set of SQL's paralelly? Are you talking about more than one SELECT statement or are you talking about parallel query? I am an Oracle DBA and would like to help you out if I can. I try to use perl as much as I can and this sounds very interesting.

Re: DB Connection pool
by rdfield (Priest) on May 07, 2002 at 12:17 UTC
    Why not use PL/SQL and call the stored package from you daemon? Sounds like a job for DBMS_JOB and DBMS_PIPE to me.


Re: DB Connection pool
by Anonymous Monk on May 07, 2002 at 14:42 UTC
    Go to :

    and dload issue-01 and read :

    Design patterns : Singeltons from brian d foy ...
    i think this is exaclty what u want ...:")


    (in the past i wanted to do a similar CGI-thing and are blaming now that i did't know that)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://164483]
Approved by gav^
Front-paged by samtregar
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-10-04 11:05 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (16 votes). Check out past polls.