Welcome to WebmasterWorld Guest from 54.225.38.176

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Server doesn't kill process

Using multi-threaded script

     
10:15 am on Apr 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


I've written a basic API script, user enters data on a form, script goes off, looks stuff up, comes back with results.

As the info it was looking up was increasing, it was taking longer and longer, and I was getting annoyed with it.

So I converted it to use::threads;

Basically, the threads are simple, it spawns x threads simultaneously, to do the searching, and joins them immediately, hence waiting for them all to finish and reporting their results.

This works fine, the only problem is, the server sometimes doesn't kill the process anymore, and I eventually get a CGI timeout error.

Even if I put a die at the end of the script, the text "Died at ....." appears in the HTML, but the progress bar still doesn't stop, and the process doesn't disappear off my server.

If I reun the script from a command line, it runs and terminates instantly as it should.

Anyone else had a problem with multi-threaded CGI?

10:27 am on Apr 27, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10551
votes: 10


just a wild guess here - try the detach() method on each thread.
11:55 am on Apr 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


Can't - I need to wait for them to finish so I can grab the output. According to spec, calling the join is blocking and will only return the output once the thread has terminated.
4:07 pm on Apr 27, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


my experience with threads is very limited, have you tried using the kill() function?
5:08 pm on Apr 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


Hmmm, take a look at this website then:
[perl.com...]

Seems like you could learn something! Very handy and easy for parallel processing. Why run 12 API's at once, when you can run all 12 simultaneously, then the total time taken is only the time of the single longest one.

Anyway, as I said, you run a new thread, and if you don't detach it, you call $thread -> join; and it waits for the thread to terminate.

7:09 am on Apr 28, 2007 (gmt 0)

Full Member

5+ Year Member

joined:Jan 29, 2007
posts:228
votes: 0


maybe you could use LWP module's 'timeout' method to call your subroutines...
11:46 am on Apr 28, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


I'm just using LWP simple for this one.

LWP::UserAgent has a timeout method -- used to specify how long it tries for before it gives up. Not even nearly the same thing!

Anyway, I've just doubled it to 24 queries by adding another API, this one's using SOAP::Lite so that wouldn't cover it.

4:47 pm on May 1, 2007 (gmt 0)

Full Member

10+ Year Member

joined:July 23, 2003
posts:227
votes: 0


The CPAN module POE was built to handle multi-threading. See [search.cpan.org...]
5:26 pm on May 1, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Mar 29, 2007
posts:1147
votes: 0


Looks interesting, but very complicated. I don't really understand it, could you post an example bit of code?