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
concurrency programming with Akka
Search
Shinpei Maruyama
August 09, 2014
Programming
2
410
concurrency programming with Akka
Shinpei Maruyama
August 09, 2014
Tweet
Share
More Decks by Shinpei Maruyama
See All by Shinpei Maruyama
設計ナイト2022 トランザクションスクリプト
shinpeim
11
3.1k
Ruby (off|with) the Rails
shinpeim
20
4.7k
綱渡りバッチ脱出大作戦
shinpeim
3
3.1k
Building native apps with scala.js
shinpeim
2
1.1k
今あえてDRY原則に向き合う
shinpeim
51
550k
Nekogata Drum Sequencer written in Scala.js
shinpeim
2
3.7k
複雑なJavaScriptアプリケーションに立ち向かうためのアーキテクチャ
shinpeim
36
14k
Using Scala.js with the JavaScript ecosystems
shinpeim
0
2.1k
Vue.jsで実現するMVVMパターン Fluxアーキテクチャとの距離
shinpeim
22
31k
Other Decks in Programming
See All in Programming
イベントストーミングによるオブジェクトモデリング・オブジェクト指向プログラミングの適用・開発プロセスの変遷・アーキテクチャの変革 / Object modeling with Event Storming.
nrslib
12
2.9k
PHP 8.3で追加されたjson_validate()を徹底的に深掘りしてみよう
mashirou1234
1
720
コミュニティに参加したことで起きた変化
ohmori_yusuke
3
130
WinUI 3デモ - "CommunityToolkit.Mvvm"NuGetパッケージ編
andrewkeepcoding
0
130
クソコード動画『カプセル化 Mk-II』 で考える 上手くカプセル化できない理由 / encapsulation2
minodriven
11
7.8k
TCA魔法学入門🪄
dazy
0
280
RubyVM を PHP で実装する 〜Hello World を出力するまで〜
memory1994
PRO
1
490
Kotlinを用いたDSL的な設計手法と使用上の注意
kohii00
3
530
とにかくHTTP3をライトニングに話す / Anyway, I'll talk to Lightning about HTTP3.
seike460
PRO
0
120
ここ1~2年くらいで 使えるようになった(主要ブラウザーの最新版 がすべて対応した ) ウェブの新機能について ランダムに喋る!
myzkyy
9
6.4k
Enhancing Applications with Accessibility API
kishikawakatsumi
3
880
GitHub Copilot Tips and Tricks
yuichielectric
26
7.4k
Featured
See All Featured
Being A Developer After 40
akosma
56
580k
For a Future-Friendly Web
brad_frost
170
8.9k
How STYLIGHT went responsive
nonsquared
92
4.7k
Typedesign – Prime Four
hannesfritz
36
2k
A designer walks into a library…
pauljervisheath
199
23k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
14
1.3k
Building an army of robots
kneath
300
41k
The Cost Of JavaScript in 2023
addyosmani
13
3.7k
The Mythical Team-Month
searls
214
42k
How to train your dragon (web standard)
notwaldorf
71
5.1k
YesSQL, Process and Tooling at Scale
rocio
160
13k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
355
22k
Transcript
by しんぺい a.k.a. 猫型蓄音機 concurrency programming with Akka
で、誰? • 猫型蓄音機 とか しんぺいさんとか • お仕事では Ruby, Scala •
趣味でも Ruby, Scala • たまに Perl
第一部 並行処理とその課題
逐次処理と並行処理 • 逐次処理 • 実行順序が保証されている • 並行処理 • 実行順序が保証されていない
逐次処理
並行処理
並行処理
並行処理と並列処理 • 並行処理 • 同時に実行される処理は一個だけかもし れない(=CPUは一個かもしれない) • 並列処理 • 同時に複数の処理が実行される(=複数の
CPUが同時に処理を行っている)
例えば • CRuby1.8までは、複数スレッドを利 用してもCPUはひとつしか使ってい なかった(= 並行処理ではあるが並 列処理ではない) • 1.9からは複数CPUで計算するように なった(=
並行処理かつ並列処理)
並行処理の課題1 • 処理の順序が保証されない = どこ で誰がメモリのどの部分を触るかわ からない • 複数のスレッドで共有されるデータ に関してはロックなどの工夫が必要
• ロック獲得し忘れてデータこわしま した • デッドロックになってシステムが停 止しました • テストしにくすぎ問題 並行処理の課題1
並行処理の課題2 • 処理の順序が保証されないのでどこ で例外ハンドリングするかめっちゃ 悩む • 例外は一種の goto です
第二部 Actor Model
辛みをコントロールする Q: なんでロックが必要なの? A: ひとつのデータをみんなで触るか ら Q: じゃあそもそもデータ共有しな きゃよくない? A:
アッハイ
例えばDLのプログレスバー UIスレッド DLスレッド 進捗率 DLを依頼 content 共有
UIアクター DLアクター DLを依頼 進捗報告 進捗報告 進捗報告 進捗報告 content 例えばDLのプログレスバー
辛みをコントロールする • 非同期の例外ハンドリングめっちゃ 大変 • じゃあ、例外が起こったらリカバリ しないで壊しちゃえ、壊れたらもっ かい新しいアクター作ろう! • Let
it crash!!!!!!!!
Let it crash Actor A Actor B mail box mail
box send message
Let it crash Actor A Actor B mail box mail
box fetch message
Let it crash Actor A Actor B mail box mail
box process message
Let it crash Actor A Actor B mail box mail
box send messages
Let it crash Actor A Actor B mail box mail
box fetch and process messages
Let it crash Actor A Actor B mail box drunk
exception! mail box
Let it crash Actor A Actor B mail box インスタンスを破棄
mail box
Let it crash Actor A mail box mail box
Let it crash Actor A mail box mail box Actor
B インスタンス再作成
Let it crash Actor A Actor B mail box mail
box fetch and process messages
supervisor tree • Actorは(基本的には)Actorによっ て作られる • 作ったActorは作られたActorを監 視する。 • 監視の木構造が出来上がる
supervisor tree • 監視されてるActorで上がった例外は監 視してるActorが捕捉できる • デフォルトかつ典型的動きとしては、さっ き見たようにアクターを再起動する • その他に、止めちゃったり、さらに上の
監視者に丸投げしたりできる
第三部 Akka で Actor
Actor in Scala • Akka • 信頼と実績のTypesafe製 • JVM上で動く •
Java/Scalaで使えるよ • クラスタリングできるよ • 要するにJVMで動くErlang/OTPみたい なかんじ!
ライブコーディング & デモします
Akka vs Erlang • Akka • JVMの資産が使える • 文法がきもくない •
Erlang • ホットデプロイできる • ErlangVM 軽量プロセス
まとめ • データを共有するのが辛い => Actor モデルで shared nothing! • 例外のハンドリングが辛い
=> Actor モデルで let it crash!
さらなる学習へのポインタ • https://gist.github.com/ Shinpeim/ ef7ce82595cb96ef4aa6 • http://akka.io/