Apache2-Controller
view release on metacpan or search on metacpan
lib/Apache2/Controller/DBI/Connector.pm view on Meta::CPAN
<Location '/busy/database/page'>
SetHandler modperl
PerlInitHandler MyApp::Dispatch
PerlHeaderParserHandler MyApp::DBI::Writer MyApp::DBI::Read
</Location>
If you use a tiered database structure with one master record
and many replicated nodes, you can do it this way. Then you
overload C<< dbi_pnotes_name >> to provide the pnotes key,
say "dbh_write" and "dbh_read". In the controller get them
with C<< $self->pnotes->{a2c}{dbh_write} >> and
C<< $self->pnotes->{a2c}{dbh_read} >>, etc.
If you subclass DBI, specify your DBI subclass name with
the directive C<< A2C_DBI_Class >>. Note that this has
to be connected using a string C<< eval() >> instead of
the block C<< eval() >> used for normal L<DBI> if you
do not specify this directive.
=head1 Accessing $dbh from controller
lib/Apache2/Controller/DBI/Connector.pm view on Meta::CPAN
Because a reference persists in package space, the database handle
will remain connected after a request ends.
Usually Apache will rotate requests through child processes.
This means that on a lightly-loaded server with a lot of spare child processes,
you will quickly get a large number of idle database connections, one per child.
To solve this you need to set your database handle idle timeout
to some small number of seconds, say 5 or 10. Then you load
L<Apache::DBI> in your Apache config file so they automatically
get reconnected if needed.
Then when you get a load increase, handles are connected that persist
across requests long enough to handle the next request, but during
idle times, your database server conserves resources.
There are various formulas for determining how much memory is
needed for the maximum number of connections your database server
provides. MySQL has a formula in their docs somewhere to calculate
( run in 1.380 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )