http://www.perlmonks.org?node_id=199709

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

By using FastCGI (.fcgi) does that automaticaly increase the speed of a perl script or do you need to use FastCGI functions. FastCGI makes it so the perl script does not have to be compiled everytime it is run, no? Thanks in advance.

Replies are listed 'Best First'.
Re: FastCGI?
by Aristotle (Chancellor) on Sep 21, 2002 at 09:59 UTC
    If you want to automatically boost the speed of cleanly(!) written CGI scripts, you should probably have a look at mod_perl and its Apache::Registry handler instead. Even for sloppily coded scripts, some gains may be had using the Apache::PerlRun handler, albeit not as much.

    Makeshifts last the longest.

Re: FastCGI?
by vek (Prior) on Sep 21, 2002 at 15:39 UTC
    If installing mod_perl is an option for you, I heartily second Aristotle's comments regarding Apache::Registry. I've seen awesome performance gains when running vanilla CGI scripts with Apache::Registry. You'll have to make sure your CGI scripts are pretty strictly coded however so there may be some "tweaking" required to get them to run under Apache::Registry. You might want to check out cgi to mod_perl Porting on perl.apache.org.

    -- vek --
Re: FastCGI?
by samtregar (Abbot) on Sep 21, 2002 at 22:32 UTC
    Yes. By using FastCGI you will save the per-request initialization cost of running a normal CGI. This includes the time it takes to load the Perl interpreter and the time it takes to compile your script. In terms of performance enhancement FastCGI offers basically the same speedup as mod_perl. However, mod_perl also allows you to access the Apache API which gives you a whole load of capabilities that are not available in CGI or FastCGI.

    -sam

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: FastCGI?
by adrianh (Chancellor) on Sep 21, 2002 at 09:13 UTC

    Warning: I do not use FastCGI. My understanding of it's functionality may be wrong. Please take with appropriate sized salt particles

    Short answer: No.

    Longer answer...

    As I understand FastCGI operates by separating out the one-time initialisation code from the per-request code.

    Your FastCGI script then does the one-time initialisation once, then sits there taking requests and passing them onto the per-request code.

    You get the speedup by only running the script "once" (it just sits there forever in a infinite loop serving requests) so you avoid the perl compilation hit, and the one-time initialisation hit.

    So, unless you rewrite you code in the form of:

    initialise(); while(FCGI::accept() >= 0) { serve_request(); };

    you won't get any speed advantage.