Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > LWP and threads: anything to look out for?

Reply
Thread Tools

LWP and threads: anything to look out for?

 
 
John Bokma
Guest
Posts: n/a
 
      10-12-2005
I want to move from Parallell UserAgent to using threads. Are there things
I should be aware of, or is this a piece of cake?

(Another option might be forking since IIRC Windows does this using
threads).

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com

 
Reply With Quote
 
 
 
 
zentara
Guest
Posts: n/a
 
      10-12-2005
On 12 Oct 2005 06:53:26 GMT, John Bokma <> wrote:

>I want to move from Parallell UserAgent to using threads. Are there things
>I should be aware of, or is this a piece of cake?
>
>(Another option might be forking since IIRC Windows does this using
>threads).


The only good reason to use threads, is if you want an easy way to share
realtime data between threads. Things such as progress data for a
progress indicator, or when you want to regex the downloaded results,
and do something in your main program, based on the regex.

Otherwise it is probably more efficient and easier to just fork. There
is Parallel::ForkManager.

But threads are pretty easy once you get the hang of the little details.
One thing to watch out for, is if you run any "exec" from any thread, it
will kill and replace all running threads with the exec'd code.



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      10-12-2005
John Bokma <> wrote:
> I want to move from Parallell UserAgent to using threads.


Why?

> Are there
> things I should be aware of, or is this a piece of cake?


I don't think you will have a problem specific to LWP as long you don't try
to share/clone LWP objects across threads. Of course, threaded programming
in general is more difficult than non-threaded, so I wouldn't say it will
be a piece of cake, unless you are already experienced in threaded
programming.

> (Another option might be forking since IIRC Windows does this using
> threads).


Maybe forking is better. I prefer it over threading in most circumstances.
(It seems to be a theme this week). But it is hard to tell without knowing
more about what you are trying to do.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      10-12-2005
wrote:

> John Bokma <> wrote:
>> I want to move from Parallell UserAgent to using threads.

>
> Why?


Good question I think that ParallellUA = UA + threading, and doesn't
add anything, and since UA is more a core module, I prefer the latter.

Also, with ParallellUA the documentation was a bit unclear to me.

>> Are there
>> things I should be aware of, or is this a piece of cake?

>
> I don't think you will have a problem specific to LWP as long you
> don't try to share/clone LWP objects across threads. Of course,
> threaded programming in general is more difficult than non-threaded,
> so I wouldn't say it will be a piece of cake, unless you are already
> experienced in threaded programming.


Java, and enough CGI experience (sharing resources, locking, etc).

>> (Another option might be forking since IIRC Windows does this using
>> threads).

>
> Maybe forking is better. I prefer it over threading in most
> circumstances. (It seems to be a theme this week). But it is hard to
> tell without knowing more about what you are trying to do.


I want to have n workers in parallell, each getting a request from a
Queue, fetching the page, storing the result, and next. Sleeping (not
wasting CPU cycles) in between each fetch.

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      10-12-2005
John Bokma <> wrote:
> wrote:
>
> > John Bokma <> wrote:
> >> I want to move from Parallell UserAgent to using threads.

> >
> > Why?

>
> Good question I think that ParallellUA = UA + threading, and doesn't
> add anything, and since UA is more a core module, I prefer the latter.


I think ParallelUA = UA + nonblocking IO, rather than threading. Assuming
it is well implemented (I haven't used ParallelUA enough to know), I think
non-blocking IO is better than threads for this task.

> Also, with ParallellUA the documentation was a bit unclear to me.


OK, fair enough. Anything in particular you found unclear?

>
> >> (Another option might be forking since IIRC Windows does this using
> >> threads).

> >
> > Maybe forking is better. I prefer it over threading in most
> > circumstances. (It seems to be a theme this week). But it is hard to
> > tell without knowing more about what you are trying to do.

>
> I want to have n workers in parallell, each getting a request from a
> Queue, fetching the page, storing the result, and next.


Store the results on the filesystem or DB, or in Perl memory?

Is the queue dynamically added to (based on the results returned from
earlier tasks in the queue) or is it built in a start-up phase and then
only consumed from then on?

If the queue is dynamically added to, that argues for threads. If each
page-fetch takes less than 1/20 of a second or so (and there are tens of
thousands of them), that argues for threads, (althought I might instead
just batch them up into chunks of several page fetches) . Otherwise, I'd
go with forking with Parallel::ForkManager. (or ParallelUA ).

> Sleeping (not
> wasting CPU cycles) in between each fetch.


This part I'm not sure of. Why sleep rather than just fetch the next
item from the queue? Are you sleeping only in the case of an empty queue
(which of course only makes sense if the queue is dynamic)? Or to avoid
overloading the remote server(s) you are fetching from?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use a look-ahead and a look-behind at the same time? dan.j.weber@gmail.com Perl Misc 4 04-09-2008 10:25 PM
have a look at my blog site for asp.net .. there is microsoft contest also ( u can win so much)have a look at my blog site for asp.net .. there is microsoft contest also ( u can win so much) justpratik Python 0 06-08-2007 04:48 AM
Unique message thought about the idea of throwing out Google for financial corruption (not counting their Napstering Library project), if anything, an experiment pr Computer Support 6 10-15-2005 09:32 PM
Why do look-ahead and look-behind have to be fixed-width patterns? inhahe Python 3 01-28-2005 12:50 PM
<tr> with a 1x1 image as a filler on a table with padding of 2 look thicker in netscape but they look ok in IE. Serial # 19781010 HTML 1 08-10-2003 09:05 PM



Advertisments