GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any...
Transcript of GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any...
![Page 1: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/1.jpg)
Dierk KönigCanoo Engineering AG
Basel, Schweiz
GPars Parallel programming concepts for the JVM
in Groovy
Jazoon2.6.2010
Donnerstag, 10. Juni 2010
![Page 2: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/2.jpg)
Welcome!Dierk KönigFellow @ Canoo Engineering AG, Basel (CH)
Canoo RIA SuiteProjects, Consultingwww.canoo.com
Open-source committer Groovy, Grails, GPars
Donnerstag, 10. Juni 2010
![Page 3: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/3.jpg)
GPars mission
3
Donnerstag, 10. Juni 2010
![Page 4: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/4.jpg)
GPars mission
3
Make concurrency simpler for the Java/Groovy programmer by giving access to new concepts.gpars.codehaus.org
Donnerstag, 10. Juni 2010
![Page 5: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/5.jpg)
„New“ concepts
Fork/JoinMap/Filter/Reduce
DataflowAgentActor
Working on collections withpredefined coordination
Implicit coordinationDelegated coordinationExplicit coordination
Donnerstag, 10. Juni 2010
![Page 6: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/6.jpg)
„New“ concepts
Fork/JoinMap/Filter/Reduce
DataflowAgentActor
CSPSTM
more
Working on collections withpredefined coordination
Implicit coordinationDelegated coordinationExplicit coordination
Donnerstag, 10. Juni 2010
![Page 7: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/7.jpg)
„New“ concepts
Fork/JoinMap/Filter/Reduce
DataflowAgentActor
CSPSTM
more
DEMODEMO
DEMOSlideSlide
Donnerstag, 10. Juni 2010
![Page 8: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/8.jpg)
„New“ concepts
Fork/JoinMap/Filter/Reduce
DataflowAgentActor
CSPSTM
DEMODEMO
DEMOSlideSlide
Donnerstag, 10. Juni 2010
![Page 9: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/9.jpg)
Fork/Join vs Map/Filter/Reduce
6
!
Donnerstag, 10. Juni 2010
![Page 10: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/10.jpg)
Fork/Join vs Map/Filter/Reduce
6
!
predefined coordination
Donnerstag, 10. Juni 2010
![Page 11: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/11.jpg)
Concurrency enabling methods
any collect count each eachWithIndex every groupBy map split filter find findAll findAny grepreduce fold max min sum
makeTransparent parallel collection
7
Donnerstag, 10. Juni 2010
![Page 12: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/12.jpg)
DataFlow
Flavors: variables, streams, operators, tasks, flows
Write-Once, Read-Many (non-blocking)
Feel free to use millions of them
Fast, efficient, safe, and testable!
8
Model the flow of data,
not the control flow!
Donnerstag, 10. Juni 2010
![Page 13: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/13.jpg)
Explicit coordination with Actors
@Grab('org.codehaus.gpars:gpars:0.10')import static groovyx.gpars.actor.Actors.*
def decrypt = reactor { code -> code.reverse() }def audit = reactor { println it }
def main = actor { decrypt 'terces pot' react { plainText -> audit plainText }}main.join()audit.stop()audit.join()
9
Donnerstag, 10. Juni 2010
![Page 14: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/14.jpg)
Actors
Process one message at a time.
Dispatch on the message type, which fits nicely with dynamic languages.
Are often used in composition,which can lead to further problems down the road.
10
Personal note:
Actors are overrated
Donnerstag, 10. Juni 2010
![Page 15: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/15.jpg)
Delegate coordination to Agents
@Grab('org.codehaus.gpars:gpars:0.9')import groovyx.gpars.agent.Agent
def guard = new Agent<String>()
guard { updateValue 'GPars' }guard { updateValue(it + ' is groovy!') }
assert "GPars is groovy!" == guard.val
11
Donnerstag, 10. Juni 2010
![Page 16: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/16.jpg)
Concurrency takeaways
12
1 GPars makes it simple
Learn the concepts
Groovy/Java is ready
2
3
Donnerstag, 10. Juni 2010
![Page 17: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/17.jpg)
13
Donnerstag, 10. Juni 2010
![Page 18: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/18.jpg)
13
Donnerstag, 10. Juni 2010
![Page 19: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/19.jpg)
Further reading
gpars.codehaus.org
manning.com/koenig2
Donnerstag, 10. Juni 2010
![Page 20: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,](https://reader030.fdocuments.in/reader030/viewer/2022040409/5ec6ea9b89b9675d89519199/html5/thumbnails/20.jpg)
Questions - and maybe some answers ...
Donnerstag, 10. Juni 2010