If you can't read please download the document
Upload
ericsword
View
2.831
Download
1
Embed Size (px)
Citation preview
Default
GPars Quick Hits
Eric Sword
Who am I
Professional geek for 17 years
Former head of engineering here at Group Logic
Now full-time dev and tech lead for SAIC
Blog: http://www.swordsystems.com
All Together Now
JEEPERS!
Why GPars?
Concise
Avoids errors with thread managementNo creating threads or managing pool
Easy to StartRolled into Groovy 1.8
import groovyx.gpars.XXX
Who?
Vaclav Pech started it in 2008
http://www.jroller.com/vaclav/
Jetbrains (makers of Intellij IDEA) employee?
Very responsive
Keeps an eye on GPars news
How?
Grab
Maven
org.codehaus.groovy
groovy-all
1.8.2
org.codehaus.gpars
gpars
0.12
@Grab('org.codehaus.gpars:gpars:0.12')
Version Dependency Hassles
Groovy bundled with 0.11, but 0.12 is out
0.11 -> org.coconut.forkjoin:jsr166y-070108.jarOr maybe jsr166y-070108.jar???
0.12 -> org.codehaus.jsr166-mirrorjsr166y-1.7.0.jar
extra166y-1.7.0.jar
4 Main Parts
Async Collections and Closures
Actors like Scala
Dataflow
Agents like Clojure
4 Main Parts
Async Collections and Closures
Actors like Scala
Dataflow
Agents like Clojure
Collection Fork-Join
each,collect,find, etc become parallelSee Re-GINA 17.2.2 for full list
Insert wherever you want
No re-architecture
Collections - code
import static groovyx.gpars.GParsPool.withPool
def urls = [...some urls here...]withPool {urls.collectParallel{it.text}}
You will see withPool a lot
Collections code
withPool {urls.makeConcurrent().collect{it.text}}
//chain together
withPool {urls.makeConcurrent().collect{it.text}.findAll{it.contains 'GROOVY'}.size()}
}
Warning: Breaking API Changes
Big changes from 0.10 to 0.12Calls deprecated in 0.11, removed in 0.12
makeTransparent -> makeConcurrent
Beware some examples in Ref Guide
Beware tutorials written for collect, filter -> findAll
From ReGina, Figure 17.1
Closures
AsyncFun
Testing
Test your code, not Gpars
Testing
Test your code, not Gpars
Bonus! Your code doesn't change
Using Gpars for Testing
http://www.slideshare.net/paulk_asert/groovy-and-concurrency - slide 102
Behind The Scenes
withPool uses a category to add the methods to collections, closures, etc.
Actual code in GparsPoolUtil
Map-Reduce methods also in that file in contained class PAWrapper
Resources
http://gpars.codehaus.org
http://git.codehaus.org/gitweb.cgi?p=gpars.git;a=tree;f=src/test/groovy/groovyx/gpars/samples
http://www.manning.com/koenig2/
http://www.slideshare.net/gr8conf/g-pars-vaclavpech2011
http://www.slideshare.net/VaclavPech/pick-up-the-lowhanging-concurrency-fruit
http://skillsmatter.com/podcast/groovy-grails/concurrent-programming-for-you-and-mestarts a little slow, but around minute 16, gives some good examples
http://groovy.codehaus.org/Guy+Steele%27s+word+split+example+using+Groovy+and+GPars
http://www.slideshare.net/paulk_asert/groovy-and-concurrency
Thanks!
Happy Parallelizing
http://www.swordsystems.com
http://www.slideshare.net/ericsword/gpars-quick-hits
Click to edit the title
(c) 2011 Eric Sword
Click to edit the title text format