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

Christian Fries email at christian-fries.de
Tue May 6 04:34:44 EDT 2014


Dear Russel.

I see that too. Please also check my previous post and this code: http://svn.finmath.net/finmath%20experiments/trunk/src/net/finmath/experiments/concurrency/NestedParallelForEachTest.java

I can show you the line in the implementation of the ForkJoinTask that is responsible for this. It is this one:
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/6be37bafb11a/src/share/classes/java/util/concurrent/ForkJoinTask.java#l386
This test if fine for any non-nested loop. For a nested loop the test is wrong and results in an awaitJoin called on a different workQueue (which then either results in a performance issue or in a deadlock).

Best
Christian

Am 06.05.2014 um 10:12 schrieb Russel Winder <russel at winder.org.uk>:

> On Tue, 2014-05-06 at 00:50 +0400, Aleksey Shipilev wrote:
> […]
>> To my knowledge of FJP mechanics, this should work perfectly well, since
>> submitters from the external loop will participate in the computation
>> and making progress. My throw-away tests, like:
>> 
>>    @GenerateMicroBenchmark
>>    public void test(BlackHole bh) {
>>        IntStream.range(0, TASKS).parallel().forEach(i -> {
>>            IntStream.range(0, TASKS).parallel().forEach(j -> {
>>                bh.consume(i + j);
>>            });
>>        });
>>    }
>> 
>> ...do not manage to deadlock.
> […]
> 
> I am finding that whilst nested streams code works, it seems to have
> dreadful performance. I need to do more work, and get proper benchmark
> data, before making an serious claim on this, for now it is just an
> anecdotal indicator. 
> -- 
> Russel.
> =============================================================================
> Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
> 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
> London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140506/c3594eab/attachment.html>


More information about the Concurrency-interest mailing list