Bug #25518: Limit process count apt-mirror forks an unlimited number of "apt-ftparchive" processes, which are very IO intensive. This makes the system very unresponsive. Same goes for "gzip", which is CPU intensive. Limit both loops to the maximum number of threads. Remove a very anoying double print, which breaks output formatting. diff --git a/apt-mirror b/apt-mirror index 7ac8b19..916035e 100755 --- a/apt-mirror +++ b/apt-mirror @@ -477,8 +477,6 @@ my $size_output = format_bytes($need_bytes); print "$size_output will be downloaded into archive.\n"; -print STDERR "$size_output will be downloaded into archive.\n"; - download_urls("archive", sort keys %urls_to_download); @@ -509,6 +507,7 @@ sub collect_children { } if ( get_variable( "recreate_packages" ) eq 'yes' ) { + my $nthreads = get_variable("nthreads"); my @gzip_files = (); my @children = (); my $pid; @@ -535,9 +534,13 @@ if ( get_variable( "recreate_packages" ) eq 'yes' ) { if ( $pid == 0 ) { chdir get_variable("mirror_path")."/$path"; - exec "apt-ftparchive $filetype $source > $packages\n"; + exec "exec apt-ftparchive $filetype $source > $packages\n"; } push @children, $pid; + if ( scalar @children >= $nthreads ) { + my $dead = wait(); + @childrens = grep { $_ != $dead } @childrens; + } } collect_children( @children ); @@ -552,9 +555,13 @@ if ( get_variable( "recreate_packages" ) eq 'yes' ) { if ( $pid == 0 ) { chdir get_variable("mirror_path")."/$path"; - exec "gzip < $packages > $packages.gz\n"; + exec "exec gzip < $packages > $packages.gz\n"; } push @children, $pid; + if ( scalar @children >= $nthreads ) { + my $dead = wait(); + @childrens = grep { $_ != $dead } @childrens; + } } collect_children( @children ); } else {