Why does the Catalyst application restart slowly?

Every time I build a Catalyst application, I get to the point where the application becomes very slow (re), the delay is about 10 seconds. Today I realized that the delay is caused by the following lines:

use lib '/home/zoul/opt/lib/perl/5.8';
use lib '/home/zoul/opt/share/perl/5.8';
use lib '/home/zoul/opt/lib/perl/5.8.8';
use lib '/home/zoul/opt/share/perl/5.8.8';

      

These lines are only needed on the server, since I do not have root access and I have Perl modules installed under ~/opt

. (I cannot use the Apaches module SetEnv

as the host does not support it. So I have to enter library paths in App.pm

.) On my development machine that shows gory latency, the paths do not exist.

My questions are: (1) Why are the lines causing so much delay, about 7 seconds? (2) What's a good way to solve this problem? The naive conditional use

doesn't work:

if ($on_the_hosting_machine)
{
    use lib '…';
}

      

I think I could eval

somehow, or is there a better way?

+2


source to share


3 answers


I don't Catalyst

, so I'm not sure if this will solve your problem, but you can try to do what is essentially what it lib.pm

does:



BEGIN { 
    if ( $on_the_hosting_machine ) {
        unshift @INC, qw'
            /home/zoul/opt/lib/perl/5.8
            /home/zoul/opt/share/perl/5.8
            /home/zoul/opt/lib/perl/5.8.8
            /home/zoul/opt/share/perl/5.8.8
        ';
    }
};

      

+9


source


1) Every time you have a use or require statement, it searches all directories in lib in order. Each use of lib makes (at least) two calls to stat.

use lib is just a wrapper for pushing @LIB ... but it also looks for the existence of the arch directory and puts it in @LIB if it exists.

You can change this change using prime no lib:



no lib ('/home/zoul/opt/lib/perl/5.8', '/home/zoul/opt/share/perl/5.8', '/home/zoul/opt/lib/perl/5.8.8', '/home/zoul/opt/share/perl/5.8.8');

      

Better yet, you could change your development environment to suit production, or even just bind those directories to real locations for your dev installation.

+6


source


Check out "Timely Start" from Jean-Louis Leroy at Perl.com . He describes the same problem and a clever solution to it.

+5


source







All Articles