SlideShare a Scribd company logo
Submit Search
Upload
Login
Signup
GPars howto - when to use which concurrency abstraction
Report
Vaclav Pech
Follow
A passionate programmer
May. 23, 2013
•
0 likes
•
2,138 views
1
of
48
GPars howto - when to use which concurrency abstraction
May. 23, 2013
•
0 likes
•
2,138 views
Download Now
Download to read offline
Report
Technology
Vaclav Pech
Follow
A passionate programmer
Recommended
Pick up the low-hanging concurrency fruit
Vaclav Pech
869 views
•
34 slides
Concurrency on the JVM
Vaclav Pech
1.4K views
•
43 slides
Gpars workshop
Vaclav Pech
1.2K views
•
54 slides
Reason and GraphQL
Nikolaus Graf
214 views
•
46 slides
Luis Atencio on RxJS
Luis Atencio
1.3K views
•
60 slides
Cascadia.js: Don't Cross the Streams
mattpodwysocki
36.8K views
•
35 slides
More Related Content
What's hot
Thinking Functionally with JavaScript
Luis Atencio
1.3K views
•
62 slides
Poor Man's Functional Programming
Dmitry Buzdin
3.3K views
•
26 slides
Refactoring to Macros with Clojure
Dmitry Buzdin
3.5K views
•
51 slides
C# console programms
Yasir Khan
10.4K views
•
12 slides
Vasia Kalavri – Training: Gelly School
Flink Forward
7.1K views
•
20 slides
C# labprograms
Jafar Nesargi
4.1K views
•
35 slides
What's hot
(20)
Thinking Functionally with JavaScript
Luis Atencio
•
1.3K views
Poor Man's Functional Programming
Dmitry Buzdin
•
3.3K views
Refactoring to Macros with Clojure
Dmitry Buzdin
•
3.5K views
C# console programms
Yasir Khan
•
10.4K views
Vasia Kalavri – Training: Gelly School
Flink Forward
•
7.1K views
C# labprograms
Jafar Nesargi
•
4.1K views
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Ontico
•
349 views
Lab 1
rimshailyas1
•
44 views
Rxjs ppt
Christoffer Noring
•
3.6K views
Connect S3 with Kafka using Akka Streams
Seiya Mizuno
•
1.6K views
Pattern printing programs
Mukesh Tekwani
•
13.4K views
My Gentle Introduction to RxJS
Mattia Occhiuto
•
651 views
Flink Batch Processing and Iterations
Sameer Wadkar
•
3.5K views
Using akka streams to access s3 objects
Mikhail Girkin
•
1.3K views
Data structure (2nd semester)
Ketan Rajpal
•
195 views
SeaJUG March 2004 - Groovy
Ted Leung
•
591 views
RxJS - The Reactive extensions for JavaScript
Viliam Elischer
•
912 views
Python in the database
pybcn
•
2.2K views
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
•
142 views
Is java8 a true functional programming language
SQLI
•
911 views
Similar to GPars howto - when to use which concurrency abstraction
Higher Order Components and Render Props
Nitish Phanse
298 views
•
94 slides
Machine-level Composition of Modularized Crosscutting Concerns
saintiss
279 views
•
36 slides
jQuery for beginners
Divakar Gu
594 views
•
33 slides
Transition graph using free monads and existentials
Alexander Granin
471 views
•
51 slides
Rx workshop
Ryan Riley
2.4K views
•
108 slides
Java 8 lambda expressions
Logan Chien
2.6K views
•
66 slides
Similar to GPars howto - when to use which concurrency abstraction
(20)
Higher Order Components and Render Props
Nitish Phanse
•
298 views
Machine-level Composition of Modularized Crosscutting Concerns
saintiss
•
279 views
jQuery for beginners
Divakar Gu
•
594 views
Transition graph using free monads and existentials
Alexander Granin
•
471 views
Rx workshop
Ryan Riley
•
2.4K views
Java 8 lambda expressions
Logan Chien
•
2.6K views
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
•
128 views
Reactive programming every day
Vadym Khondar
•
463 views
Road to react hooks
Younes (omar) Meliani
•
156 views
Functional Programming with Javascript
Deepankar Chopra
•
67 views
Avoiding Callback Hell with Async.js
cacois
•
21.4K views
Things about Functional JavaScript
ChengHui Weng
•
324 views
ppt - Deep Learning From Scratch.pdf
surefooted
•
1 view
TI1220 Lecture 6: First-class Functions
Eelco Visser
•
1.1K views
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
Big Data Spain
•
1.6K views
Functional Programming
Yuan Wang
•
606 views
Reactive programming on Android
Tomáš Kypta
•
7.5K views
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
Data Con LA
•
456 views
React 101
Casear Chu
•
917 views
1. George Shevtsov - Functional JavaScript
Innovecs
•
330 views
More from Vaclav Pech
Domain Specific Language with pleasure
Vaclav Pech
1.5K views
•
44 slides
Concepts of JetBrains MPS
Vaclav Pech
2.3K views
•
63 slides
Advanced IDE functionality in modern language workbenches
Vaclav Pech
795 views
•
42 slides
Get 'em before they get You
Vaclav Pech
522 views
•
19 slides
Gpars concepts explained
Vaclav Pech
2.5K views
•
44 slides
Groovy in IntelliJ IDEA
Vaclav Pech
1.1K views
•
7 slides
More from Vaclav Pech
(8)
Domain Specific Language with pleasure
Vaclav Pech
•
1.5K views
Concepts of JetBrains MPS
Vaclav Pech
•
2.3K views
Advanced IDE functionality in modern language workbenches
Vaclav Pech
•
795 views
Get 'em before they get You
Vaclav Pech
•
522 views
Gpars concepts explained
Vaclav Pech
•
2.5K views
Groovy in IntelliJ IDEA
Vaclav Pech
•
1.1K views
Groovy Intro
Vaclav Pech
•
760 views
Team City
Vaclav Pech
•
4K views
Recently uploaded
TEKART CON 2023
AdedoyinSamuel1
20 views
•
35 slides
Roottoo Innovation V24_CP.pdf
roottooinnovation
22 views
•
13 slides
The Rise of the Machines: How AI will shape our lives in 2024
Iain Martin
41 views
•
49 slides
Inclusivity and AI: opportunity or threat
Alan Dix
34 views
•
37 slides
AMAZON-RESUME.pdf
RegineRaneses
38 views
•
1 slide
Document Understanding as Cloud APIs and Generative AI Pre-labeling Extractio...
DianaGray10
74 views
•
11 slides
Recently uploaded
(20)
TEKART CON 2023
AdedoyinSamuel1
•
20 views
Roottoo Innovation V24_CP.pdf
roottooinnovation
•
22 views
The Rise of the Machines: How AI will shape our lives in 2024
Iain Martin
•
41 views
Inclusivity and AI: opportunity or threat
Alan Dix
•
34 views
AMAZON-RESUME.pdf
RegineRaneses
•
38 views
Document Understanding as Cloud APIs and Generative AI Pre-labeling Extractio...
DianaGray10
•
74 views
Improve Employee Experiences on Cisco RoomOS Devices, Webex, and Microsoft Te...
ThousandEyes
•
89 views
Microsoft Azure New - Sep 2023
Daniel Toomey
•
32 views
Announcing InfluxDB Clustered
InfluxData
•
47 views
Easy Salesforce CI/CD with Open Source Only - Dreamforce 23
NicolasVuillamy1
•
100 views
Scaling out with WordPress
Konstantin Kovshenin
•
50 views
Swiss Re Reinsurance Solutions - Automated Claims Experience – Insurer Innova...
The Digital Insurer
•
26 views
Regulating Generative AI - LLMOps pipelines with Transparency
Debmalya Biswas
•
42 views
Fipto Seed Pitch Deck
sjcobrien
•
36 views
MapInfo Pro v2023: The Next Dimension in Spatial Analytics
Precisely
•
38 views
Jino Clone: Develop a Car Wash Mobile App with Limited Resources
eSiteWorld TechnoLabs Pvt. Ltd.
•
28 views
Knowledge graph use cases in natural language generation
Elena Simperl
•
82 views
Die ultimative Anleitung für HCL Nomad Web Administratoren
panagenda
•
53 views
who we are - values.pptx
LauraGarceran
•
30 views
The Ultimate Administrator’s Guide to HCL Nomad Web
panagenda
•
45 views
GPars howto - when to use which concurrency abstraction
1.
GPars 'coz concurrency is
Groovy Václav Pech
2.
Asynchronous calculations Fork/Join Parallel collections Actors Agents,
Stm Dataflow CSP Why this talk?
3.
Structure Parallelism Task Data Random Independent Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared
state
4.
Structure Parallelism Task Data Random Independent Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared
state
5.
Parallelism Task parallelism Task Data Random Independent
Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared state
6.
Asynchronous invocation Future f
= threadPool.submit(calculation); … System.out.println(“Result: “ + f.get());
7.
Async the Groovy
way task { calculation.process() }
8.
Async the Groovy
way def group = new NonDaemonPGroup(10) group.task { calculation.process() }
9.
group.task {->…} group.task new
Runnable() {…} group.task new Callable<V>() {...} Async the Groovy way
10.
Independent tasks def group
= new NonDaemonPGroup(10) submissions.each {form → group.task { form.process() } }
11.
Dependent tasks Parallelism Task Data Random Independent
Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared state
12.
State sharing Parallelism Task Data Random Independent
Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared state
13.
State sharing List registrations
= [] submissions.each {form → group.task { if (form.process().valid) { registrations << form } } }
14.
State sharing List registrations
= [] submissions.each {form → group.task { if (form.process().valid) { registrations << form } } } Needs protection
15.
Agent Lock Shared
Mutable State in a Safe Alter the State Alter the State
16.
Agent inside Double IncrementAdd
25 Message Queue 36 thread
17.
Sharing through agents Agent
registrations = group.agent( [] ) submissions.each {form → group.task { if (form.process().valid) { registrations.send {it << form} } } }
18.
Random task dependency Parallelism Task
Data Random Independent Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared state
19.
Dataflow Concurrency No race-conditions No
live-locks Deterministic deadlocks
20.
Dataflow Variables /
Promises main task2 task3 x yz task1
21.
Dataflow Variables /
Promises task2 x task1
22.
Dataflow Variables /
Promises main task2 task3 x yz task1
23.
Chaining promises def h1
= download('url') then {text → text.trim()} then hash
24.
Error handling url.then(download) .then(calculateHash) .then(formatResult) .then(printResult, printError) .then(sendNotificationEmail);
25.
List registrations =
[] List<Promise> forms=submissions.collect {form → group.task { if (form.process().valid) return form } } forms.each{registrations << it.get()} Pass results around
26.
Dataflow Variables /
Promises task2 x task1
27.
Dataflow Channels task2 x|y|z task1
28.
Synchronous Channels task2 x|y|z task1
29.
Tasks with progress
indication List<Promise> forms=submissions.collect {form → group.task { def result = form.process() progressQueue << 1 if (result.valid) { return form } } }
30.
Channel Selection Select alt
= group.select(validForms, invalidForms) SelectResult selectResult = alt.select() //alt.prioritySelect() switch (selectResult.index) { case 0: registrations << selectResult.value; break case 1: ... }
31.
Parallelism Data parallelism Task Data Random Independent
Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared state
32.
Parallelism Data parallelism Task Data Random Independent
Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared state
33.
Geometric decomposition images.eachParallel {it.process()} documents.sumParallel() candidates.maxParallel
{it.salary}.marry()
34.
Geometric decomposition registrations =
submissions .collectParallel { form -> form.process()} .findAllParallel { it.valid } registrations = submissions.parallel .map { form -> form.process()} .filter { it.valid }.collection
35.
Frequent confusion
36.
Improper use 1 def
accumulator = 0 myCollection.eachParallel { accumulator += calculate(it) }
37.
Improper use 2 new
File("/file.txt").withReader{reader -> reader.eachParallel { def r1 = step1(r) def r2 = step2(r1) def r3 = step3(r2) } }
38.
Unroll iteration def pipeline
= data | step1 | step2 | step3 new File("/file.txt").withReader{reader -> reader.each { data << it } }
39.
Unroll iteration
40.
Parallelism Streamed data Task Data Random Independent
Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared state
41.
Pipeline DSL def toProcess
= new DataflowQueue() def validated = new DataflowQueue() toProcess | {form -> process(form)} | {processedForm -> validate(processedForm)} | validated submissions.each {toProcess << it}
42.
Url resolverUrl resolverUrl
resolverprocess validate inProcess validated
43.
Url resolverUrl resolver Downloader Groovy
scanner Scala scanner Url resolverUrl resolver Reporter Speculator Evaluator Splitter Confirm Cache updates Approvals
44.
Dataflow Operators operator(inputs: [headers,
bodies, footers], outputs: [articles, summaries]) {header, body, footer -> def article = buildArticle(header, body, footer) bindOutput(0, article) bindOutput(1, buildSummary(article)) }
46.
Conclusion Parallelism Task Data Random Independent Dependent Hierarchical Geometrical Streamed Event-driven Functional Hierarchical Shared
state
47.
Summary Parallelism is not
hard, multi-threading is Jon Kerridge, Napier University
48.
Questions? Find more at: http://gpars.codehaus.org http://www.jroller.com/vaclav http://twitter.com/vaclav_pech