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
640
ざっとわかるPython
hakobe
4
6.8k
はてなで一人前のエンジニアになる方法
hakobe
3
6.7k
契約による設計の紹介
hakobe
6
20k
Scala In Perl Company
hakobe
11
12k
TDDの練習 Coding Kata の実践
hakobe
0
1.3k
なめらかにGHEに移行する方法
hakobe
19
7.7k
開発フロー@はてなブックマーク
hakobe
0
150
Git on WebApp with Perl
hakobe
1
3.8k
Other Decks in Programming
See All in Programming
offers_20241022_imakiire.pdf
imakurusu
2
360
macOS でできる リアルタイム動画像処理
biacco42
7
1.8k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
130
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
240
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.5k
のびしろを広げる巻き込まれ力:偶然を活かすキャリアの作り方/oso2024
takahashiikki
1
410
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
330
現場で役立つモデリング 超入門
masuda220
PRO
12
2.9k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
290
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
How to Think Like a Performance Engineer
csswizardry
19
1.1k
How STYLIGHT went responsive
nonsquared
95
5.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
KATA
mclloyd
29
13k
How GitHub (no longer) Works
holman
311
140k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Writing Fast Ruby
sferik
626
61k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
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