Which version of threads are you using? Upgrading to 0.71 seems to avoid memory leaks that the combination of 5.10 and some earlier versions (eg. 0.67) exhibited.

There is no way that you should using 100% cpu with 10 threads performing IO. This seems to be a problem with Parallel::ForkManager on 5.10. You can do pretty much exactly the same thing as above, but using threads, like this:

#! perl -slw use threads; use threads::shared; use LWP::UserAgent; use HTTP::Request; my $semStdout :shared; my $running :shared = 0; open(LIST,"urls.txt"); while ( my $tld = <LIST> ) { chomp $tld; Win32::Sleep( 100 ) while do{ lock $running; $running >= 10 }; async{ { lock $running; ++$running; } my $url = "http://$tld/"; my $ua = new LWP::UserAgent; $ua->timeout(5); $ua->agent("Mozilla/6.0"); my $req = HTTP::Request->new('GET',$url); my $res = $ua->request($req); my $content = $res->content; my $status = $content =~ /OK/i ? 'ack' : 'nak'; { lock $semStdout; printf "(%3d)$tld: %s\n", threads->self->tid, $status; } { lock $running; --$running; } }->detach; } close(LIST);

Memory usage seems to be stable and cpu usage < 10% for 10 threads.

There are better, lower resource intensive ways of using threads, but it does have the virtue of being very close to the P::FM way of operating which you might consider a bonus.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Parallel::ForkManager (high cpu and a lot of memory) by BrowserUk
in thread Parallel::ForkManager (high cpu and a lot of memory) by marto9

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.