in reply to Parallel downloading under Win32?
- under Win32 AND Linux
- without having it crash due to too many leaked scalars
- without using a GB of ram
- without being incredibly slow when downloading
(I don't have Linux!)
(The maximum throughput of my connection: 2496 kbps.)
#! perl -sw use 5.010; use strict; use threads ( stack_size => 0 );; use Thread::Queue; sub thread { my $tid = threads->tid; require LWP::Simple; my( $Q, $dir ) = @_; while( my $url = $Q->dequeue ) { my( $file ) = $url =~ m[/([^/]+)$]; my $status = LWP::Simple::getstore( $url, "$dir/$file" ); printf STDERR "[$tid] $url => $dir/$file: $status\n"; } } our $T ||= 4; our $DIR ||= '.'; say scalar localtime; my $Q = new Thread::Queue; my @threads = map threads->create( \&thread, $Q, $DIR ), 1 .. $T; chomp, $Q->enqueue( $_ ) while <>; $Q->enqueue( (undef) x $T ); $_->join for @threads; say scalar localtime;
Console log from test session:
__END__ C:\test\tmp>dir Volume in drive C has no label. Volume Serial Number is 8C78-4B42 Directory of C:\test\tmp 29/04/2009 20:13 <DIR> . 29/04/2009 20:13 <DIR> .. 29/04/2009 20:13 904 urls.txt 1 File(s) 904 bytes 2 Dir(s) 436,394,737,664 bytes free C:\test\tmp>..\pget urls.txt Wed Apr 29 20:13:51 2009 [1] http://extensions.services.openoffice.org/files/2318/4/as_IN.oxt = +> ./as_IN.oxt: 200 [1] http://extensions.services.openoffice.org/files/2318/4/as_IN.oxt = +> ./as_IN.oxt: 200 [3] http://wordpress.org/latest.zip => ./latest.zip: 200 [3] http://extensions.services.openoffice.org/files/2318/4/as_IN.oxt = +> ./as_IN.oxt: 200 [1] http://wordpress.org/latest.zip => ./latest.zip: 200 [1] http://uk2.php.net/distributions/php-debug-pack-5.2.9-2-Win32.zip +=> ./php-debug-pack-5.2.9-2-Win32.zip: 200 [3] http://wordpress.org/latest.zip => ./latest.zip: 200 [1] http://extensions.services.openoffice.org/files/2318/4/as_IN.oxt = +> ./as_IN.oxt: 200 [2] http://uk2.php.net/distributions/php-debug-pack-5.2.9-2-Win32.zip +=> ./php-debug-pack-5.2.9-2-Win32.zip: 200 [2] http://extensions.services.openoffice.org/files/2318/4/as_IN.oxt = +> ./as_IN.oxt: 200 [1] http://uk2.php.net/distributions/php-debug-pack-5.2.9-2-Win32.zip +=> ./php-debug-pack-5.2.9-2-Win32.zip: 200 [3] http://wordpress.org/latest.zip => ./latest.zip: 200 [2] http://uk2.php.net/distributions/php-debug-pack-5.2.9-2-Win32.zip +=> ./php-debug-pack-5.2.9-2-Win32.zip: 200 [1] http://wordpress.org/latest.zip => ./latest.zip: 200 [4] http://search.cpan.org/CPAN/authors/id/N/NW/NWCLARK/perl-5.8.9.tar +.bz2 => ./perl-5.8.9.tar.bz2: 200 [3] http://uk2.php.net/distributions/php-debug-pack-5.2.9-2-Win32.zip +=> ./php-debug-pack-5.2.9-2-Win32.zip: 200 Wed Apr 29 20:17:01 2009 C:\test\tmp>dir Volume in drive C has no label. Volume Serial Number is 8C78-4B42 Directory of C:\test\tmp 29/04/2009 20:13 <DIR> . 29/04/2009 20:13 <DIR> .. 29/04/2009 20:15 96,501 as_IN.oxt 29/04/2009 20:16 1,853,086 latest.zip 29/04/2009 20:16 11,121,414 perl-5.8.9.tar.bz2 29/04/2009 20:17 5,149,576 php-debug-pack-5.2.9-2-Win32.zip 29/04/2009 20:13 904 urls.txt 5 File(s) 18,221,481 bytes 2 Dir(s) 436,377,415,680 bytes free
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parallel downloading under Win32?
by Xenofur (Monk) on Apr 29, 2009 at 20:05 UTC | |
by Corion (Patriarch) on Apr 29, 2009 at 20:10 UTC | |
by Xenofur (Monk) on Apr 29, 2009 at 21:25 UTC | |
by BrowserUk (Patriarch) on Apr 29, 2009 at 21:07 UTC | |
by Xenofur (Monk) on Apr 29, 2009 at 21:36 UTC | |
by BrowserUk (Patriarch) on Apr 30, 2009 at 02:17 UTC | |
by Xenofur (Monk) on Apr 30, 2009 at 09:30 UTC | |
|