Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Vaclav Pech on GPars
Search
Enterprise Java User Group Austria
March 05, 2012
Technology
0
34
Vaclav Pech on GPars
Enterprise Java User Group Austria
March 05, 2012
Tweet
Share
More Decks by Enterprise Java User Group Austria
See All by Enterprise Java User Group Austria
Gerrit Grunwald on What the CRaC... SUPERFAST JVM STARTUP
ejug
1
57
Spring Framework 5.2 - Core Container Revisited
ejug
0
110
Andreas Caternberg on Jenkins Pipelines
ejug
0
400
Martin Ahrer on Continuous Delivery Infrastructure With Docker
ejug
0
100
Dirk Mahler on Software Analyse mit jQAssistant & Neo4j
ejug
0
170
Christoph Strobl on Spring Data & Hypermedia
ejug
0
71
Stefan Armbruster on Graph Modelling Antipatterns
ejug
0
78
Stefan Armbruster on Introduction into Neo4J
ejug
0
60
Michael Nitschinger on Building a reactive Couchbase driver for the JVM
ejug
0
91
Other Decks in Technology
See All in Technology
RAGのサービスをリリースして1年3ヶ月が経ちました
segavvy
4
950
Classmethod流のPlatform Engineering / classmethod-platform-engineering-devio2024
tomoki10
0
480
ここがすごいよ! AWS Systems Manager!
saichan11
0
1.8k
Git 研修 Basic【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
310
Luupの開発組織におけるインシデントマネジメントの変遷 ver.RoadtoSRENEXT2024
grimoh
1
270
エンジニア向け会社紹介資料
caddi_eng
14
230k
ギークの理想が7つ集まるエムスリーで夢を叶えよう - エムスリー株式会社
m3_engineering
1
260
可視化プラットフォームGrafanaの基本と活用方法の全て
hamadakoji
0
230
What is DRE? - Road to SRE NEXT@広島
chanyou0311
3
630
地理情報とAPIのトレンド
nagix
0
160
スレットハンティングについて知っておきたいこと
hacket
0
130
推薦システムを本番導入する上で一番優先すべきだったこと~NewsPicks記事推薦機能の改善事例を元に~
morinota
0
130
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
423
64k
Large-scale JavaScript Application Architecture
addyosmani
506
110k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
78
15k
Robots, Beer and Maslow
schacon
PRO
157
8.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
224
21k
It's Worth the Effort
3n
181
27k
Building a Modern Day E-commerce SEO Strategy
aleyda
25
6.7k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
24
1.8k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
34
1.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
360
22k
Designing the Hi-DPI Web
ddemaree
276
34k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
36
9.1k
Transcript
GPars Promises to keep Václav Pech
About me ['Passionate programmer', 'Concurrency enthusiast', 'GPars lead', 'Developer/technology evangelist
@ JetBrains' ].eachParallel {say it} http://www.jroller.com/vaclav http://twitter.com/vaclav_pech
We're all parallel now Use them or leave them!
None
# of cores
# of cores Today Soon
Dealing with threads sucks! public class Counter { private static
long count = 0; public Counter() { count++; } }
Dealing with threads sucks! public class Counter { private static
long count = 0; public Counter() { synchronized (this) { count++; } } }
Dealing with threads sucks! public class Counter { private static
long count = 0; public Counter() { synchronized (this.getClass()) { count++; } } }
Dealing with threads sucks! public class ClickCounter implements ActionListener {
public ClickCounter(JButton button) { button.addActionListener(this); } public void actionPerformed(final ActionEvent e) { ... } }
images.eachParallel {it.process()} documents.sumParallel() candidates.maxParallel {it.salary}.marry() Parallel Collections
Parallel Collections progLanguages.parallel.filter {it.concurrent} .max {it.javaInteroperability} .map {it.logo} ==
Fork/Join Solve hierarchical problems Divide and conquer
Merge sort, Quick sort Tree traversal File scan / search … [a, b, c, d, e, f, g, h] [a, b, c, d] [e, f, g, h] [a, b] [c, d] [e, f] [g, h]
Thread Pool Tasks Worker threads Queue
Thread Pool Contention!
Fork/Join Thread Pool
Fork/Join Thread Pool Work stealing
Languages are either concurrent or obsolete.
Java 5 Asynchronous calculations
Java 7 Asynchronous calculations Fork/Join
Java 8 Asynchronous calculations Fork/Join Parallel collections
Scala Asynchronous calculations Fork/Join Parallel collections Actors
Clojure Asynchronous calculations Fork/Join Parallel collections Actors Agents, Stm
Oz Asynchronous calculations Fork/Join Parallel collections Actors Agents, Stm Dataflow
Google's Go Asynchronous calculations Fork/Join Parallel collections Actors Agents, Stm
Dataflow CSP
Asynchronous calculations Fork/Join Parallel collections Actors Agents, Stm Dataflow CSP
Asynchronous calculations Fork/Join Parallel collections Actors Agents, Stm Dataflow CSP
Agenda
Actors Processes with a mail-box Share no data Communicate by
sending messages Use a thread-pool
Stateless Actors (pure Java) class MyActor extends DynamicDispatchActor { Account
account = ... public void onMessage(String msg) { String encripted = encrypt(msg); reply(encripted); } public void onMessage(Integer number) { reply(2 * number); } public void onMessage(Money cash) { System.out.println("Received a donation " + cash); account.deposit(cash); } }
Active Objects @ActiveObject class MyCounter { private int counter =
0 @ActiveMethod def incrementBy(int value) { println "Received an integer: $value" this.counter += value } }
Composing async functions int hash1 = hash(download('http://www.gpars.org')) int hash2 =
hash(loadFile('/gpars/website/index.html')) boolean result = compare(hash1, hash2) println result
Composing async functions @AsyncFun hash = oldHash @AsyncFun compare =
oldCompare @AsyncFun download = oldDownload @AsyncFun loadFile = oldLoadFile def hash1 = hash(download('http://www.gpars.org')) def hash2 = hash(loadFile('/gpars/website/index.html')) def result = compare(hash1, hash2) println result.get()
Composing async functions @AsyncFun hash = oldHash @AsyncFun(blocking = true)
compare = oldCompare @AsyncFun download = oldDownload @AsyncFun loadFile = oldLoadFile def hash1 = hash(download('http://www.gpars.org')) def hash2 = hash(loadFile('/gpars/website/index.html')) boolean result = compare(hash1, hash2) println result
int hash(String text) {…} Promise<int> hash(Promise<String> | String text)
int hash(String text) {…} Promise<int> hash(Promise<String> | String text) compare(
hash( download() ), hash( loadFile() ) )
int hash(String text) {…} Promise<int> hash(Promise<String> | String text) {
1.Return a Promise for the result 2.Wait (non-blocking) for the text param 3.Call the original hash() 4.Bind the result }
Composing async functions Combine functions as usual Parallelism is detected
automatically
Dataflow Concurrency No race-conditions No live-locks Deterministic
deadlocks Completely deterministic programs BEAUTIFUL code (Jonas Bonér)
Dataflow Variables / Promises main task2 task3 x y z
task1
Dataflows def df = new Dataflows() task { df.z =
df.x + df.y } task { df.x = 10 } task { println ”I am task 3” df.y = 5 } assert 15 == df.z
operator(inputs: [headers, bodies, footers], outputs: [articles, summaries]) {header, body, footer
-> def article = buildArticle(header, body, footer) bindOutput(0, article) bindOutput(1, buildSummary(article)) } * + <> Dataflow Operators
Url resolver Url resolver Downloader Groovy scanner Scala scanner Url
resolver Url resolver Reporter Speculator Evaluator Splitter Confirm Cache updates Approvals Dataflow Operators
None
'coz concurrency is Groovy Find more at: http://gpars.codehaus.org http://www.jroller.com/vaclav http://twitter.com/vaclav_pech
GPars