+ All Categories
Home > Documents > GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any...

GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any...

Date post: 21-May-2020
Category:
Upload: others
View: 20 times
Download: 0 times
Share this document with a friend
21
Dierk König Canoo Engineering AG Basel, Schweiz GPars Parallel programming concepts for the JVM in Groovy Jazoon 2.6.2010 Donnerstag, 10. Juni 2010
Transcript
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,

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,

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,

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,

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,

„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,

„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,

„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,

„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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

Questions - and maybe some answers ...

Donnerstag, 10. Juni 2010

Page 21: GPars Parallel programming concepts for the JVM in Groovy · Concurrency enabling methods any collect count each eachWithIndex every groupBy map split ... DataFlow Flavors: variables,

Questions - and maybe some answers ...

[email protected]@mittie

Donnerstag, 10. Juni 2010


Recommended