[concurrency-interest] ForkJoinPool not designed for nested Java 8 streams.parallel().forEach( ... )

Paul Sandoz paul.sandoz at oracle.com
Tue May 6 10:44:54 EDT 2014


On May 6, 2014, at 3:01 PM, Christian Fries <email at christian-fries.de> wrote:

> Hi Paul.
> Oh. I expected that it would be countered that „Thread.sleep()“ is not be a legitimate test case… ;-)

:-) I think what you have now with CPU burning is more relevant and also different from where you started. Have you tried writing a jmh benchmark instead? i would recommend doing so if you want to further explore the performance characteristics.

> I have update my demo and now I use a stupid for-loop summing up some cosine to burn real CPU time. The result is
> Nested stream forEach: outer parallel, inner sequential:	34 sec
> Nested stream forEach: outer parallel, inner parallel:		63 sec

That is not too surprising, to me at least, from my previous experience and esp. what Doug said about nested parallelism.

> In the first case my 8-core CPU ist working at 800% all the time. In the second case you can clearly see that its almost idle at certain times.
> You find my updated test case here:
> http://svn.finmath.net/finmath%20experiments/trunk/src/net/finmath/experiments/concurrency/NestedParallelForEachTest.java
> If you like to not use Thread.sleep() set isCPUTimeBurned to true - you might need to calibrate that count used in the loop.

FWIW you can do: 

                    ForkJoinPool.managedBlock(blocker(() -> {
                        // Inner loop as parallel: worst case (sequential) it takes 10 * numberOfTasksInInnerLoop millis
                        IntStream.range(0,numberOfTasksInInnerLoop).parallel().forEach(j -> {

which enables work to balance out a bit more, but could be regarded as somewhat of an abuse.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140506/d6edba43/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140506/d6edba43/attachment.bin>

More information about the Concurrency-interest mailing list