perlfaq nodetype
faq_monk
<P>
Beyond the normal measures described to make general Perl programs faster or smaller, a
<FONT SIZE=-1>CGI</FONT> program has additional issues. It may be run several times per second. Given that each time it runs it will need to be re-compiled and will often allocate a megabyte or more of system memory, this can be a killer. Compiling into
<FONT SIZE=-1>C</FONT>
<STRONG>isn't going to help
you</STRONG> because the process start-up overhead is where the bottleneck is.
<P>
There are two popular ways to avoid this overhead. One solution involves running the Apache
<FONT SIZE=-1>HTTP</FONT> server (available from <A HREF="http://www.apache.org/)">http://www.apache.org/)</A> with either of the mod_perl or mod_fastcgi plugin modules.
<P>
With mod_perl and the Apache::Registry module (distributed with mod_perl), httpd will run with an embedded Perl interpreter which pre-compiles your script and then executes it within the same address space without forking. The Apache extension also gives Perl access to the internal server
<FONT SIZE=-1>API,</FONT> so modules written in Perl can do just about anything a module written in
<FONT SIZE=-1>C</FONT> can. For more on mod_perl, see <A HREF="http://perl.apache.org/">http://perl.apache.org/</A>
<P>
With the
<FONT SIZE=-1>FCGI</FONT> module (from
<FONT SIZE=-1>CPAN),</FONT> a Perl executable compiled with sfio (see the
<EM>INSTALL</EM> file in the distribution) and the mod_fastcgi module (available from <A HREF="http://www.fastcgi.com/)">http://www.fastcgi.com/)</A> each of your perl scripts becomes a permanent
<FONT SIZE=-1>CGI</FONT> daemon process.
<P>
Both of these solutions can have far-reaching effects on your system and on the way you write your
<FONT SIZE=-1>CGI</FONT> scripts, so investigate them with care.
<P>
See <A HREF="http://www.perl.com/CPAN/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/">http://www.perl.com/CPAN/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/</A>
.
<P>
<FONT SIZE=-1>A</FONT> non-free, commerical product, ``The Velocity Engine for Perl'', (http://www.binevolve.com/ or <A HREF="http://www.binevolve.com/bine/vep)">http://www.binevolve.com/bine/vep)</A> might also be worth looking at. It will allow you to increase the performance of your perl scripts, upto 25 times faster than normal
<FONT SIZE=-1>CGI</FONT> perl by running in persistent perl mode, or 4 to 5 times faster without any modification to your existing
<FONT SIZE=-1>CGI</FONT> scripts. Fully functional evaluation copies are available from the web site.
<P>