17. Pros & Cons
Pros
● No blocked wait on join()
● Lower latency in case of multiple jobs
● API for task decomposition and parallel
computation
● Load-balancing mechanism
● Local submission queues may improve CPU
caching
18. Pros & Cons
Cons
● Workers are usual java.lang.Thread
extensions
● Computation overhead from stealing
mechanism (spinlock)
● Warm-up has some overhead
● Hard to tune the computation. (Task
decomposition granularity)
● Can be slower than sequential computing
● Can be memory intensive
● API has some flaws
● No JMX
● Cryptic source code
20. The Common Pool
boot CL
Extension CL
System CL
I’m a singleton!
URL CL#1 URL CL#1
21.
22. Pros & Cons
Cons
● No multitenancy
● main thread joins the workers
● Error prone
● Computation may stall
● We can’t use operations that are waiting for
resources
○ I/O
○ Shared memory access
○ Network wait
26. Pros & Cons
Pros
● Ease of use
● Functional interface
● Easy to parallelize an existing method
● Lots of ready-made operations in Java 8
CPU4
CPU3
CPU2
CPU1
27. Pros & Cons
Cons
● Uses common fork-join pool!
○ One slow operation affects others
● Computation can be invalid as ordering is
not guaranteed
● Can be slower, than sequential stream
CPU4
CPU3
CPU2
CPU1
30. Executive Summary
● All parallel steam uses common pool
● One pool per JVM
● One slow operation can block all others
● Waiting for resources (IO/Network/Lock) is slow
● Even there’s no JMX
● What can I do?
31. Holy Hack
How to start parallel stream using custom
ForkJoinPool?
37. Advises
● Avoid using the common pool
○ Check every library for parallel() calls
○ Check common-pool thread usage in test environment
● Try to automate testing of parallel operations
● Performance test with sequential and parallel streams
○ Use different collection sizes
○ Take number of CPUs into account
● Use CompletableFuture, which has an Executor argument
○ Try out various executors, but be aware of what you’re doing!