[Dbix-class] Startup speed [SOLUTION]
Pedro Melo
melo at simplicidade.org
Sat Aug 18 09:04:41 GMT 2007
Hi,
The original problem is below. Basically my 75 static schema files
where taking 19 seconds to start up.
The solution (executive summary) was:
* move load_components() into a base class, use base that class on
all the sources (mst suggestion);
* replace custom "load_classes" loop with the basic load_classes()
and a loop over sources (tracked down after a message from Hartmaier
Alexander).
With this two changes, the load time is now:
melo at MrTray:lib $ time perl -MWG::S -e 1
real 0m2.058s
user 0m1.818s
sys 0m0.096s
Thanks to all.
A more detailed version follows.
----
After some tips from mst, I moved my load_components() to a base
class and used that as my use base in my sources.
So this code:
package My::S::Source;
use strict;
use base qw( DBIx::Class );
__PACKAGE__->load_components(qw( A B C D Core ) );
.....
becomes
package My::BaseSource;
use strict;
use base qw( DBIx::Class );
__PACKAGE__->load_components(qw( A B C D Core ) );
1;
and from all my sources, I removed the load_components(), and switch
the base:
use base qw( DBIx::Class );
to
use base qw( My::BaseSource );
After all this changes my startup time was now:
real 0m7.973s
user 0m6.970s
sys 0m0.132s
which is a massive improvement. But the timings sent by Alex where
much better for a comparable amount of tables, so I dig deeper.
The second problem was that I wanted to do some shortcut methods in a
special namespace for each source. So I was replacing load_classes()
with:
foreach my $class (@classes) { # @classes is calculated with
Module::Pluggable
$class =~ s/common_prefix//;
__PACKAGE__->load_class($class);
# create shortcut method here
}
Instead I rewrote the code to:
__PACKAGE_->load_classes;
foreach my $source (__PACKAGE__->sources) {
# create shortcut method here
}
and this made the startup time move to:
real 0m2.058s
user 0m1.818s
sys 0m0.096s
Much, much better now.
Many thanks to all.
On Aug 17, 2007, at 1:27 PM, Pedro Melo wrote:
> Hi,
>
> I'm working on a project that has about 75 tables (when we finish
> I expect them to be in the 120-something). Running:
>
> time perl -MSchema -e 1
>
> gives:
>
> real 0m19.851s
> user 0m18.674s
> sys 0m0.195s
>
> For production, given that restarts are not common, this is
> acceptable. For development, this is a pain.
>
> I'm using latest DBIC, Class::C3 and C:C3::XS.
>
> I'm considering using bleadperl for most developments to take
> advantage of the even greater speedups, but then I have to do a
> round of testing with the production perl.
>
> Apart from those, is there any secret formula to speed up the
> startup time?
>
> Thanks in advance,
> --
> Pedro Melo
> Blog: http://www.simplicidade.org/notes/
> XMPP ID: melo at simplicidade.org
> Use XMPP!
>
>
>
> _______________________________________________
> List: http://lists.rawmode.org/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 at lists.rawmode.org
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo at simplicidade.org
Use XMPP!
More information about the DBIx-Class
mailing list