Node.jsの非同期とI/Oについて調べてみた

33ef4c1ebe619115b552db9a9f9a3509?s=47 sadnessOjisan
December 09, 2019

 Node.jsの非同期とI/Oについて調べてみた

33ef4c1ebe619115b552db9a9f9a3509?s=128

sadnessOjisan

December 09, 2019
Tweet

Transcript

  1. Node.js I/O    Node.js    

    Ginza.js#7 @PLAID Yuta Ide(@sadnessOjisan)
  2. Yuta Ide ( ) @sadnessOjisan (Twitter, Github, Qiita)

  3.       

  4. Node.js

  5.  

  6.      

  7.          

  8. Node.js  •  •  I/O • ( 

    )
  9.    

  10.         A B

    C 
  11.   " !  #   $ 

  12.     1     A

  13. 

  14.        

  15. C10K

  16. Node.js    

  17.        

  18.   •    •   •

        • 
  19.       A B C

  20.    B A C   

  21.     

  22.         B A

    C  
  23.   I/O

  24. I/O  app  

  25. I/O   • to RAM < to Disk •

      network
  26. I/O    B A C   

  27. I/O  I/O

  28.     I/O

  29.       I/O

  30.  Node.js  

  31. Node.js     I/O

  32.   I/O  AI/O    *0͕ൃੜͯ͠΋ɺޙଓॲཧ Λߦ͏ɻ*0׬ྃޙʹ΋ͱ΋

    ͱ΍Γ͔ͨͬͨॲཧΛߦ͏  A
  33.   Node.js 

  34.   I/O  • I/O  •  

    
  35. I/O       https://www.packtpub.com/web- development/nodejs-design-patterns

  36. Busy Wait Pattern • Bad    • While

     
  37.  I/O  

  38. Reactor Pattern https://subscription.packtpub.com/book/web_development/9781 783287314/1/ch01lvl1sec09/the-reactor-pattern

  39.  https://subscription.packtpub.com/book/web_development/9781 783287314/1/ch01lvl1sec09/the-reactor-pattern ͳΜ͔Χοί͍͍ʂʂʂ

  40. Demulti plexier I/O    

  41. Event queue I/O    

  42. Event loop Queue 

  43.    

  44. 

  45.   queue  OS   

  46. Kqueue https://nxmnpg.lemoda.net/ja/2/kqueue man

  47.  EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD, NOTE_WRITE, 0, NULL); ret =

    kevent(kq, &kev, 1, NULL, 0, NULL); https://github.com/sadnessOjisan/kqueue_fileio  
  48.   Node.js 

  49.   Node.js     OS  

  50. 

  51. MacFile I/O  • Mac OS

  52. libuv •    I/O  • OS 

  53.     !

  54. libuv • I/OOS •   •   

  55. Q:  Node.js  

  56. A:  http://docs.libuv.org/en/v1.x/design.html

  57. 

  58. Default loop http://docs.libuv.org/en/v1.x/guide/basics.html

  59. Wather  http://docs.libuv.org/en/v1.x/guide/basics.html Node

  60. Call back http://docs.libuv.org/en/v1.x/guide/basics.html 

  61. I/O  

  62.  https://www.slideshare.net/saghul/libuv-nodejs-and-everything-in-between GTSFBE'JMF &7@4&5

  63.  https://www.slideshare.net/saghul/libuv-nodejs-and-everything-in-between Կ΋৮Ε͍ͯ ͳ͍

  64. Node.jslibuv      

  65.     

  66. 

  67.   

  68.          

      N o d e. js 
  69.  https://www.slideshare.net/saghul/libuv-nodejs-and-everything-in-between $ ΁ͷόΠ ϯσΟϯά $PEF δϟϯϓ ͍ͨ͠

  70.  https://www.slideshare.net/saghul/libuv-nodejs-and-everything-in-between $ ΁ͷόΠ ϯσΟϯά $PEF δϟϯϓ ͍ͨ͠ ͭΒ͍

  71. fs.readFile https://www.slideshare.net/saghul/libuv-nodejs-and-everything-in-between "TZOD3FBEͳ ʹͯ͠Δͷʁ ˞͜Ε͸·ͩɺ ௥͑͹Θ͔Δ

  72. node-main.cc https://www.slideshare.net/saghul/libuv-nodejs-and-everything-in-between MJCVW΁ͷ XBUDIFS͸Ͳ ͜Ͱఆٛʁ

  73. Node https://juejin.im/post/5dd0b1fff265da0bae519ed4 ˞தࠃޠͷυΩϡϝ ϯτΛ(PPHMF຋༁ ͯ͠ಡΜͰΔ

  74. Ginza.js  ଟ෼͜ͷลʹ͍Δ

  75.  Ginza.js   ଟ෼͜ͷลʹ͍Δ    mm

  76.  • Node.js " C10K%() • .' 0 I/O-$ 

    • -$I/O & OS # */,!libuv+
  77.  • 12/23   •