gpars parallel programming concepts for the jvm in groovy · concurrency enabling methods any...

Post on 21-May-2020

27 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Dierk KönigCanoo Engineering AG

Basel, Schweiz

GPars Parallel programming concepts for the JVM

in Groovy

Jazoon2.6.2010

Donnerstag, 10. Juni 2010

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

GPars mission

3

Donnerstag, 10. Juni 2010

GPars mission

3

Make concurrency simpler for the Java/Groovy programmer by giving access to new concepts.gpars.codehaus.org

Donnerstag, 10. Juni 2010

„New“ concepts

Fork/JoinMap/Filter/Reduce

DataflowAgentActor

Working on collections withpredefined coordination

Implicit coordinationDelegated coordinationExplicit coordination

Donnerstag, 10. Juni 2010

„New“ concepts

Fork/JoinMap/Filter/Reduce

DataflowAgentActor

CSPSTM

more

Working on collections withpredefined coordination

Implicit coordinationDelegated coordinationExplicit coordination

Donnerstag, 10. Juni 2010

„New“ concepts

Fork/JoinMap/Filter/Reduce

DataflowAgentActor

CSPSTM

more

DEMODEMO

DEMOSlideSlide

Donnerstag, 10. Juni 2010

„New“ concepts

Fork/JoinMap/Filter/Reduce

DataflowAgentActor

CSPSTM

DEMODEMO

DEMOSlideSlide

Donnerstag, 10. Juni 2010

Fork/Join vs Map/Filter/Reduce

6

!

Donnerstag, 10. Juni 2010

Fork/Join vs Map/Filter/Reduce

6

!

predefined coordination

Donnerstag, 10. Juni 2010

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

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

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

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

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

Concurrency takeaways

12

1 GPars makes it simple

Learn the concepts

Groovy/Java is ready

2

3

Donnerstag, 10. Juni 2010

13

Donnerstag, 10. Juni 2010

13

Donnerstag, 10. Juni 2010

Further reading

gpars.codehaus.org

manning.com/koenig2

Donnerstag, 10. Juni 2010

Questions - and maybe some answers ...

Donnerstag, 10. Juni 2010

Questions - and maybe some answers ...

dierk.koenig@canoo.com@mittie

Donnerstag, 10. Juni 2010

top related