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
アクターによる 並行処理アプケーション アーキテクチャ
Search
hakobe (Yohei Fushii)
November 27, 2015
Programming
4
3.4k
アクターによる 並行処理アプケーション アーキテクチャ
社内勉強会でアクターとアクターを使ったアプリケーションのアーキテクチャについて紹介した資料です
hakobe (Yohei Fushii)
November 27, 2015
Tweet
Share
More Decks by hakobe (Yohei Fushii)
See All by hakobe (Yohei Fushii)
はてなにおけるプログラミング言語の歴史とこれから
hakobe
0
660
ざっとわかるPython
hakobe
4
6.8k
はてなで一人前のエンジニアになる方法
hakobe
3
6.8k
契約による設計の紹介
hakobe
6
20k
Scala In Perl Company
hakobe
11
12k
TDDの練習 Coding Kata の実践
hakobe
0
1.4k
なめらかにGHEに移行する方法
hakobe
19
7.8k
開発フロー@はてなブックマーク
hakobe
0
160
Git on WebApp with Perl
hakobe
1
3.8k
Other Decks in Programming
See All in Programming
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
410
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
390
良いユニットテストを書こう
mototakatsu
11
3.6k
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
240
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
170
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
700
『改訂新版 良いコード/悪いコードで学ぶ設計入門』活用方法−爆速でスキルアップする!効果的な学習アプローチ / effective-learning-of-good-code
minodriven
28
4.2k
AHC041解説
terryu16
0
400
Androidアプリの One Experience リリース
nein37
0
1.2k
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
950
Оптимизируем производительность блока Казначейство
lamodatech
0
950
Featured
See All Featured
Facilitating Awesome Meetings
lara
51
6.2k
The World Runs on Bad Software
bkeepers
PRO
66
11k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Scaling GitHub
holman
459
140k
Optimizing for Happiness
mojombo
376
70k
The Power of CSS Pseudo Elements
geoffreycrofte
74
5.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
240
The Language of Interfaces
destraynor
155
24k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Designing for humans not robots
tammielis
250
25k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Transcript
ΞΫλʔʹΑΔ ฒߦॲཧΞϓέʔγϣϯ ΞʔΩςΫνϟ hakobe932 1
͢͜ͱ •ฒߦॲཧʹ͍͓ͭͯ͞Β͍ •ΞΫλʔͷհ •ErlangʹΑΔΞϓϦέʔγϣϯ ΞʔΩςΫνϟ
The Free Lunch Is Over ϋʔυΣΞਐԽΛ ͯγεςϜੑೳ͕ ্͢Δ࣌ऴΘͬͨ (2005ʹ)
IUUQXXXHPUXDBQVCMJDBUJPOTDPODVSSFODZEEKIUN ϚϧνίΞCPUͷ࣌
ϚϧνίΞCPUΛੜ͔ͤΔ ฒߦॲཧϓϩάϥϛϯάٕज़Λ ֶ΅͏!
AppΤϯδχΞʹؔͳ͍? Q:WebΞϓϦέʔγϣϯͷੑೳ جຊతʹIOόϯυ͡ΌΜ? A:ϨΠςϯγʹؔͯ͠ɻ େྔͷλεΫΛ࣌͘͞ͷεϧʔϓοτ ͕͕ͪ͏ɻ গͳ͍αʔόͰͨ͘͞Μࣄ͕Ͱ͖͓ͯಘ
ϚϧνίΞCPUΛ׆༻ •୯Ґ࣌ؒʹ͔͞ͳ͍ͱ͍͚ͳ͍ σʔλ૿͍͑ͯΔ • ϒϩά/ϒοΫϚʔΫͷϦΫΤετ • Mackerelͷσʔλͷϙετ •ࠓ͋ΔΈͰ͖͖͞Εͳ͘ͳͬ ͨΒ?? •
ࣗͰ࡞Δͱ͍͏બࢶΛ࣋ͭ
ฒߦॲཧ͓͞Β͍
ϓϩηεʹΑΔฒߦॲཧ •ॲཧʹରԠ͢ΔϓϩηεΛىಈ(fork) ͠OSʹεέδϡʔϧͤ͞Δ Good • ҆શ • ϓϩάϥϛϯάύϥμΠϜ͕มΘΒͳ͍ Bad •
ϝϞϦ/CPUΛ͏ • σʔλڞ༗͕େม(File, Pipe, Socket, DB)
εϨουʹΑΔฒߦॲཧ •ҰͭͷϓϩηεͰෳͷ࣮ߦ୯Ґ Good • ൺֱతϦιʔεΛΘͳ͍ • ϝϞϦϑΝΠϧϋϯυϧͳͲΛ ڞ༗Ͱ͖Δ Bad •
҆શʹڞ༗ϦιʔεΛ͏ͷ͕͍͠
εϨουΛ҆શʹ͏ʹ •εςʔτϨεʹ͢Δ •ڞ༗ϝϞϦͷΞΫηεΛಉظԽ͢Δ • Lock/Mutex/Semaphore/synchronized/ volatile … ͨͩ͠ਖ਼͘͠͏ͷ͍͠ σουϩοΫ!
σʔλڝ߹!!
ྫ: σουϩοΫ public class LeftRightDeadlock { private final Object
left = new Object(); private final Object right = new Object(); public void leftRight() { synchronized (left) { synchronized (right) { doSomething(); } } } public void rightLeft() { synchronized (right) { synchronized (left) { doSomething(); } } } } " # leftΛ ϩοΫ rightΛ ϩοΫ rightΛ ϩοΫ͍ͨ͠ leftΛ ϩοΫ͍ͨ͠ Ӭԕʹͭ Ӭԕʹͭ
ฒߦॲཧͷநԽ •εϨουηʔϑͳΦϒδΣΫτʹ நԽ͢Δ •͍͠ॲཧΛ҆શʹͱΓ͔͋ͭ͑Δ ෦ͱ͖ͯ͠ΓΘ͚Δ •ྫ: Future •ࢀߟ: Javaฒߦॲཧϓϩάϥϛϯά
IUUQTQSBZJPEVTF
ΞΫλʔ
ΞΫλʔ •εϨουͷΑ͏ͳฒߦॲཧͷ୯Ґ •ϝοηʔδͷૹड৴ʹΑͬͯڠௐ •ΞΫλʔؒͰϝϞϦΛڞ༗͠ͳ͍ ˠ ڝ߹σουϩοΫ͕ى͖ʹ͍͘
ΞΫλʔ͕Ͱ͖Δ͜ͱ 1.ϝοηʔδΛผͷΞΫλʔʹૹ৴͢Δ 2.ผͷΞΫλʔΛ࡞Δ 3.ϝοηʔδΛड৴ͯࣗ͠ͷঢ়ଶΛ มߋ͢Δ
ϝοηʔδͷૹड৴ Actor ϝʔϧϘοΫε ϝοηʔδ ঢ়ଶͷߋ৽ Actor
৽͍͠ΞΫλʔͷੜ Actor Actor Actor Actor ੜ ੜ ੜ
ΞΫλʔʹΑΔγεςϜ Actor Actor Actor Actor Actor Actor
•ΞΫλʔΛߴʹେྔʹੜͰ͖Δ •ΞΫλʔΛίϯτϩʔϧ͢ΔΈ •ΞϓϦέʔγϣϯͱͯ͠ಈ࡞ͤ͞Δ Έ ΞΫλʔʹΑΔ ࣮༻తͳΞϓϦέʔγϣϯߏங ErlangͷྫͰ۩ମతʹհ →
Erlangʹ͍ͭͯগ͠ •ؔܕ, ಈతܕ, มͷ࠶ೖෆՄ •ΞΫλʔத৺ͷΞʔΩςΫνϟ •༗໊ͳΞϓϦέʔγϣϯྫ: • RabbitMQ, Riak, CouchDB,
ిͷަػ
Erlang༻ޠͰΞΫλʔͷ͜ ͱΛϓϩηεͱݺͼ·͢!!! ͕ͱ͜͜ͰΞΫλʔͱ͍͏͜ͱͰʜ
ErlangͷΞΫλʔ •ErlangϓϩάϥϜΞΫλʔͷू߹ •ඇৗʹܰྔͰߴ • 1ͭ300ϫʔυ • ୯७ͳͷͰ͘͢ىಈͰ͖Δ • ࢀߟ: http://d.hatena.ne.jp/sakaia/
20150315#1426406872 •ωΠςΟϒεϨουͰͳ͘ άϦʔϯεϨουతʹಈ࡞
spawn !! Pid = spawn(fun() -> receive hello ->
io:format("Hello, World!~n") end end). Pid ! hello. Actor Actor Actor Actor Actor Actor hello Hello, World!
ΞΫλʔͷίϯτϩʔϧ •Ұ෦ͷΞΫλʔ͕Τϥʔ͕͓͖ͨΒ? Actor Actor Actor Actor Actor Actor Error!!
Let it crash •Τϥʔ͕͓͖ΔͱΞΫλʔ͕Ϋϥογϡ! Actor Actor Actor Actor Actor
Actor γεςϜͷଞͷ෦Ͳ͏͢Δ?
Link Actor Actor Actor Actor Actor Actor -JOL Ұํ͕ऴྃ
ࣗಈతʹ ͏Ұํऴྃ γεςϜશମΛ࣮֬ʹऴྃͰ͖Δ
Link + process_trap Actor Actor Actor Actor Actor Actor
-JOL Ұํ͕ऴྃ &9*5 ͕ૹ৴͞ΕΔ &9*5
•ऴྃϋϯυϧͰ͖Δ Link + process_trap Actor Actor ޙॲཧΛ͢Δ Actor Actor
࠶ىಈ͢Δ Actor ͋Δ͍ Monitorͱ͍͏Έ͋Δ
Ͳ͏͍͏ઓུͰΤϥʔॲཧ͢Δ͔? •࣮͜ΕWorkerManagerͰͨ͠ Server Worker Worker Worker Manager Main શମΛཧ
ϦΫΤετ ड͚͚ ϫʔΧʔΛ ཧ
Worker͕Τϥʔ Server Worker Worker Worker Manager Main →Worker͚ͩ࠶ىಈ͢ΕΑ͍
Server͕Τϥʔ Server Worker Worker Worker Manager Main →ܑఋͱͦͷࢠ͋Θͤͯ࠶ىಈ
Supervisorʹ·͔ͤΑ͏ •ΞΫλʔऴྃॲཧʹύλʔϯ͕͋Δ •Link(Monitor)Λͬͯஸೡʹ࣮ ͢Δͷୀ۶ •Α͋͘ΔཧॲཧΛݞΘΓͯ͘͠Ε Δͷ͕Supervisor
࠶ىಈͷઓུ •࠶ىಈ͢Δ͔Ͳ͏͔? • permanent/temporary/transient •ԿΛ࠶ىಈ͢Δ͔? • one_for_one/one_for_all/one_for_rest •ͲΕ͘Β͍Ͱ͖͋ΒΊΔ͔? • nҎʹmճ࠶ىಈͨ͠Βࢮ͵
Managerͷઓུ Server Worker Worker Worker Manager Main permanent, one_for_one
Mainͷઓུ Server Worker Worker Worker Manager Main permanent one_for_all
•SupervisorπϦʔ͕ ΞϓϦέʔγϣϯΛߏ͢Δ ErlangͷΞϓϦέʔγϣϯ Application
RabbitMQͷSupervisorπϦʔ IUUQXXXTMJEFTIBSFOFUPME@TPVOEEJTTFDUJOHUIFSBCCJU
SupervisorʹΑΔো ΞʔΩςΫνϟ •ΤϥʔͷॏཁʹԠͯ͡ΞΫλʔΛׂ •Τϥʔ࣌ͷΞΫλʔͷઓུΛSupervisor ʹΑΓઃఆ • దͳൣғΛඞཁʹԠͯ͡࠶ىಈ • Τϥʔͷ͜ͱΛߟ͑ͳ͍ͱ͍͚ͳ͍ઃܭ
·ͱΊ •ΞΫλʔ҆શͰॊೈͳ ฒߦॲཧϓϩάϥϛϯάٕज़ͷͻͱͭ •ErlangΞΫλʔʹΑΔγεςϜͷ ࣮༻తͳϓϥοτϑΥʔϜ •SupervisorΛ༻͍ͨোੑ ΞʔΩςΫνϟ͕ߏஙͰ͖Δκ
ࢀߟจݙ •Javaฒߦॲཧϓϩάϥϛϯά - http://www.amazon.co.jp/dp/4797337206 •͍͢͝ErlangΏ͔͍ʹֶ΅͏ʂ - http://www.amazon.co.jp/dp/B00MLUGZIS/ •ฒߦॲཧॳ৺ऀͷͨΊͷAkkaೖ -
http://www.slideshare.net/sifue/akka-39611889 •ϓϩάϥϛϯάݴޠͷύϥμΠϜγϑτʔScala͔ΒݟΔؔܕͱฒ ྻੑ࣌ͷນ։͚ - http://www.slideshare.net/TanUkkii/functional-and- concurencyinscala •Web API αʔόʔͱͯ͠ͷ Elixir ͷՄೳੑ - https://speakerdeck.com/naoya/web-api-sabatositefalse-elixir- falseke-neng-xing