title: Python 3 multiprocessing: optimal chunk size
body: <p>How do I find the optimal chunk size for <code>multiprocessing.Pool</code> instances?</p>
  
  <p>I used this before to create a generator of <code>n</code> sudoku objects:</p>
  
  <pre><code>processes = multiprocessing.cpu_count()
  worker_pool = multiprocessing.Pool(processes)
  sudokus = worker_pool.imap_unordered(create_sudoku, range(n), n // processes + 1)
  </code></pre>
  
  <p>To measure the time, I use <code>time.time()</code> before the snippet above, then I initialize the pool as described, then I convert the generator into a list (<code>list(sudokus)</code>) to trigger generating the items (only for time measurement, I know this is nonsense in the final program), then I take the time using <code>time.time()</code> again and output the difference.</p>
  
  <p>I observed that the chunk size of <code>n // processes + 1</code> results in times of around <strong>0.425 ms</strong> per object. But I also observed that the CPU is only fully loaded the first half of the process, in the end the usage goes down to 25% (on an i3 with 2 cores and hyper-threading).</p>
  
  <p>If I use a smaller chunk size of <code>int(l // (processes**2) + 1)</code> instead, I get times of around <strong>0.355 ms</strong> instead and the CPU load is much better distributed. It just has some small spikes down to ca. 75%, but stays high for much longer part of the process time before it goes down to 25%.</p>
  
  <p>Is there an even better formula to calculate the chunk size or a otherwise better method to use the CPU most effective? Please help me to improve this multiprocessing pool's effectiveness.</p>