title: Work-stealing parallel job doesn't seem to steal much work
body: <p>The idea is to run a parallel job on a 96-cores machine, with a work stealing <code>ForkJoinPool</code>.</p>
  
  <p>Below is the code I'm using so far:</p>
  
  <pre><code>import scala.collection.parallel.ForkJoinTaskSupport
  import scala.concurrent.forkjoin.ForkJoinPool
  
  val sequence: ParSeq[Item] = getItems().par
  sequence.tasksupport = new ForkJoinTaskSupport(new ForkJoinPool())
  val results = for {
    item &lt;- sequence
    res   = doSomethingWith(item)
  } yield res
  </code></pre>
  
  <p>Here, <code>sequence</code> has about 20,000 items. Most items take 2-8 seconds to process, and only about 200 of them take longer, around 40 seconds.</p>
  
  <p><strong>The problem:</strong></p>
  
  <p>Everything runs fine, however, the work-stealing aspect doesn't seem to work well. Here are the expected total CPU load (black) compared to the actual load (blue) over time:</p>
  
  <p><a href="https://i.stack.imgur.com/jCnis.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jCnis.png" alt="Expected vs Actual work loads"></a></p>
  
  <p>When looking at the CPU activity, it's very clear that less and less cores get used as the job is progressing towards the end. During the last 10 few minutes, only 2 or 3 cores are still busy processing dozens of items sequentially, one after the other.</p>
  
  <p>How comes that the items still in the queue don't get stolen by the other free cores, even when using a <code>ForkJoinPool</code>, which is supposed to be work-stealing?</p>
  
  <p><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html" rel="nofollow noreferrer">https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html</a></p>