Re: [CDBI] CDBI, Oracle, and mod_perl

[prev] [thread] [next] [Date index for 2005/08/14]

From: William Ross
Subject: Re: [CDBI] CDBI, Oracle, and mod_perl
Date: 13:39 on 14 Aug 2005
On 14 Aug 2005, at 06:32, Simon Miner wrote:
> Hi,
>
> (Note: I originally posted this message to the groups.kasei.com  
> version of this list. Then I saw the note on the wiki that the  
> mailing list had been moved. I apologize if sending this message  
> results in a duplicate post.)
>
> My organization uses mod_perl and Oracle to run our high traffic e- 
> commerce web site.  Our site currently using DBI (via Apache::DBI)  
> to interact with its database.  We would like to bring Class::DBI  
> into the mix, but we are concerned about the two-connections-per- 
> process problem mentioned in the ReUseLegacyDBIHandle page on the  
> Class::DBI wiki (http://wiki.class-dbi.com/index.cgi? 
> ReUseLegacyDBIHandle).
>
> Perrin Harkins' wiki page on overriding the do_Main() method to  
> accommodate mod_perl (http://wiki.class-dbi.com/index.cgi? 
> UsingWithModPerl) seems to provide a potential solution, but it  
> also appears to contradict the assertion on the  
> ReUseLegacyDBIHandle page that you cannot use a normal DBI handle  
> for a Class::DBI handle.  There appeared to be some back and forth  
> on this in a previous thread on this list (http://groups.kasei.com/ 
> mail/arc/cdbi-talk/2005-02/msg00218.html), but I couldn't see any  
> resolution coming out of it.
>
> Has there been any further development on this matter?  I would  
> like to recommend Class::DBI for our e-commerce web site, but we  
> just could not abide doubling our Oracle connections.  As has been  
> mentioned, they are just too resource intensive.  Is it possible to  
> (safely) set up a database connection for a Class::DBI object using  
> a DBI handle?
It's very simple and perfectly safe, so long as you take the right  
precautions. Forgive me if I go on a bit:

Under normal circumstances Class::DBI uses a handle provided by  
Ima::DBI, which uses a clever but now rather eccentric system of  
closures to achieve persistent but economical database links. It does  
this by injecting a db_[connection name] method into the namespace of  
the class calling connection() or set_db(). In the case of Class::DBI  
the connection name is always 'Main', so the database handle is  
always retrieved by calling db_Main. Most serious users of cdbi end  
up subclassing this runtime method either to relax cdbi's class-level  
attachment to its database or to supply a database handle they've  
already got.

A cdbi object can make use of any database handle that has the root  
class DBIx::ContextualFetch (which is a DBI subclass of Tony's that  
adds some shortcuts and defaults. The wisdom of this decision is  
often debated). This inheritance should have no effect on the use of  
your handle by other machinery unless there happens to be a clash of  
method names, so the easiest answer is to tweak your existing  
connection pool so that it contains cdbi-compatible handles, and then  
put in your base class a db_Main method that retrieves its connection  
from this pool.

The problems mentioned on the wiki arise when you can't change  
existing code, but still want to use existing handles. If you really  
want cdbi's convenience then it's possible to inject the necessary  
methods into your handle when it arrives in the cdbi application (ie  
in db_Main, again), but I don't think I would recommend investing  
that much customisation work right now. There's a lot of forking and  
blustering going on at the moment and it would probably be more  
sensible to wait a month or three and then see which of the resulting  
solutions serves you best.

(also, I haven't used Oracle, but I get the impression that cdbi  
isn't all that well adapted to a setting where connections are very  
expensive. Perhaps someone else here has suggestions.)

It's also worth mentioning that under mod_perl, or in any other  
persistent environment, you have to pay attention to cdbi's use of  
class data and symbol-table manipulation. If you're using the same  
classes for more than one application, or to access more than one  
database, then you will need to take extra care about  
compartmentalising data and configuration settings and returning the  
right handle for each request.

hth

will










_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] CDBI, Oracle, and mod_perl
Simon Miner 05:32 on 14 Aug 2005

Re: [CDBI] CDBI, Oracle, and mod_perl
William Ross 13:39 on 14 Aug 2005

[CDBI] Re: CDBI, Oracle, and mod_perl
Edward J. Sabol 17:46 on 14 Aug 2005

RE: [CDBI] CDBI, Oracle, and mod_perl
Simon Miner 15:04 on 15 Aug 2005

Generated at 13:17 on 19 Aug 2005 by mariachi v0.52