SlideShare a Scribd company logo
1 of 45
Download to read offline
ForkJoinPools
&
parallel streams
… are useless?
Agenda
● Motivation
● History
● Big Picture
● ForkJoinPool
● Parallel streams
● Advises
● Alternatives
:(){ :|:& };:
Motivation
why?
Motivation
Think Twice Before Using Java 8 Parallel Streams - DZone Java
https://dzone.com/articles/think-twice-using-java-8
Java Parallel Streams Can Unexpectedly Degrade Performance ...
https://zeroturnaround.com/.../java-parallel-streams-are-bad-for-your-...
A Java Parallel Calamity - Cooperative Software Systems, Inc
coopsoft.com/ar/Calamity2Article.html
A Java Fork-Join Calamity - Cooperative Software Systems, Inc
coopsoft.com/ar/CalamityArticle.html
What's Wrong in Java 8, Part III: Streams and Parallel Streams - DZone ...
https://dzone.com/articles/whats-wrong-java-8-part-iii
...
History
History
2000 2006
JDK 6
2011 2014
JDK 7 JDK 8
...
JDK 9
extension fork-join parallel Files.lines()
Big Picture
Big Picture
ForkJoinPool
Recursive Task Decomposition
fork fork
fork fork fork fork
join join join join
join join
main
w
steal
w
Anatomy
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
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
The Common Pool
The Common Pool
boot CL
Extension CL
System CL
I’m a singleton!
URL CL#1 URL CL#1
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
Parallel Streams
CPU4
CPU3
CPU2
CPU1
stream()Collection parallel()
map()
map()
map()
map()
filter()
filter()
filter()
filter()
reduce()
Parallel Minimum Search
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
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
Performance Considerations
● Collection size
● Splitting efficiency
○ Arrays / ArrayLists
○ HashMaps/HashSets
○ LinkedLists
○ BlockingQueues
● Operation efficiency
○ Dependencies
○ Statelessnes
CPU4
CPU3
CPU2
CPU1
Executive Summary
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?
Holy Hack
How to start parallel stream using custom
ForkJoinPool?
Holy Hack II
Using CompletableFutute
Advises
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!
Bulkheads
Service
Data
Access
Gateway
Using Bulkheads
incoming requests pool #2
pool #3
pool #1
Alternatives
Alternatives
● Reactor Core - http://projectreactor.io/
● Akka - http://akka.io/
● Reactive Streams - http://www.reactive-streams.org/
● Speedment Java Stream ORM - https://github.com/speedment/speedment
● Quasar - https://github.com/puniverse/quasar
Thanks!
References
● GitHub examples & presentation
○ https://github.com/gitaroktato/forkjoinpools-and-parallelstreams
● HTTP Async calls in REST
○ https://jersey.java.net/documentation/latest/async.html
○ http://allegro.tech/2014/10/async-rest.html
● Presentations discussing Java 8 ‘s parallel & asynchronous capabilities
○ https://www.youtube.com/watch?v=fabN6HNZ2qY
○ https://www.youtube.com/watch?v=h1N-qbo5VyY
○ https://www.youtube.com/watch?v=HdnHmbFg_hw
● Talks with the authors of parallel computation in Java 8
○ https://www.infoq.com/interviews/doug-lea-fork-join
○ https://www.infoq.com/presentations/parallel-java-se-8
References II
● Shortest path algorithm parallelization in graphs
○ http://www.mcs.anl.gov/~itf/dbpp/text/node35.html
○ http://www.cslab.ntua.gr/courses/pps/files/fall2011/paper_sfhmmy.pdf
● Original Fork-Join whitepaper
○ http://gee.cs.oswego.edu/dl/papers/fj.pdf
● ForkJoinPool explanations
○ http://www.h-online.com/developer/features/The-fork-join-framework-in-Java-7-1762357.html
○ http://howtodoinjava.com/java-7/forkjoin-framework-tutorial-forkjoinpool-example/
○ http://www.oracle.com/technetwork/articles/java/fork-join-422606.html
○ http://www.javaworld.com/article/2078440/enterprise-java/java-tip-when-to-use-forkjoinpool
-vs-executorservice.html
References III
● Parallel stream explanations
○ https://blog.oio.de/2016/01/22/parallel-stream-processing-in-java-8-performance-of-sequentia
l-vs-parallel-stream-processing/
○ http://www.drdobbs.com/jvm/parallel-array-operations-in-java-8/240166287?pgno=2
● Files.lines().parallel() issue in Java 8
○ http://bytefish.de/blog/jdk8_files_lines_parallel_stream/

More Related Content

What's hot

Using Flame Graphs
Using Flame GraphsUsing Flame Graphs
Using Flame GraphsIsuru Perera
 
Analyzing Java Applications Using Thermostat (Omair Majid)
Analyzing Java Applications Using Thermostat (Omair Majid)Analyzing Java Applications Using Thermostat (Omair Majid)
Analyzing Java Applications Using Thermostat (Omair Majid)Red Hat Developers
 
ruby test-all parallel running
ruby test-all parallel runningruby test-all parallel running
ruby test-all parallel runningShota Fukumori
 
Using Java Mission Control & Java Flight Recorder
Using Java Mission Control & Java Flight RecorderUsing Java Mission Control & Java Flight Recorder
Using Java Mission Control & Java Flight RecorderIsuru Perera
 
Performance tests with gatling
Performance tests with gatlingPerformance tests with gatling
Performance tests with gatlingSoftwareMill
 
Puppet managed loadays
Puppet managed loadaysPuppet managed loadays
Puppet managed loadaysYankee Nemoy
 
Pg chameleon, mysql to postgresql replica made easy
Pg chameleon, mysql to postgresql replica made easyPg chameleon, mysql to postgresql replica made easy
Pg chameleon, mysql to postgresql replica made easyFederico Campoli
 
Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012slandelle
 
Apache cTAKES- NLP in Healthcare
Apache cTAKES- NLP in HealthcareApache cTAKES- NLP in Healthcare
Apache cTAKES- NLP in HealthcareAlexandru Zbarcea
 
Java Performance and Using Java Flight Recorder
Java Performance and Using Java Flight RecorderJava Performance and Using Java Flight Recorder
Java Performance and Using Java Flight RecorderIsuru Perera
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongPROIDEA
 

What's hot (19)

Using Flame Graphs
Using Flame GraphsUsing Flame Graphs
Using Flame Graphs
 
Java JVM
Java JVMJava JVM
Java JVM
 
Analyzing Java Applications Using Thermostat (Omair Majid)
Analyzing Java Applications Using Thermostat (Omair Majid)Analyzing Java Applications Using Thermostat (Omair Majid)
Analyzing Java Applications Using Thermostat (Omair Majid)
 
Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016
 
ruby test-all parallel running
ruby test-all parallel runningruby test-all parallel running
ruby test-all parallel running
 
Using Java Mission Control & Java Flight Recorder
Using Java Mission Control & Java Flight RecorderUsing Java Mission Control & Java Flight Recorder
Using Java Mission Control & Java Flight Recorder
 
Performance tests with gatling
Performance tests with gatlingPerformance tests with gatling
Performance tests with gatling
 
Puppet managed loadays
Puppet managed loadaysPuppet managed loadays
Puppet managed loadays
 
Pg chameleon, mysql to postgresql replica made easy
Pg chameleon, mysql to postgresql replica made easyPg chameleon, mysql to postgresql replica made easy
Pg chameleon, mysql to postgresql replica made easy
 
Zk meetup talk
Zk meetup talkZk meetup talk
Zk meetup talk
 
Java in flames
Java in flamesJava in flames
Java in flames
 
What's new in Java 11
What's new in Java 11What's new in Java 11
What's new in Java 11
 
Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012Gatling Tool in Action at Devoxx 2012
Gatling Tool in Action at Devoxx 2012
 
JVM
JVMJVM
JVM
 
Apache cTAKES- NLP in Healthcare
Apache cTAKES- NLP in HealthcareApache cTAKES- NLP in Healthcare
Apache cTAKES- NLP in Healthcare
 
Java Performance and Using Java Flight Recorder
Java Performance and Using Java Flight RecorderJava Performance and Using Java Flight Recorder
Java Performance and Using Java Flight Recorder
 
Tools for static analyses of Java af Hans Søndergaard, ViaUC
Tools for static analyses of Java af Hans Søndergaard, ViaUCTools for static analyses of Java af Hans Søndergaard, ViaUC
Tools for static analyses of Java af Hans Søndergaard, ViaUC
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
 
Java basics mind map
Java basics mind mapJava basics mind map
Java basics mind map
 

Similar to ForkJoinPools and parallel streams

Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfjexp
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Ramith Jayasinghe
 
Introduction to ZooKeeper - TriHUG May 22, 2012
Introduction to ZooKeeper - TriHUG May 22, 2012Introduction to ZooKeeper - TriHUG May 22, 2012
Introduction to ZooKeeper - TriHUG May 22, 2012mumrah
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel StreamTengwen Wang
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK toolsHaribabu Nandyal Padmanaban
 
Performance tuning Grails Applications GR8Conf US 2014
Performance tuning Grails Applications GR8Conf US 2014Performance tuning Grails Applications GR8Conf US 2014
Performance tuning Grails Applications GR8Conf US 2014Lari Hotari
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9Gal Marder
 
Load testing in Zonky with Gatling
Load testing in Zonky with GatlingLoad testing in Zonky with Gatling
Load testing in Zonky with GatlingPetr Vlček
 
Reactive programming with Rxjava
Reactive programming with RxjavaReactive programming with Rxjava
Reactive programming with RxjavaChristophe Marchal
 
Java features. Java 8, 9, 10, 11
Java features. Java 8, 9, 10, 11Java features. Java 8, 9, 10, 11
Java features. Java 8, 9, 10, 11Ivelin Yanev
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang YoonJesang Yoon
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8Heartin Jacob
 
LCE13: Test and Validation Summit: The future of testing at Linaro
LCE13: Test and Validation Summit: The future of testing at LinaroLCE13: Test and Validation Summit: The future of testing at Linaro
LCE13: Test and Validation Summit: The future of testing at LinaroLinaro
 
LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...
LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...
LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...Linaro
 
Optimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardwareOptimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardwareIndicThreads
 

Similar to ForkJoinPools and parallel streams (20)

Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
 
Why Concurrency is hard ?
Why Concurrency is hard ?Why Concurrency is hard ?
Why Concurrency is hard ?
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Concurrency - Why it's hard ?
Concurrency - Why it's hard ?
 
Java under the hood
Java under the hoodJava under the hood
Java under the hood
 
Introduction to ZooKeeper - TriHUG May 22, 2012
Introduction to ZooKeeper - TriHUG May 22, 2012Introduction to ZooKeeper - TriHUG May 22, 2012
Introduction to ZooKeeper - TriHUG May 22, 2012
 
JAVA 8 Parallel Stream
JAVA 8 Parallel StreamJAVA 8 Parallel Stream
JAVA 8 Parallel Stream
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Performance tuning Grails Applications GR8Conf US 2014
Performance tuning Grails Applications GR8Conf US 2014Performance tuning Grails Applications GR8Conf US 2014
Performance tuning Grails Applications GR8Conf US 2014
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
Load testing in Zonky with Gatling
Load testing in Zonky with GatlingLoad testing in Zonky with Gatling
Load testing in Zonky with Gatling
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Reactive programming with Rxjava
Reactive programming with RxjavaReactive programming with Rxjava
Reactive programming with Rxjava
 
Java features. Java 8, 9, 10, 11
Java features. Java 8, 9, 10, 11Java features. Java 8, 9, 10, 11
Java features. Java 8, 9, 10, 11
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
LCE13: Test and Validation Summit: The future of testing at Linaro
LCE13: Test and Validation Summit: The future of testing at LinaroLCE13: Test and Validation Summit: The future of testing at Linaro
LCE13: Test and Validation Summit: The future of testing at Linaro
 
LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...
LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...
LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...
 
Optimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardwareOptimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardware
 

More from Oresztész Margaritisz

More from Oresztész Margaritisz (7)

Overview of health-check patterns
Overview of health-check patternsOverview of health-check patterns
Overview of health-check patterns
 
Being agile with modern Java
Being agile with modern JavaBeing agile with modern Java
Being agile with modern Java
 
How to make technical deicisons?
How to make technical deicisons?How to make technical deicisons?
How to make technical deicisons?
 
Cassandra On EPAM Cloud - VDAY 2017
Cassandra On EPAM Cloud - VDAY 2017Cassandra On EPAM Cloud - VDAY 2017
Cassandra On EPAM Cloud - VDAY 2017
 
Asynchronous programming using CompletableFutures in Java
Asynchronous programming using CompletableFutures in JavaAsynchronous programming using CompletableFutures in Java
Asynchronous programming using CompletableFutures in Java
 
Cassandra on EPAM Cloud
Cassandra on EPAM CloudCassandra on EPAM Cloud
Cassandra on EPAM Cloud
 
Introduction to DC/OS
Introduction to DC/OSIntroduction to DC/OS
Introduction to DC/OS
 

Recently uploaded

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 

Recently uploaded (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

ForkJoinPools and parallel streams

  • 2. Agenda ● Motivation ● History ● Big Picture ● ForkJoinPool ● Parallel streams ● Advises ● Alternatives
  • 5. Motivation Think Twice Before Using Java 8 Parallel Streams - DZone Java https://dzone.com/articles/think-twice-using-java-8 Java Parallel Streams Can Unexpectedly Degrade Performance ... https://zeroturnaround.com/.../java-parallel-streams-are-bad-for-your-... A Java Parallel Calamity - Cooperative Software Systems, Inc coopsoft.com/ar/Calamity2Article.html A Java Fork-Join Calamity - Cooperative Software Systems, Inc coopsoft.com/ar/CalamityArticle.html What's Wrong in Java 8, Part III: Streams and Parallel Streams - DZone ... https://dzone.com/articles/whats-wrong-java-8-part-iii ...
  • 7. History 2000 2006 JDK 6 2011 2014 JDK 7 JDK 8 ... JDK 9 extension fork-join parallel Files.lines()
  • 10.
  • 11.
  • 12.
  • 14. Recursive Task Decomposition fork fork fork fork fork fork join join join join join join
  • 15.
  • 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
  • 28. Performance Considerations ● Collection size ● Splitting efficiency ○ Arrays / ArrayLists ○ HashMaps/HashSets ○ LinkedLists ○ BlockingQueues ● Operation efficiency ○ Dependencies ○ Statelessnes 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?
  • 32.
  • 33.
  • 34. Holy Hack II Using CompletableFutute
  • 35.
  • 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!
  • 41. Alternatives ● Reactor Core - http://projectreactor.io/ ● Akka - http://akka.io/ ● Reactive Streams - http://www.reactive-streams.org/ ● Speedment Java Stream ORM - https://github.com/speedment/speedment ● Quasar - https://github.com/puniverse/quasar
  • 43. References ● GitHub examples & presentation ○ https://github.com/gitaroktato/forkjoinpools-and-parallelstreams ● HTTP Async calls in REST ○ https://jersey.java.net/documentation/latest/async.html ○ http://allegro.tech/2014/10/async-rest.html ● Presentations discussing Java 8 ‘s parallel & asynchronous capabilities ○ https://www.youtube.com/watch?v=fabN6HNZ2qY ○ https://www.youtube.com/watch?v=h1N-qbo5VyY ○ https://www.youtube.com/watch?v=HdnHmbFg_hw ● Talks with the authors of parallel computation in Java 8 ○ https://www.infoq.com/interviews/doug-lea-fork-join ○ https://www.infoq.com/presentations/parallel-java-se-8
  • 44. References II ● Shortest path algorithm parallelization in graphs ○ http://www.mcs.anl.gov/~itf/dbpp/text/node35.html ○ http://www.cslab.ntua.gr/courses/pps/files/fall2011/paper_sfhmmy.pdf ● Original Fork-Join whitepaper ○ http://gee.cs.oswego.edu/dl/papers/fj.pdf ● ForkJoinPool explanations ○ http://www.h-online.com/developer/features/The-fork-join-framework-in-Java-7-1762357.html ○ http://howtodoinjava.com/java-7/forkjoin-framework-tutorial-forkjoinpool-example/ ○ http://www.oracle.com/technetwork/articles/java/fork-join-422606.html ○ http://www.javaworld.com/article/2078440/enterprise-java/java-tip-when-to-use-forkjoinpool -vs-executorservice.html
  • 45. References III ● Parallel stream explanations ○ https://blog.oio.de/2016/01/22/parallel-stream-processing-in-java-8-performance-of-sequentia l-vs-parallel-stream-processing/ ○ http://www.drdobbs.com/jvm/parallel-array-operations-in-java-8/240166287?pgno=2 ● Files.lines().parallel() issue in Java 8 ○ http://bytefish.de/blog/jdk8_files_lines_parallel_stream/