Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Isolating dynamically loaded modules with Thread::Isolate.

by gmpassos (Priest)
on Jan 30, 2005 at 01:18 UTC ( #426324=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Isolating dynamically loaded modules with Thread::Isolate.
in thread Isolating dynamically loaded modules with Thread::Isolate.

Maybe this can help you. With a normal Perl thread, create 2 threads, make the 2 thread load 2 pages, let's say www.perlmonks.com, 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 = 'http://www.perlmonks.com/' ; 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".


Comment on Re^4: Isolating dynamically loaded modules with Thread::Isolate.
Download Code
Re^5: Isolating dynamically loaded modules with Thread::Isolate.
by BrowserUk (Pope) on Jan 30, 2005 at 01:48 UTC

    This is what I got from your script above:

    P:\test>426324 GOT PAGE: 61833 bytes GOT PAGE: 61456 bytes INC: AutoLoader.pm Carp.pm Config.pm DynaLoader.pm Exporter.pm Exporter/Heavy.pm Fcntl.pm Storable.pm Thread/Isolate.pm XSLoader.pm attributes.pm c:/Perl/lib/auto/Storable/_freeze.al c:/Perl/lib/auto/Storable/autosplit.ix c:/Perl/lib/auto/Storable/freeze.al overload.pm strict.pm threads.pm threads/shared.pm vars.pm warnings.pm warnings/register.pm (in cleanup) Can't call method "PUSH" on an undefined value at + c:/Perl/site/lib/Thread/Isolate.pm line 224 during global destructio +n.

    And this is what I got from my equivalent:

    P:\test>426297 GOT PAGE: 61637 bytes GOT PAGE: 61585 bytes AutoLoader.pm Carp.pm Config.pm DynaLoader.pm Exporter.pm overload.pm strict.pm threads.pm vars.pm warnings.pm warnings/register.pm

    Rather less loaded?

    The script I used was:

    #! perl -slw use strict; use threads qw[ async ]; my $thr = async { require LWP::Simple; return LWP::Simple::get( 'http://www.perlmonks.com/' ); }; print 'GOT PAGE: ', length $thr->join, ' bytes'; $thr = async { require LWP::Simple; return LWP::Simple::get( 'http://www.perlmonks.com/' ); }; print 'GOT PAGE: ', length $thr->join, ' bytes'; print for sort keys %INC;

    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
      Ok, now get your code and put it as a module and ensure that it will always load that!

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-07-12 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (239 votes), past polls