Apache::Sybase::ConPool - A Sybase connection pooling module for Apache/mod_perl
Pre-load this module in your mod_perl startup script:
use Apache::Sybase::ConPool (config => '/usr/local/apache/lib/conpool.cfg');
Then in your mod_perl scripts/handlers:
use Apache::Sybase::ConPool; my $dbh = Apache::Sybase::ConPool::getDbh($server); .... use $dbh for some query or queries .... Apache::Sybase::ConPool::freeDbh($dbh);
Apache::Sybase::ConPool allocates a pre-defined number of connections at startup and stores them in a hash. These connections can then be shared among the httpd child processes as needed, using System V semaphores to syncronize access to each connection.
This module is useful if you have a large (5 or more) client web servers that connect to the same database server, as it reduces the number of open sockets that are needed on the database server.
I have found that allocating 10 connections for each web server works well, but you should of course experiment with this.
The connection details are handled in a configuration file (see sample conpool.cfg included in the package). The location of the configuration file is passed in when the module is use'd in the mod_perl startup script.
Apache::Sybase::ConPool defines the following calls:
- $dbh = getDbh($server)
Get a connection to $server. An entry for this server has to have been defined in conpool.cfg. This returns undef if no connections are available (under heavy load, for example).
Release the lock on $dbh, and return it to the pool of available connections.
Force the releasing of all database connections that this process may have. Usefull to be included in a cleanup handler to make sure that no stray locks are kept on a connection.
The web server(s) has to be restarted if the database server goes down.
The database handles can become unusable if a child dies while holding a lock on the handle.
Michael Peppler, firstname.lastname@example.org
Copyright (c) 2001 Michael Peppler
You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file, with the exception that it cannot be placed on a CD-ROM or similar media for commercial distribution without the prior approval of the author.