Upgrade to Pro — share decks privately, control downloads, hide ads and more …

everyone node.js

ogom
October 13, 2011

everyone node.js

node.js 入門編

ogom

October 13, 2011
Tweet

More Decks by ogom

Other Decks in Programming

Transcript

  1. 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 ͰαʔόʔαΠυͷΞϓϦέʔγϣ ϯ͕࡞੒Ͱ͖·͢ɻ

  2. node.js ͍͍Ͷʂ •Πϕϯτϧʔϓ͸ߴ౓ͳύϑΥʔϚϯεΛཁٻ͞ΕΔ
 ωοτϫʔΫΞϓϦέʔγϣϯʹ࠷దͰ͢ɻ •ฒߦॲཧΛγϯάϧεϨουͰ͢ΔͨΊʹϊϯϒϩοΩϯάI/OͰඇಉظॲཧΛ࣮ݱ͍ͯ͠·͢ɻ
 ɹ(node.js ͸ฒߦॲཧʹΠϕϯτϧʔϓͱݺ͹ΕΔϞσϧΛ࠾༻͍ͯ͠·͢ɻ)
 •γϯάϧεϨου͸ϝϞϦͷফඅྔ͕গ͘
 ϋʔυ΢ΣΞͷίετΛ཈͑·͢ɻ •1ͭͷϓϩηεͰෳ਺ͷϦΫΤετΛѻ͏ͷͰϝϞϦྔ͸ΫϥΠΞϯτ਺ʹൺྫ͠·ͤΜɻ

    •γϯάϧεϨουͱϊϯϒϩοΩϯI/O͸ JavaScript ͱ૬ੑ͕Α͘
 ·ͨɺΫϩʔδϟ͕Πϕϯτۦಈͷ࢓૊ΈͷίʔϧόοΫʹͱͯ΋ศརͰ͢ɻ
 •ϑϩϯτΤϯυͷߏஙͰϝδϟʔͳ JavaScript Ͱ
 όοΫΤϯυͷॲཧΛߏஙͰ͖·͢ɻ •αʔόʔαΠυJavaScript ͱݴΘΕ͍ͯ·͢ɻ͞ΒʹɺϑϩϯτΤϯυͰख़Ε͍ͯΔ
 ΠϕϯτۦಈͷελΠϧ΋όοΫΤϯυͰར༻Ͱ͖·͢ɻ

  3. ΠϕϯτϧʔϓͱϊϯϒϩοΩϯάI/O •͝͸Μͷ༻ҙͰઆ໌͠·͢ɻ •ಠ਎ͷஉɿΠϕϯτϧʔϓ •ϨϯδͷԹΊɿΠϕϯτϋϯυϥA •νʔϯɿΠϕϯτϋϯυϥAͷίʔϧόοΫ •ίϯϩͰ౬෸͠ɿΠϕϯτϋϯυϥB •ΰϘΰϘɿΠϕϯτϋϯυϥBͷίʔϧόο Ϋ
 
 •Πϕϯτϧʔϓ

    •Πϕϯτ͕ൃੜͨ͠λΠϛϯάͰ
 ίʔϧόοΫͰݺͼग़͞ΕΔ࢓૊Έͷ͜ͱ •ϊϯϒϩοΩϯάI/O •σʔλೖग़ྗ(I/O)͕׬ྃΛ଴ͨͣʹ
 ଞͷॲཧΛ։࢝͢Δํࣜͷ͜ͱ ϊϯϒϩοΩϯά ΠϕϯτϋϯυϥA ίʔϧόοΫA ΠϕϯτϋϯυϥB ίʔϧόοΫB ΰϘΰϘ νʔϯ ͓ࡼ΁ ౬ͷΈ΁ ೑͡Ό͕ ϨϯδԹΊ ͓஡ ίϯϩ౬෸͠ Πϕϯτϧʔϓ ϊϯϒϩοΩϯά
  4. Αࣖ͘ʹ͢Δ࿩ •C10K໰୊ •C ͸ clientɺ10K ͸ 10000 Λද͍ͯ͠·͢ɻ •ಉ࣌ʹ઀ଓ͢ΔΫϥΠΞϯτ਺͕ଟ͗͢ΔͱαʔόͷύϑΥʔϚϯε͕େ͖͘௿Լ͢Δ໰୊Ͱ͢ɻ •ϋʔυ΢ΣΞ͕ϘτϧωοΫͰ͸ͳ͘ιϑτ΢ΣΞʹ໰୊͕͋Γ·͢ɻ


    •Apache ͱ nginx •Apache ͸εϨουϞσϧͰ͢ɻ •ΫϥΠΞϯτ͔ΒͷϦΫΤετΛॲཧΛ͢Δͷʹ1ͭͷϓϩηε͕ඞཁͰ͢ɻ •ಉ࣌ʹॲཧ͢ΔϦΫΤετͷ਺Λ૿΍͢ͱϓϩηεͷ਺΋૿͑ΔͷͰϝϞϦͷ࢖༻ྔ΋૿Ճ͍͖ͯ͠·͢ɻ
 •nginx ͸ΠϕϯτϧʔϓͰ͢ɻ •1ͭͷϓϩηεͰෳ਺ͷϦΫΤετΛѻ͏ͷͰϝϞϦͷ࢖༻ྔ͸΄ͲΜͲ૿Ճ͠·ͤΜɻ
 
 
 •εϨουϞσϧ͸େྔͷܭࢉॲཧ(CPUό΢ϯυ)ʹ޲͍͍ͯ·͢ɻ •Πϕϯτϧʔϓ͸େྔͷཁٻॲཧ(I/Oό΢ϯυ)ͷωοτϫʔΫ
 ΞϓϦέʔγϣϯʹద͍ͯ͠·͢ɻ
  5. ωοτϫʔΫΞϓϦέʔγϣϯͷ࢓ࣄ •ϦΫΤετͱϨεϙϯε 1.ϦΫΤετΛड͚·͢ɻɹɹɹɹɹɹɹ→ɹnetwork read 2.σΟεΫ͔ΒίϯςϯπΛಡΈ·͢ɻɹ→ ɹdisk read 3.ϨεϙϯεΛฦ͠·͢ɻɹɹɹɹɹɹɹ→ɹnetwork write
 •ωοτϫʔΫ

    ΞϓϦέʔγϣϯ͸ৗʹԿॲ͔Ͱread/write Λ
 ॲཧ͍ͯ͠·͢ɻ •read/write ͸ඞͣ४උ͕ඞཁ͕ͦΕΒશͯϒϩοΫ͢Δͱ
 ϦΫΤετ͔ΒϨεϙϯεΛ׬ྃ͢Δ·Ͱʹ͕͔͔࣌ؒΓ·͢ɻ
 •node.js ͸ read/write ΛϒϩοΫ͠ͳ͍ɻ •ωοτϫʔΫ ΞϓϦέʔγϣϯͰߴ͍ύϑΥʔϚϯε͕ಘΒΕ·͢ɻ
  6. JavaScript ͷಈ޲ •JavaScript ͷීٴ •JSON •Web্ͷσʔλަ׵ϑΥʔϚοτ͕XML͔ΒJSONʹγϑτ͍ͯ͠·͢ɻ •HTML5 •ωοτϫʔΫ(Web Socket)ɺεϨου(Web Workers)ɺͳͲ

    •HTML5ͷීٴ͢ΔͱɺJavaScript։ൃऀ͕૿Ճ͢ΔͱݴΘΕ͍ͯ·͢ɻ •υΩϡϝϯτσʔλϕʔε •CouchDB, MongoDB •JavaScriptͰͷΞΫηεΛڧ͘ҙ͍ࣝͯ͠·͢ɻ
 • JavaScript ։ൃऀͷ૿Ճ͕༧ଌ͞Ε·͢ɻ •࣮ߦ؀ڥ΍։ൃ؀ڥɾϑϨʔϜϫʔΫ͕੔͑͹ঘߋͰ͢ɻ •ࣄྫ΍αϯϓϧίʔυͷྔ͕ JavaScript ͷར༻Λଅਐ͞Ε·͢ɻ
  7. node.js ͷ͜Ε͔Β •node.js Λ࢝ΊΑ͏ •JavaScript ͰϓϩάϥϜΛهड़͢ΔͷͰෑډ͸௿͍Ͱ͢ɻ •socket.ioΛ͸͡ΊศརͳϥΠϒϥϦ͕୔ࢁ͋Γ·͢ɻ •npm registry Ͱެ։͞Ε͍ͯ·͢ɻ

    •node.js ͷ PaaS ΍ϩά΍σʔλϕʔεͳͲͷ SaaS ͕
 ొ৔͓ͯ͠Γ؆୯ʹ࣮ߦ؀ڥ͕खʹೖΓ·͢ɻ
 ✤node.js ͕ϓϩάϥϛϯάΛ࢝ΊΔ
 ੾ֻ͚ͬʹͳΕ͹Α͍ͳͱࢥ͍ͬͯ·͢ɻ enjoy node!