# HTTP::Async # this one will do 20mbps, fastest invokation for me was # perl -w httpasync.pl 0 15 use strict; use warnings; use threads; use threads::shared; use HTTP::Async; use HTTP::Request; use HTTP::Response; my @urls : shared = ; my $numchildren = $ARGV[0]; my $numthreads = $ARGV[1]; print "num children: $numchildren, threads: $numthreads\n"; my $pid = 0; for(my $i = 0; $i < $numchildren; ++$i) { $pid = fork(); if($pid == 0) { last; } else { print "forked $pid\n"; } } $pid = $$; print "pid: $pid\n"; sub fetch { my $tid = shift; my $async = HTTP::Async->new; $async->slots(int(@urls)); my %idurl = (); while(1) { if($async->total_count < $async->slots) { my $url = $urls[int(rand(int(@urls)))]; chomp $url; print "start $pid/$tid: $url\n"; my $id = $async->add(HTTP::Request->new(GET=>$url)); $idurl{$id} = $url; } if($async->not_empty) { my ($resp, $id) = $async->next_response(); if($resp) { my $size = length $resp->content; my $url = $idurl{$id}; print "finish $pid/$tid: $url, $size bytes\n"; delete $idurl{$id}; } } } } my @threads; for(my $i = 0; $i < $numthreads; ++$i) { my $thread = threads->create(\&fetch,$i); push(@threads, $thread); } foreach (@threads) { $_->join(); } __DATA__ some urls...