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
650
ざっとわかる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.7k
開発フロー@はてなブックマーク
hakobe
0
160
Git on WebApp with Perl
hakobe
1
3.8k
Other Decks in Programming
See All in Programming
Zoneless Testing
rainerhahnekamp
0
120
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
140
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
良いユニットテストを書こう
mototakatsu
8
2.6k
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
260
testcontainers のススメ
sgash708
1
120
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
110
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
280
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
327
38k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
We Have a Design System, Now What?
morganepeng
51
7.3k
It's Worth the Effort
3n
183
28k
Building Your Own Lightsaber
phodgson
103
6.1k
Optimizing for Happiness
mojombo
376
70k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Building Applications with DynamoDB
mza
91
6.1k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
KATA
mclloyd
29
14k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
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