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.4k
なめらかに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
Quine, Polyglot, 良いコード
qnighy
4
650
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Click-free releases & the making of a CLI app
oheyadam
2
120
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
CSC509 Lecture 11
javiergs
PRO
0
180
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
Jakarta EE meets AI
ivargrimstad
0
240
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Teambox: Starting and Learning
jrom
133
8.8k
Docker and Python
trallard
40
3.1k
Writing Fast Ruby
sferik
627
61k
For a Future-Friendly Web
brad_frost
175
9.4k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Done Done
chrislema
181
16k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Happy Clients
brianwarren
98
6.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
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