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
everyone node.js
Search
ogom
October 13, 2011
Programming
0
110
everyone node.js
node.js 入門編
ogom
October 13, 2011
Tweet
Share
More Decks by ogom
See All by ogom
PicoRuby から始めるたのしい電子工作
ogom
0
1.5k
GraphQL Better Errors
ogom
0
320
Osaka RubyKaigi 02
ogom
0
290
Osaka RubyKaigi 01
ogom
0
200
Contributing to GitLab with OSS Gate
ogom
0
520
DojoCon Japan 2017
ogom
0
120
GDStudy Engage
ogom
1
740
Using Immutable.js with React Redux
ogom
0
130
CoderDojo と オープンソース
ogom
2
470
Other Decks in Programming
See All in Programming
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
220
イベント駆動で成長して委員会
happymana
1
320
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
Macとオーディオ再生 2024/11/02
yusukeito
0
370
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
136
6.6k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Faster Mobile Websites
deanohume
305
30k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Done Done
chrislema
181
16k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Transcript
ΈΜͳͷ node.js node.js ೖฤ
ࣗݾհ ! •GitHubɿogom •Twitterɿ@ogomr
͡Ίʹ •ΈΜͳͷnode.jsͬͯʁ •node.js ΈΜͳͰ͏ΞϓϦέʔγϣϯʹ ద͍ͯ͠·͢ɻ •·ͨɺΈΜͳ͕͍ͬͯΔ JavaScript ͷ ݴޠͰهड़͠·͢ɻ !
•͜Ε͔Β node.js Λֶश͢Δํʹ͚ͯ ಛ͍ॴΛղઆ͠·͢ɻ hello node world!
Agenda ! •node.js ͱ •node.js ͷ͍ॴ •ྲྀߦͱظ
node.js ͱ
node.js ͷಛ •Eventide I/O for V8 JavaScript. •node.js ͷެࣜαΠτͷ࢝Ίʹग़͍ͯΔΩʔϫʔυͰ͢ɻ ͜ͷ
Evented I/O ͱ V8 JavaScript ͕ಛΛද͠·͢ɻ ! •Evented I/O •ΠϕϯτۦಈͷΈͰେྔͷೖग़ྗ(I/O)Ͱ ߴ͍ύϑΥʔϚϯεͷΞϓϦέʔγϣϯ͕࡞Ͱ͖·͢ɻ •V8 JavaScript •V8 Google ͷ Chrome ʹࡌ͞Ε͍ͯΔߴͳ JavaScript Engine Ͱ͢ɻͦͷ JavaScript ͰαʔόʔαΠυͷΞϓϦέʔγϣ ϯ͕࡞Ͱ͖·͢ɻ
node.js ͍͍Ͷʂ •ΠϕϯτϧʔϓߴͳύϑΥʔϚϯεΛཁٻ͞ΕΔ ωοτϫʔΫΞϓϦέʔγϣϯʹ࠷దͰ͢ɻ •ฒߦॲཧΛγϯάϧεϨουͰ͢ΔͨΊʹϊϯϒϩοΩϯάI/OͰඇಉظॲཧΛ࣮ݱ͍ͯ͠·͢ɻ ɹ(node.js ฒߦॲཧʹΠϕϯτϧʔϓͱݺΕΔϞσϧΛ࠾༻͍ͯ͠·͢ɻ) •γϯάϧεϨουϝϞϦͷফඅྔ͕গ͘ ϋʔυΣΞͷίετΛ͑·͢ɻ •1ͭͷϓϩηεͰෳͷϦΫΤετΛѻ͏ͷͰϝϞϦྔΫϥΠΞϯτʹൺྫ͠·ͤΜɻ
•γϯάϧεϨουͱϊϯϒϩοΩϯI/O JavaScript ͱ૬ੑ͕Α͘ ·ͨɺΫϩʔδϟ͕ΠϕϯτۦಈͷΈͷίʔϧόοΫʹͱͯศརͰ͢ɻ •ϑϩϯτΤϯυͷߏஙͰϝδϟʔͳ JavaScript Ͱ όοΫΤϯυͷॲཧΛߏஙͰ͖·͢ɻ •αʔόʔαΠυJavaScript ͱݴΘΕ͍ͯ·͢ɻ͞ΒʹɺϑϩϯτΤϯυͰख़Ε͍ͯΔ ΠϕϯτۦಈͷελΠϧόοΫΤϯυͰར༻Ͱ͖·͢ɻ
͝Μ͍͖ͨͩ·͢ •ಠͷஉ͕͝Μͷ༻ҙΛ࢝Ί·ͨ͠ɻ •ిࢠϨϯδͰࡢͷ͡Ό͕ΛԹΊ·͢ɻ •ͦͷؒʹΨείϯϩͰ͓౬Λ͔͠·͢ɻ •͝൧ΛΑͦͬͯɺ͠͠ٳܜŋŋŋ •͓౬͕ΰϘΰϘͨ͠ͷͰ͓ΛೖΕ·͢ɻ •νʔϯͱ໐ͬͨͷͰςʔϒϧͷࡼʹҠͯ͠ Ҝࢠʹ࠲Γ·͢ɻ •͠Λखʹʮ͍͖ͨͩ·͢ʯ ͋ͬςϨϏ͚ͭͳ͖Όʂ
! •ૣ͘͝ΜΛ৯͍ͨͷͰ͡Ό͕ͱ ͓ͷ༻ҙΛฒߦʹ࡞ۀ͠·͢ɻ •͡Ό͕ͷԹΊͱ͓౬͕͘ͷͲͪΒ͕ઌ ͰΑͯ͘ɺͰ͖ͨํ͔ΒऔΓֻ͔ΕΔͷ خ͍͠Ͱ͢ɻ
ΠϕϯτϧʔϓͱϊϯϒϩοΩϯάI/O •͝Μͷ༻ҙͰઆ໌͠·͢ɻ •ಠͷஉɿΠϕϯτϧʔϓ •ϨϯδͷԹΊɿΠϕϯτϋϯυϥA •νʔϯɿΠϕϯτϋϯυϥAͷίʔϧόοΫ •ίϯϩͰ౬͠ɿΠϕϯτϋϯυϥB •ΰϘΰϘɿΠϕϯτϋϯυϥBͷίʔϧόο Ϋ •Πϕϯτϧʔϓ
•Πϕϯτ͕ൃੜͨ͠λΠϛϯάͰ ίʔϧόοΫͰݺͼग़͞ΕΔΈͷ͜ͱ •ϊϯϒϩοΩϯάI/O •σʔλೖग़ྗ(I/O)͕ྃΛͨͣʹ ଞͷॲཧΛ։࢝͢Δํࣜͷ͜ͱ ϊϯϒϩοΩϯά ΠϕϯτϋϯυϥA ίʔϧόοΫA ΠϕϯτϋϯυϥB ίʔϧόοΫB ΰϘΰϘ νʔϯ ͓ࡼ ౬ͷΈ ͡Ό͕ ϨϯδԹΊ ͓ ίϯϩ౬͠ Πϕϯτϧʔϓ ϊϯϒϩοΩϯά
node.js ͷ͍ॴ
Αࣖ͘ʹ͢Δ •C10K •C clientɺ10K 10000 Λද͍ͯ͠·͢ɻ •ಉ࣌ʹଓ͢ΔΫϥΠΞϯτ͕ଟ͗͢ΔͱαʔόͷύϑΥʔϚϯε͕େ͖͘Լ͢ΔͰ͢ɻ •ϋʔυΣΞ͕ϘτϧωοΫͰͳ͘ιϑτΣΞʹ͕͋Γ·͢ɻ
•Apache ͱ nginx •Apache εϨουϞσϧͰ͢ɻ •ΫϥΠΞϯτ͔ΒͷϦΫΤετΛॲཧΛ͢Δͷʹ1ͭͷϓϩηε͕ඞཁͰ͢ɻ •ಉ࣌ʹॲཧ͢ΔϦΫΤετͷΛ૿͢ͱϓϩηεͷ૿͑ΔͷͰϝϞϦͷ༻ྔ૿Ճ͍͖ͯ͠·͢ɻ •nginx ΠϕϯτϧʔϓͰ͢ɻ •1ͭͷϓϩηεͰෳͷϦΫΤετΛѻ͏ͷͰϝϞϦͷ༻ྔ΄ͲΜͲ૿Ճ͠·ͤΜɻ •εϨουϞσϧେྔͷܭࢉॲཧ(CPUόϯυ)ʹ͍͍ͯ·͢ɻ •Πϕϯτϧʔϓେྔͷཁٻॲཧ(I/Oόϯυ)ͷωοτϫʔΫ ΞϓϦέʔγϣϯʹద͍ͯ͠·͢ɻ
ωοτϫʔΫΞϓϦέʔγϣϯͷࣄ •ϦΫΤετͱϨεϙϯε 1.ϦΫΤετΛड͚·͢ɻɹɹɹɹɹɹɹ→ɹnetwork read 2.σΟεΫ͔ΒίϯςϯπΛಡΈ·͢ɻɹ→ ɹdisk read 3.ϨεϙϯεΛฦ͠·͢ɻɹɹɹɹɹɹɹ→ɹnetwork write •ωοτϫʔΫ
ΞϓϦέʔγϣϯৗʹԿॲ͔Ͱread/write Λ ॲཧ͍ͯ͠·͢ɻ •read/write ඞͣ४උ͕ඞཁ͕ͦΕΒશͯϒϩοΫ͢Δͱ ϦΫΤετ͔ΒϨεϙϯεΛྃ͢Δ·Ͱʹ͕͔͔࣌ؒΓ·͢ɻ •node.js read/write ΛϒϩοΫ͠ͳ͍ɻ •ωοτϫʔΫ ΞϓϦέʔγϣϯͰߴ͍ύϑΥʔϚϯε͕ಘΒΕ·͢ɻ
ྲྀߦͱظ
JavaScript ͷಈ •JavaScript ͷීٴ •JSON •Web্ͷσʔλަϑΥʔϚοτ͕XML͔ΒJSONʹγϑτ͍ͯ͠·͢ɻ •HTML5 •ωοτϫʔΫ(Web Socket)ɺεϨου(Web Workers)ɺͳͲ
•HTML5ͷීٴ͢ΔͱɺJavaScript։ൃऀ͕૿Ճ͢ΔͱݴΘΕ͍ͯ·͢ɻ •υΩϡϝϯτσʔλϕʔε •CouchDB, MongoDB •JavaScriptͰͷΞΫηεΛڧ͘ҙ͍ࣝͯ͠·͢ɻ • JavaScript ։ൃऀͷ૿Ճ͕༧ଌ͞Ε·͢ɻ •࣮ߦڥ։ൃڥɾϑϨʔϜϫʔΫ͕͑ঘߋͰ͢ɻ •ࣄྫαϯϓϧίʔυͷྔ͕ JavaScript ͷར༻Λଅਐ͞Ε·͢ɻ
node.js ͷ͜Ε͔Β •node.js Λ࢝ΊΑ͏ •JavaScript ͰϓϩάϥϜΛهड़͢ΔͷͰෑډ͍Ͱ͢ɻ •socket.ioΛ͡ΊศརͳϥΠϒϥϦ͕ࢁ͋Γ·͢ɻ •npm registry Ͱެ։͞Ε͍ͯ·͢ɻ
•node.js ͷ PaaS ϩάσʔλϕʔεͳͲͷ SaaS ͕ ొ͓ͯ͠Γ؆୯ʹ࣮ߦڥ͕खʹೖΓ·͢ɻ ✤node.js ͕ϓϩάϥϛϯάΛ࢝ΊΔ ֻ͚ͬʹͳΕΑ͍ͳͱࢥ͍ͬͯ·͢ɻ enjoy node!
͋Γ͕ͱ͏͍͟͝·ͨ͠