Regression (b88): OOM on parallel limit operation
Paul Sandoz
paul.sandoz at oracle.com
Fri May 10 10:03:17 PDT 2013
On May 10, 2013, at 11:15 AM, Paul Sandoz <Paul.Sandoz at oracle.com> wrote:
>
> On May 9, 2013, at 10:57 AM, "Mallwitz, Christian" <christian.mallwitz at commerzbank.com> wrote:
>
>> Hi,
>>
>> Re-reporting problem for build 88: the limit() on the third examples bombs out with an immediate OOM.
>>
>
> Thanks!
>
> Since the current implementation of limit is a full barrier (until the limit is known to have been reached) the heap size is too small:
>
> $ java -XX:+PrintCommandLineFlags OOM
> -XX:ClassMetaspaceSize=104857600 -XX:InitialHeapSize=134217728 -XX:MaxHeapSize=2147483648 -XX:+PrintCommandLineFlags -XX:+UseCompressedKlassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
> 200000
> 100000
> 200000
>
> However, i can reproduce if i increase the limit sizes by a factor.
>
> Note that we are still working on fixing this area, there are various optimizations for various stream characteristics we can apply. For example, when the stream is sized, or when the stream is unordered.
>
> The case with Stream.iterator().limit() is the worst possible case, an infinite (unknown sized) and ordered stream.
>
> I think we need to change the implementation so it is no longer a full barrier and instead is a wrapping slice/limit spliterator that peels off left splits as arrays (same trick we do for creating a spliterator from an iterator).
>
I chatted with Brian about this and the solution i proposed is gonna fail for cases such as:
unknownSizedAndOrderedStream.filter(veryExpensiveFilter).limit(...)
Unfortunately we don't know the cost of operations (Q).
Because of the filter 100x elements are buffered and ~200 F/J leaf tasks will created.
There is no getting around the potential for OOME in these cases. It is up to us to provide clear documentation on when/where to use limit correctly.
Having said that i think we need to do some careful analysis to see if we can improve the threshold when an OOME occurs. I have already found one possible tweak to get 90% of the way there, on my 4 core mac book pro, before hitting an OOME, which is better than 50% before that tweak :-)
Paul.
More information about the lambda-dev
mailing list