in reply to Re^2: Perl threads to open 200 http connections
in thread Perl threads to open 200 http connections
The first thing I notice is that there are things wrong with the code you've posted.
You have use strict; but $thread is never declared?
Also, you are attempting to start 200 threads, but only waiting for one to complete.
Try this:
#! perl -slw use strict; use threads ( stack_size => 4096 ); use threads::shared; use LWP::Simple; use Time::HiRes qw[ time sleep ]; our $T ||= 200; my $url = ### your url (of the actual file!) here ###; my $running :shared = 0; my $start = time; for( 1 .. $T ) { async( sub{ { lock $running; ++$running }; sleep 0.001 while $running < $T; my $id = shift; getstore( $url, qq[c:/test/dl.t.$id] ); --$running; }, $_ )->detach; } sleep 1 while $running; printf "Took %.3f seconds\n", time() - $start;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Perl threads to open 200 http connections
by robrt (Novice) on Aug 04, 2010 at 13:07 UTC | |
by ikegami (Patriarch) on Aug 04, 2010 at 16:19 UTC | |
by BrowserUk (Patriarch) on Aug 04, 2010 at 16:28 UTC | |
by robrt (Novice) on Aug 05, 2010 at 14:41 UTC |