Question

I have to maintain a prehistoric web site with tons of Perl code. After moving to a new Server things got fuzzy:

When multiple requests from the same Client are running on a page (generating images with GD), those scripts overwrite each others variables, leading to strange results.

As a quick workaround I set MaxRequestsPerChild=1 in Apache, which fixes this, but now things are slowed down to a crawl ...

Is there a way to separate the requests ? Any mod_perl or Apache parameters that could help me ?

Apache:

Server version: Apache/2.2.15 (Unix)
Server built:   Apr  3 2014 23:56:16
Server's Module Magic Number: 20051115:25
Server loaded:  APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)

perl -v

This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

Any solution for this would be greatly appreciated :)


EDIT: I could not find a proper way to fix things with mod_perl, but the following workaround works:

  • Disable mod_perl
  • Enable mod_cgi
  • AddHandler cgi-script .pl
  • Disable suEXEC

The last one was necessary because it gave me 'premature end of script headers' when suEXEC was enabled.

Was it helpful?

Solution

No, there's nothing you can do to "separate the requests". All the scripts running in a single Perl interpreter process will share the same environment, and under mod_perl that environment is persistent. You can try setting up ModPerl::Registry to run them in (if you haven't already) which should wrap them in their own subroutine and eliminates some of the namespace issues, but if the scripts aren't written with persistence in mind (*) you're still going to have to modify them to at least some extent.

http://perl.apache.org/docs/2.0/user/intro/start_fast.html#Registry_Scripts

You can also run in to trouble when the scripts are using particular modules such as SOAP::Lite which have a global state that is shared across all modules using it, though that is a much rarer problem.

So no, unfortunately there's nothing you can do to ensure the scripts will work okay without changing them. Some might be fine, others won't be. You should perhaps set up a regular Apache CGI server besides the separate mod_perl server and gradually migrate them over. You won't get the performance on the regular CGI server, but you also won't have the problems.

(*) In particular, and this is from memory from many, many moons ago, they must avoid setting global variables, always declare variables with my, use the CGI module (or mod_perl API) for request interaction, and things like that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top