On Tue, 5 Sep 2000, Michael Peppler wrote:

> I've come across a technique that allows modperl processes to share a 
> pool of database handles. It's not something that I have seen
> documented, so I figured I'd throw it out here.
> 
> The idea is to create a pool of connections during the main
> apache/modperl startup. Because these connections end up in the code
> segment for the child processes they are completely shareable. You
> populate a hash in a BEGIN block with x connections, and then provide
> some calls to grab the first available one (I use IPC::Semaphore to
> coordinate access to each connection).

There is no such a thing as a code segment in Perl. Everything is handled
as data, so unless you write your code in C and glue it to Perl, you
cannot ensure that some read/write variable wouldn't land on the same page
with the data that stores the connections.

> Based on preliminary tests I was able to use a 1 in 10 ratio of
> database handles per httpd child processes, which, on a large site
> would cut down on the number of connections that the database server
> needs to handle.
> 
> The advantage of this solution is that connections don't go down when
> the apache child dies (for example because the MAX_REQUEST per child
> has been reached).

If there would be a way for a chile to know its processor slot as seen by
Apache::Status, there will be no need for any semaphoring technique --
each process will access the connection by asking for its slot
number. This will work because when the child being reaped off a new
process replacing it is running in the same slot. Looks a much faster way
to me if you get hold of the slot number.

> The disadvantage is that the connections can only be restarted by
> restarting the webserver (apachectl stop/apachectl start).
> 
> This technique works with Sybase connections using either
> DBI/DBD::Sybase or Sybase::CTlib (I've not tested Sybase::DBlib, nor
> any other DBD modules).
> 
> I'd be very interested in any comments, in particular if there are any 
> downsides that I haven't considered (which is quite possible).
> 
> Michael
> -- 
> Michael Peppler         -||-  Data Migrations Inc.
> [EMAIL PROTECTED]    -||-  http://www.mbay.net/~mpeppler
> Int. Sybase User Group  -||-  http://www.isug.com
> Sybase on Linux mailing list: [EMAIL PROTECTED]
> 



_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://jazzvalley.com
http://singlesheaven.com http://perlmonth.com   perl.org   apache.org


Reply via email to