gpars - the coolest bits
Post on 12-Jul-2015
107 Views
Preview:
TRANSCRIPT
The coolest bits
Why bother!?
GParsGroovy Parallel Systems- multiple high-level parallelism abstractions- Java-usable- GAE-usable- part of Groovy SDK- open source (Apache 2 License)- Grooovy documentation
GParsGroovy Parallel Systems
Team: Václav Pech, Dierk König, Russel Winder,Alex Tkachman, Paul King, Jon Kerridge,Rafał Sławik and others
One Ring to rule them all...Parallelism approach in GPars (originally?) found in implemented using
Parallel collections Scala, Java jsr-166y / JDK5 executors
jsr-166y Fork/Join (sugar) Java jsr-166y
Actors Erlang, Scala java.util.concurrent
Software Transactional Memory Clojure, Scala Multiverse
Agents Clojure java.util.concurrent
CSP CSP :) Dataflow* or JCSP
Dataflow and extensions:Pipelines, Kanbanflow
Linda, Verilog, Agilent Vee, Scala, Unreal Engine
jsr-166y / JDK5 executors (?)
Composable asynchronous functions ? jsr-166y / JDK5 executors
Our focusParallelism approach in GPars (originally?) found in implemented using
Parallel collections Scala, Java jsr-166y / JDK5 executors
jsr-166y Fork/Join (sugar) Java jsr-166y
Actors Erlang, Scala java.util.concurrent
Software Transactional Memory Clojure, Scala Multiverse
Agents Clojure java.util.concurrent
CSP CSP :) Dataflow* or JCSP
Dataflow and extensions:Pipelines, Kanbanflow
Linda, Verilog, Agilent Vee, Scala, Unreal Engine
jsr-166y / JDK5 executors (?)
Composable asynchronous functions ? jsr-166y / JDK5 executors
Demo time!Enabling GPars GDSL in Intellij IDEA
Demo time!Parallel collections- withPool / enhancer- makeConcurrent / makeSequential /
asParallel- GParsPool + ParallelEnhancer /
GParsExecutorsPool + GParsExecutorsPoolEnhancer
- Map-Reduce (Fork / Join pool only)
Things to consider / a warning...
In this approach, your iteration body must be:- stateless- side-effect free- constrained to the current elementElse - welcome to concurrency hell...
Demo time!Agents- updating immutable / mutable- syntax equivalents for .send- copy method- parallel behaviour- error handling- parallel groups, daemon threads & shutting
down
Agents - what else is there- listeners- validators & validation gotchas- non-closure sends- prefer composition over inheritance- sendAndAwait
Agents - Q & AQuestions?- what if I want to check a condition
before updating state?- how do I 'lock' the state?
Composable Asynchronous Functions- @AsyncFun / asyncFun()- async funs return DataflowVariable-s- blocking @AsyncFun-s for convenience- rest of the docs: instantiation variants,
pool configuration
Demo time!
Bonus: on parallelism flavours
Choosing an approachTask parallelism
Independent Async closures, Futures, whatever...
Dependent Random / Unknown Dataflow
Functional / Linear Composable asynchronous functions, Dataflow tasks, CSP
Hierarchical / Recursive Fork / Join
Shared state Agents, STM
Choosing an approachData parallelism
Geometrical / Linear Parallel collections
Hierarchical / Recursive Fork / Join
Streamed (regular) Pipeline DSL, Dataflow, CSP
Event-driven (irregular) Actors
From GPARS User Guide
TL;DRParallel collectionsAsync functionsDataflowAgentsMessage passing - CSP - Dataflow - Actors
Also: Bashing actors a little :)
Actors are overratedDierk König
Also: Bashing actors a little :)Why there were no Actors in Clojure*● complex● no efficient sharing even for immutable structures● reduce flexibility● do not really distribute well from single to many
machines
* a purposefully exaggerating summary by me
Slides since Morpheus based on● Václav Pech - GPars How To Guide● Paul King - Concurrency with GPars● GPars User Guide - Applicability of concepts● GPars docs - Concepts compared● Dierk König - Concurrent programming for you and me● my personal biases :)
Recap- GPars is quite a lib :)- Be sure to try Dataflows- Actors are overrated ;)
Questions?
Thank you!
top related