Hi John, How it may work if I am using Rose::DB::Object::Loader and creating my Manager subclasses in the runtime ? I ran into the same problem with looping over thousand of My::Manager->get_someTable() calls Thanks, Maxim Grigoriev.
> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of John Siracusa > Sent: Thursday, January 10, 2008 7:25 PM > To: Rose-DB-Object > Subject: Re: [RDBO] Too Many connections > > On 1/10/08 5:30 PM, James Masters wrote: > > Looking into this, I seem to simply be doing the following > in a "for" > > loop more than 100 times: > > > > my $shipobj = MGORD::Shipment->new(shipid => $shipid)->load(with > > =>['items', 'costs', 'problems', 'predictedcosts', 'toaddress', > > 'fromaddress']); > > > > So the implication is that each one of these is opening a > new client > > connection and not closing it. > > > > I know I can just increase the default connections limit > from 100 to > > say 200 to fix the problem. But is Rose really supposed to be > > creating all these client connections or have I written > something wrongly? > > When an RDBO-derived object needs a database connection, it > calls its db() > method: > > > http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object.pm#db > > If a db object does not yet exist, the init_db() method is > called to create > one: > > > http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object. pm#init_db > > The default implementation of init_db() returns a new > Rose::DB object, which in turn will create its own DBI > database connection. > > If you'd like one or more objects to share a single > Rose::DB-derived object (and therefore a single database > connection), a straightforward way to do it is to explicitly > code the sharing: > > my $db = My::DB->new; # share this among all objects created below > > for(...) > { > my $shipobj = > MGORD::Shipment->new(db => $db, ...)->load(...); > } > > If you'd rather not do this explicitly, or if you simply want > another default policy, then you should override the > init_db() method, either in your common base class or in each > individual RDBO-derived class, depending on the policy you want. > > For example, if you want all objects of or derived from a > given class to share a single database connection by default, > you could use the > new_or_cached() Rose::DB method: > > http://search.cpan.org/dist/Rose-DB/lib/Rose/DB.pm#new_or_cached > > writing an init_db() method like this: > > sub init_db { My::DB->new_or_cached } > > Remember that no matter what policy you implement in > init_db(), you can always explicitly create and pass a > Rose::DB-derived object as that value of a "db" parameter to > any individual object or Manager call. > > -John > > > > > -------------------------------------------------------------- > ----------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for just about > anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.n et/marketplace > _______________________________________________ > Rose-db-object mailing list > Rose-db-object@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rose-db-object > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object