Re: Ima::DBI and connections at Apache startup

[prev] [thread] [next] [Date index for 2004/10/04]

From: Perrin Harkins
Subject: Re: Ima::DBI and connections at Apache startup
Date: 17:15 on 04 Oct 2004
On Mon, 2004-10-04 at 10:03, Brad Bowman wrote:
> In short, combining Ima::DBI, Class::DBI::mysql and Apache opened 
> database connections at startup time and kept them across forking
> causing discomfort...

This won't happen if you use your own db_Main method, bypassing the
Ima::DBI connection stuff.  Apache::DBI is smart enough to avoid this. 
However you will get warnings about database handles (the ones opened at
startup) being destroyed.  I did an ugly workaround for this.  From our
startup.pl:

use Apache::DBI;
use DBI;
use DBD::mysql;
BEGIN{ $DBI::connect_via = 'connect_cached'; };
# The above line requires a little explanation.  We need to connect to
the
# database during startup to get table information for the Class::DBI
# objects.  Apache::DBI will skip the connection cache during startup to
# avoid forking problems, but this causes errors from Class::DBI about
# the database handle being DESTROY'd without an explicit disconnect.
# This is because Class::DBI expects the handles to be persistent.  To
fix
# this, we use a cheat to make DBI do a connect_cached during startup
# (as opposed to using Apache::DBI) and then explicitly disconnect that
# at the end of this fule and tell it to use Apache::DBI after that. 
Phew.

[... bunch of preload modules ...]

# Disconnect before fork and then switch to using Apache::DBI
My::ClassDBI::Base->db_Main()->disconnect();
$DBI::connect_via = 'Apache::DBI::connect';

Obviously we need to do better than this.

> This is one approach, make Ima::DBI mod_perl aware.
> 
> Another approach is to let DBI handle it and just call connect_cached.
> This'd be slower, I guess.

That was the main issue according to Schwern when I complained about the
closure thing before.

> But at least then Ima::DBI isn't duplicating
> Apache::DBI and DBI's functions.

Agreed, this would be highly desirable.  Maybe you could do some
benchmarking on how much of a difference the closure makes?

- Perrin

(message missing)

Ima::DBI and connections at Apache startup
Brad Bowman 08:03 on 04 Oct 2004

Re: Ima::DBI and connections at Apache startup
Perrin Harkins 17:15 on 04 Oct 2004

Re: Ima::DBI and connections at Apache startup
Brad Bowman 01:15 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Brad Bowman 04:47 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Perrin Harkins 14:27 on 05 Oct 2004

Problem with has_many and searching
John Day 16:06 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Perrin Harkins 14:26 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Brad Bowman 05:01 on 06 Oct 2004

Re: Ima::DBI and connections at Apache startup
Perrin Harkins 15:23 on 06 Oct 2004

Re: Problem with has_many and searching
Perrin Harkins 16:21 on 05 Oct 2004

Re: Problem with has_many and searching
John Day 17:26 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Tony Bowden 17:31 on 06 Oct 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52