Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: mod_perl, threads, and blank pages

by Codon (Friar)
on May 08, 2006 at 21:47 UTC ( #548087=note: print w/ replies, xml ) Need Help??


in reply to mod_perl, threads, and blank pages

The system you are describing sounds strangely similar to one we were trying to build: Apache2/mod_perl2 + Perl iThreads, parallel searches to multiple threads, collecting data, returning it back to the user. The differences we had included spawning all threads at ChildInit and putting them into a wait loop, then signalling them when we wanted them to work. They'd go do stuff, put the data in a shared hash, then return to the wait loop.

What we found is that Perl is not thread-safe. Let me repeat that: PERL IS NOT THREAD-SAFE! I say this with emphasis because after several long nights hunting down segfaults in the system, turning on debugging, adding evals to trap errors, banging my head, I came across this in the log:

Bizarre ARRAY copy in caller() at Common::Logger::log_stuff ...
Common::Logger is our internal logging package. log_stuff is the logging function. It calls CORE::caller(). This blew up. Evidently, the thread boundary is a bit like an event horizon and caller can't cross it without potentially breaking. I saw this message a few more times before we ditched threads entirely.

I strongly encourage you to investigate the possibility of dead threads fouling your app. Then look at alternatives to a threaded model. We moved to a multi-tiered Apache platform. We have an Apache "front-end" that talks to an Apache "back-end" (which in turn can talk to itself; we have layers of parallel and serially parallel processing).

When we mentioned to merlyn, TheDamien, and Nick Clark that we were looking at the threaded approach when we were at OSCON 2005, they all pretty much wished us luck. I do the same for you now.

Ivan Heffner
Sr. Software Engineer, DAS Lead
WhitePages.com, Inc.


Comment on Re: mod_perl, threads, and blank pages
Download Code
Re^2: mod_perl, threads, and blank pages
by richard5mith (Beadle) on May 08, 2006 at 22:55 UTC

    The threads themselves seem to work fine until mod_perl is switched on. The application is live in it's non mod_perl version at the moment. But yes, it took us a long time to get to the stage where we got something other than bizarre errors in the log. And with mod_perl, they just get ever stranger.

    We actually started as non-threading, using a simple Perl powered web server (HTTP::Server based I think it was) plus LWP::Paralllel on the front-end to connect to it with different parameters, which it then went off and processed. But it all became too slow and unwieldy as the number of searches increased and the Perl webserver forked more and more. Returning to an LWP::Parallel process connecting to a more stable backend (like a light web server) is tempting, if only for scalability reasons.

    But darnit, when you've come this far, sometimes you just want things to work. :)

Re^2: mod_perl, threads, and blank pages
by BrowserUk (Pope) on May 09, 2006 at 02:47 UTC
    What we found is that Perl is not thread-safe. Let me repeat that: PERL IS NOT THREAD-SAFE!

    That sentance makes no sense at all.

    Bizarre ARRAY copy in caller() at Common::Logger::log_stuff ...

    Common::Logger is our internal logging package. log_stuff is the logging function. It calls CORE::caller(). This blew up.

    Hmm. Did you report this 'bug'?

    It's quite possible to generate the 'Bizarre ARRAY copy' bug in perfectly ordinary, non-threaded bad code. What's more, perl will often not give you much in the way of clues as to what you are doing wrong when it happens.

    I don't know what version of Perl you were using, but it seems quite unlikely that using caller with threads is a problem. Set the loop counters in the following code to any values you like; or increase the depth of sub calls as far as you like, and it will run for as long as you let it without producing a "bizarre array copy error". Or any other error.

    #! perl -slw use strict; use threads; sub t1{ printf "%3d:t1: %s\n", threads->tid, join '|', grep defined, calle +r(1); return } sub t2 { t1(); printf "%3d:t2: %s\n", threads->tid, ''; '|', grep defined, calle +r(1); return } sub t3 { for( 1 .. 100 ) { t2(); printf "%3d:t3: %s\n", threads->tid, join '|', grep defined, +caller(1); } return; } my @threads = map{ threads->create( \&t3 ) } 1 .. 100; sleep 3; $_->join for @threads;

    It seems much more likely that your Common::Logger class was not written to be called from multiple threads. Indeed, the most likely scenario is that you were passing objects between threads. That's a documented no no.

    Most modern cars are pretty safe, but if you attempt to climb trees in them, it's likely to be unsuccessful; but saying cars are useless because your tree climbing attempt went ary, is unlikely to garner much support, even from the tree-hugging, cars-are-evil crowd.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://548087]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-08-23 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (177 votes), past polls