jbhasin83 has asked for the wisdom of the Perl Monks concerning the following question:

I have written the website in perl CGI script. I found that the perl CGI was taking some time to load. After it loads it only takes few milliseconds to finish. So I understood that the problem was only in loading all the modules (use libraries or modules). So I removed all the use libraries/modules and then loading time reduced immensely. I cant remove these use libraries and even a single use library increases the load time immensely. I would like some help/suggestions to fix this issue. Thanks.

Replies are listed 'Best First'.
Re: Perl CGI Loads Slow
by hippo (Archbishop) on Apr 04, 2017 at 08:00 UTC

    Some options:

    • FCGI or CGI::Fast can allow you to move to a persistent model with only minor changes to your existing code - although you will need an FCGI-capable webserver. See also mod_perl
    • Don't load all the modules in all the scripts. If you've been clever in your design then it is likely that most of the scripts will only need a fraction of the modules.
    • If some modules are only needed by some execution paths in a single script then only load those modules on demand in those execution paths.
    • Use lighter modules to begin with. You don't say which modules you have currently used but avoiding the monsters (Moose is a good one to ditch for instance) can make a huge difference.
Re: Perl CGI Loads Slow
by choroba (Cardinal) on Apr 04, 2017 at 07:57 UTC
    Use mod_perl, CGI::Fast, or move to PSGI. It loads all the modules when starting the server, not for each request. But, you might need big changes in the code, as the persistent environment keeps the values of global variables across requests.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Perl CGI Loads Slow
by marto (Cardinal) on Apr 04, 2017 at 08:20 UTC
Re: Perl CGI Loads Slow
by Anonymous Monk on Apr 04, 2017 at 17:36 UTC
    Would you mind listing these libraries out? It is important to know which ones are standard CPAN libraries and which ones are custom libraries developed from your silo.