[Dbix-class] dynamic class requires

Jason Kohles email at jasonkohles.com
Fri Dec 28 14:47:34 GMT 2007


On Dec 27, 2007, at 5:39 PM, Lawrence Hochberg wrote:

> We currently loaded hundreds of classes in our load_classes  
> statement.  These classes in turn have many dependencies.  The end  
> result is that the load_classes statement takes over a second to  
> execute.  This would not be a problem for a long running perl  
> program, but we use the schema functionality to handle short lived  
> requests on a webserver.  Most of these requests only need to access  
> a handful of tables, so it seems wasteful (read slow) to load all of  
> the classes for every table in our database when only a couple are  
> needed.  One possibility is to break up our tables into logical  
> groups, but because of cross dependencies, this is not optimal from  
> a maintenance point of view.  I am currently trying to hack in  
> AUTOLOAD functionality, but if such a feature already exists, or  
> there is a better approach, I'd appreciate the feedback.
>
If you use something like mod_perl or fastcgi, then you *want* all  
these classes to be loaded at once, otherwise when the interpreters  
start loading things after they are forked, then they all end up  
sucking up memory for their own copies of each of these classes.  If  
you aren't using something like mod_perl or fastcgi, then those would  
be better options than trying to delay the loading of classes, which  
is going to get very complicated very quickly as you find that when  
you load one resultsource class, you also have to load the ones it has  
relationships with, and the ones they have relationships with, and so  
on, until you probably end up loading most of them at once anyway...

Using mod_perl or fastcgi and loading all the classes up front moves  
that load time to the interpreter startup time, rather than to the  
request time, so the fact that it takes a couple of seconds isn't an  
issue when it's taking a couple of seconds every time the web server  
is restarted, rather than a couple of seconds for every request.

> thank you for your help!
>
> Regards,
> lmh
>
>
> At 05:22 PM 12/27/2007, Ash Berlin wrote:
>
>> On 27 Dec 2007, at 20:37, Lawrence Hochberg wrote:
>>
>>> Hi
>>>
>>> Is there a way to dynamically require a class at the first
>>> instantiation of an instance as opposed to loading all classes
>>> upfront via load_classes?
>>>
>>> I am looking for similar functionality to the Class::Factory module
>>> methods add_factory_type and register_factory_type.
>>>
>>> Regards,
>>> lmh
>>
>> First things first: Why?
>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.rawmode.org
>>
>
>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.rawmode.org
>

-- 
Jason Kohles, RHCA RHCDS RHCE
email at jasonkohles.com - http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire





More information about the DBIx-Class mailing list