Re: Ima::DBI and connections at Apache startup
[prev]
[thread]
[next]
[Date index for 2004/10/05]
On Tue, 2004-10-05 at 03:15, Brad Bowman wrote:
> Is there anything tricky to your replacement db_Main, or
> does it just call DBI->connect?
It's a little bit tricky because it has to return a handle with the
attributes that Class::DBI expects:
RaiseError => 1,
FetchHashKeyName => 'NAME_lc',
ShowErrorStatement => 1,
ChopBlanks => 1,
RootClass => 'DBIx::ContextualFetch
Also, when you write your own db_Main, it breaks dbi_commit and
dbi_rollback because Ima::DBI no longer knows about your handle. You
need to either override them in your base class to make them work, or
just call Your::ClassDBI->db_Main()->commit() instead.
> There is a significant difference, especially since Class::DBI
> calls db_Main everywhere expecting a the same handle.
>
> Benchmark: timing 50000 iterations of DBI_cc, ImaDBI...
> DBI_cc: 14 wallclock secs (12.16 usr + 0.43 sys = 12.59 CPU) @ 3971.41/s (n=50000)
> ImaDBI: 2 wallclock secs ( 0.81 usr + 0.33 sys = 1.14 CPU) @ 43859.65/s (n=50000)
> Rate DBI_cc ImaDBI
> DBI_cc 3971/s -- -91%
> ImaDBI 43860/s 1004% --
>
> However, Ima::DBI's caching can cause errors under mod_perl
> so something has to be done. Perhaps another form of caching
> which is easier to tweak?
I hate to introduce mod_perl-specific stuff into Ima::DBI, but it looks
like that may be the only way to keep the performance high. My approach
would be check for $ENV{MOD_PERL} and if true create a different kind of
closure for getting the handle. This closure would store the handle in
Apache->request()->pnotes() for the duration of the current request,
making it very fast to fetch and ensuring that it will get cleaned up
and Apache::DBI will get called again at the start of the next request.
This ensures that the cleanup_handler for transactions will happen.
> Another BIG hitch with my plan is that Class::DBI needs to
> consistently get the same handle from db_Main for transactions
> to work.
That shouldn't be a problem at all. You always get the same handle in
the same process when you use connect_cached/Apache::DBI and send the
same connect string.
- Perrin
|
(message missing)
|