Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Maybe this can help you. With a normal Perl thread, create 2 threads, make the 2 thread load 2 pages, let's say, but you need to do all of this loading only 1 time LWP::Simple.

Remember that when you create 2 threads and use LWP::Simple from this 2 threads you are loading LWP::Simple 2 times in the memory since Perl duplicate everything when a thread is created. If you play a while with threads you will see that Perl threads use to much memory, so I can't load more than 10 threads to do a real job. With Delphi for example we can load more than 30 threads and still have a good execution, with Perl if I use more than 8 I start to see the application to be slow! Is more about performance and not what is possible to do.

Here's a simple way to do that with Thread::Isolate:

use Thread::Isolate ; $|=1 ; my $thi = Thread::Isolate->new() ; $thi->use('LWP::Simple'); my $url = '' ; my @threds = ( threads->new( \&get_pages , $url ) , threads->new( \&get_pages , $url ) , ) ; foreach my $threds_i ( @threds ) { $threds_i->join ; } print "INC:\n" ; foreach my $Key (sort keys %INC ) { print "$Key\n" ; } sub get_pages { my $url = shift ; my $html = $thi->call('LWP::Simple::get' , $url) ; print "GOT PAGE: ". length($html) ." bytes\n" ; }

Graciliano M. P.
"Creativity is the expression of liberty".

In reply to Re^4: Isolating dynamically loaded modules with Thread::Isolate. by gmpassos
in thread Isolating dynamically loaded modules with Thread::Isolate. by gmpassos

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (4)
    As of 2021-02-28 20:24 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found