title: Is it bad practice to just kick off new threads for blocking operations (Perl)
body: <p>If doing CPU intensive tasks I believe it is optimal to have one thread per core.  If you have a 4 core CPU you can run 4 instances of a CPU intensive subroutine without any penalty.  For example I once experimentally ran four instances of a CPU intensive algorithm on a four core CPU.  Up to four times the time per process did not decrease.  At the fifth instances all instances took longer.</p>
  
  <p>What is the case for blocking operations?  Let's say I have a list of 1,000 URLs.  I have been doing the following:</p>
  
  <p>(Please don't mind any syntax errors, I just mocked this up)</p>
  
  <pre><code>my @threads;
  foreach my $url (@urlList) {    
       push @threads, async {
           my $response = $ua-&gt;get($url);
           return $response-&gt;content;   
       }
  }
  
  foreach my $thread (@threads) {
      my $response = $thread-&gt;join;
      do_stuff($response); 
  }
  </code></pre>
  
  <p>I am essentially kicking off as many threads as there are URLs in the URL list.  If there are a million URLs then a million threads will be kicked off.  Is this optimal, if not what is an optimal number of threads?  Is using threads a good practice for ANY blocking I/O operation that can wait (reading a file, database queries, etc)?</p>
  
  <p><strong>Related Bonus Question</strong></p>
  
  <p>Out of curiosity does Perl threads work the same as Python and it's GIL?  With python to get the benefit of multithreading and utilize all cores for CPU intensive tasks you have to use multiprocessing.</p>