richard5mith has asked for the wisdom of the Perl Monks concerning the following question:
On our web site we have two parts that run side by side.
The first, which outputs the general pages the site has, uses mod_rewrite to direct any URL ending in .phtml through a Perl script that pulls together the relevant templates and outputs the page. Essentially this means that /homepage.phtml becomes /index.pl?action=homepage and the file called homepage is loaded and processed. This runs through mod_perl and Apache::Registry (or ModPerl::Registry when under Apache2/mod_perl2).
The second part is a Perl script which uses threads.
use threads; use threads::shared; use Thread::Running;
We have a series of modules that connect to different supplier systems, like foo::system1, foo::system2 etc. The Perl script which uses threads knows which of these suppliers we need to connect to and then creates a new thread for each of the calls, so that all the communication with the suppliers happens at the same time. We do this via a function in the script called search...
sub search { # ... code above here takes in the params eval { eval("use " . $enginename); $enginehandler = $enginename->new(); $results{$engine} = $enginehandler->search($foo, $bar); }; }
The engine name is passed into the sub (hence the eval'd use line) and the whole call is wrapped in an eval to trap errors (the suppliers have a habit of changing their system or being offline and breaking, so we don't want the whole system to fall over just because one of them isn't working). The results hash that the reply goes into is shared at the top of the script using threads::shared.
share(%results);
After all the threads are created, which we do with...
threads->create(\&search, $foo, $bar);
We wait for 30 seconds and then grab everything that's been put into the shared hash, store that, and then move onto the next part of the process (which is a new script, which doesn't use threads).
Running under mod_cgi, this all works fantastically. When under mod_perl however, things aren't quite so peachy.
Under mod_perl, the search itself still works fine. All the threaded stuff seems to work great, it's our first script that starts failing, the one that handles the .phtml URLs. At random intervals after mod_perl has been enabled for the threads.pl script and searches are occuring, accessing a page like /homepage.phtml returns a blank page. The Apache access log shows that /homepage.phtml has been requested, the error log shows nothing, but the browser gets nothing returned, not even a content-type. Occassionally, accessing other Perl scripts on the server causes the browser to pop-up a dialog asking where you'd like to save it, again, as if no content-type was actually getting returned.
I put some warns in the index.pl script that mod_rewrite pushes through, and on the times where I get a blank page, they aren't sent to the error log, meaning that Apache isn't even executing the script. I changed the Apache LogLevel to debug instead of warn, and that didn't shed any light on the matter either.
I initially thought this was a problem with Apache 1.3/mod_perl1, thinking that they weren't setup for threads under the pre-fork model. So I installed Apache2, migrated everything over to that and the threaded worker module, but the results are essentially the same. As soon as we switch to SetHandler perl-script instead of cgi-script and tell it to use ModPerl::Registry, pages fail to come up.
I've thought that maybe the threads are dying with errors which are getting caught by the eval and the process that was running that thread is then the one Apache is picking to server the next .phtml request, only to find out it's unable to use it when it's already too late. But that's me thinking of logical reasons rather than knowing anything specific.
I've tried everything I can think of at this point, but getting nowhere, with no sign of anything similar elsewhere online. Not being able to swtich on mod_perl for the threads.pl script is really taxing the server and it's becoming a bigger problem with each day.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mod_perl, threads, and blank pages
by Codon (Friar) on May 08, 2006 at 21:47 UTC | |
by BrowserUk (Patriarch) on May 09, 2006 at 02:47 UTC | |
by richard5mith (Beadle) on May 08, 2006 at 22:55 UTC | |
|
Re: mod_perl, threads, and blank pages
by perrin (Chancellor) on May 08, 2006 at 16:57 UTC | |
by richard5mith (Beadle) on May 08, 2006 at 18:50 UTC | |
|
Re: mod_perl, threads, and blank pages
by blahblahblah (Priest) on May 09, 2006 at 02:07 UTC |