62
2012. 2. 11 Outsider at OKJSP정기세미나

Node.js at OKJSP

Embed Size (px)

DESCRIPTION

2월 11일 OKJSP 정기세미나에서 발표한 발표자료입니다.

Citation preview

Page 1: Node.js at OKJSP

2012.����������� ������������������  2.����������� ������������������  11Outsider����������� ������������������  at����������� ������������������  OKJSP정기세미나

Page 2: Node.js at OKJSP

server-sideJavaScript

is

Page 3: Node.js at OKJSP

I����������� ������������������  expected����������� ������������������  itbecause

Netscape����������� ������������������  actuallywanted����������� ������������������  to����������� ������������������  do����������� ������������������  that.

Brendan����������� ������������������  Eich,����������� ������������������  CTO����������� ������������������  at����������� ������������������  Mozilla

Page 4: Node.js at OKJSP

Event-Loop

Page 5: Node.js at OKJSP

Application

Page 6: Node.js at OKJSP

Application

File����������� ������������������  System

Page 7: Node.js at OKJSP

Application

File����������� ������������������  System

Database

Page 8: Node.js at OKJSP

Application

File����������� ������������������  System

Database Network

Page 9: Node.js at OKJSP

Application

File����������� ������������������  System

Database Network

Page 10: Node.js at OKJSP

Application

File����������� ������������������  System

Database Network

Input/Output

Page 11: Node.js at OKJSP

L1

L2

RAM

DISK

Internet 80,000,000ns

13,700,000ns

83ns

4.7ns

1ns

http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait

I/O����������� ������������������  latency

Page 12: Node.js at OKJSP

����������� ������������������  var����������� ������������������  result����������� ������������������  =����������� ������������������  db.query('쿼리');

����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

Page 13: Node.js at OKJSP

����������� ������������������  var����������� ������������������  result����������� ������������������  =����������� ������������������  db.query('쿼리');

����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

db.query('쿼리',����������� ������������������  function(result)����������� ������������������  {

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

});

Page 14: Node.js at OKJSP

����������� ������������������  var����������� ������������������  result����������� ������������������  =����������� ������������������  db.query('쿼리');

����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

db.query('쿼리',����������� ������������������  function(result)����������� ������������������  {

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

});

Sync

Async

Page 15: Node.js at OKJSP

코드실행

Page 16: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

Page 17: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

코드실행

Page 18: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

코드실행

파일����������� ������������������  조회

Page 19: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

코드실행

파일����������� ������������������  조회

코드실행

Page 20: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

코드실행

파일����������� ������������������  조회

코드실행

코드실행

Page 21: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

코드실행

파일����������� ������������������  조회

코드실행

코드실행

DB����������� ������������������  조회

Page 22: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

코드실행

파일����������� ������������������  조회

코드실행

코드실행

DB����������� ������������������  조회

파일����������� ������������������  조회

Page 23: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

코드실행

파일����������� ������������������  조회

코드실행

코드실행

DB����������� ������������������  조회

파일����������� ������������������  조회

콜백실행

Page 24: Node.js at OKJSP

코드실행

DB����������� ������������������  조회

코드실행

파일����������� ������������������  조회

코드실행

코드실행

DB����������� ������������������  조회

파일����������� ������������������  조회

콜백실행 콜백실행

Page 25: Node.js at OKJSP

Sync

Async

코드실행

DB����������� ������������������  조회

코드실행

파일����������� ������������������  조회

코드실행

코드실행

DB����������� ������������������  조회

파일����������� ������������������  조회

콜백실행 콜백실행

Page 26: Node.js at OKJSP

var����������� ������������������  server����������� ������������������  =����������� ������������������  require('http');

server.createServer();

server.on('request',����������� ������������������  function(req,����������� ������������������  res)����������� ������������������  {

});

server.listen(3000,����������� ������������������  'localhost');

console.log('서버가����������� ������������������  시작되었습니다.');

Page 27: Node.js at OKJSP

var����������� ������������������  server����������� ������������������  =����������� ������������������  require('http');

server.createServer();

server.on('request',����������� ������������������  function(req,����������� ������������������  res)����������� ������������������  {

});

server.listen(3000,����������� ������������������  'localhost');

console.log('서버가����������� ������������������  시작되었습니다.');

코드����������� ������������������  실행

Page 28: Node.js at OKJSP

var����������� ������������������  server����������� ������������������  =����������� ������������������  require('http');

server.createServer();

server.on('request',����������� ������������������  function(req,����������� ������������������  res)����������� ������������������  {

});

server.listen(3000,����������� ������������������  'localhost');

console.log('서버가����������� ������������������  시작되었습니다.');

코드����������� ������������������  실행

이벤트리스너����������� ������������������  등록

Page 29: Node.js at OKJSP

var����������� ������������������  server����������� ������������������  =����������� ������������������  require('http');

server.createServer();

server.on('request',����������� ������������������  function(req,����������� ������������������  res)����������� ������������������  {

});

server.listen(3000,����������� ������������������  'localhost');

console.log('서버가����������� ������������������  시작되었습니다.');

코드����������� ������������������  실행

이벤트리스너����������� ������������������  등록

콜백����������� ������������������  실행

Page 30: Node.js at OKJSP

Everything����������� ������������������  is

Non-blocking����������� ������������������  I/O

Page 31: Node.js at OKJSP

����������� ������������������  var����������� ������������������  result����������� ������������������  =����������� ������������������  db.query('쿼리');

����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

db.query('쿼리',����������� ������������������  function(result)����������� ������������������  {

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

});

Page 32: Node.js at OKJSP

����������� ������������������  var����������� ������������������  result����������� ������������������  =����������� ������������������  db.query('쿼리');

����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

db.query('쿼리',����������� ������������������  function(result)����������� ������������������  {

����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  //����������� ������������������  result를����������� ������������������  사용한다.

});

Block

non-Block

Page 33: Node.js at OKJSP

JavaScript����������� ������������������  on����������� ������������������  V8

Page 34: Node.js at OKJSP

Single����������� ������������������  Thread

Single����������� ������������������  Stack

Page 35: Node.js at OKJSP

console.log('Hello����������� ������������������  World');

Hello����������� ������������������  World

Page 36: Node.js at OKJSP

setTimeout(function()����������� ������������������  {

����������� ������������������  ����������� ������������������  console.log('World');

},����������� ������������������  2000);

console.log('Hello');

Hello����������� ������������������  World

Page 37: Node.js at OKJSP

setTimeout(function()����������� ������������������  {

����������� ������������������  ����������� ������������������  console.log('World');

},����������� ������������������  2000);

console.log('Hello');

while(true)����������� ������������������  {}

Hello����������� ������������������  World

Page 38: Node.js at OKJSP

ev_loop()

node����������� ������������������  execution����������� ������������������  stack

Page 39: Node.js at OKJSP

ev_loop()node����������� ������������������  

execution����������� ������������������  stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 40: Node.js at OKJSP

ev_loop()

socket_readable(1)node����������� ������������������  

execution����������� ������������������  stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 41: Node.js at OKJSP

ev_loop()

socket_readable(1)

http_parse(1)

node����������� ������������������  execution����������� ������������������  

stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 42: Node.js at OKJSP

ev_loop()

socket_readable(1)

http_parse(1)

load(“index.html”)

node����������� ������������������  execution����������� ������������������  

stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 43: Node.js at OKJSP

ev_loop()

socket_readable(1)

http_parse(1)

node����������� ������������������  execution����������� ������������������  

stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 44: Node.js at OKJSP

ev_loop()

socket_readable(1)node����������� ������������������  

execution����������� ������������������  stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 45: Node.js at OKJSP

ev_loop()node����������� ������������������  

execution����������� ������������������  stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 46: Node.js at OKJSP

ev_loop()node����������� ������������������  

execution����������� ������������������  stack

메모리에����������� ������������������  대한����������� ������������������  ����������� ������������������  두번째����������� ������������������  요청

Page 47: Node.js at OKJSP

ev_loop()

socket_readable(2)node����������� ������������������  

execution����������� ������������������  stack

메모리에����������� ������������������  대한����������� ������������������  ����������� ������������������  두번째����������� ������������������  요청

Page 48: Node.js at OKJSP

ev_loop()

socket_readable(2)

http_parse(2)

node����������� ������������������  execution����������� ������������������  

stack

메모리에����������� ������������������  대한����������� ������������������  ����������� ������������������  두번째����������� ������������������  요청

Page 49: Node.js at OKJSP

ev_loop()

socket_readable(2)

http_parse(2)

http_respond(2)

node����������� ������������������  execution����������� ������������������  

stack

메모리에����������� ������������������  대한����������� ������������������  ����������� ������������������  두번째����������� ������������������  요청

Page 50: Node.js at OKJSP

ev_loop()

socket_readable(2)

http_parse(2)

node����������� ������������������  execution����������� ������������������  

stack

메모리에����������� ������������������  대한����������� ������������������  ����������� ������������������  두번째����������� ������������������  요청

Page 51: Node.js at OKJSP

ev_loop()

socket_readable(2)node����������� ������������������  

execution����������� ������������������  stack

메모리에����������� ������������������  대한����������� ������������������  ����������� ������������������  두번째����������� ������������������  요청

Page 52: Node.js at OKJSP

ev_loop()node����������� ������������������  

execution����������� ������������������  stack

메모리에����������� ������������������  대한����������� ������������������  ����������� ������������������  두번째����������� ������������������  요청

Page 53: Node.js at OKJSP

ev_loop()node����������� ������������������  

execution����������� ������������������  stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 54: Node.js at OKJSP

ev_loop()

file_loaded()node����������� ������������������  

execution����������� ������������������  stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 55: Node.js at OKJSP

ev_loop()

file_loaded()

http_respond(1)

node����������� ������������������  execution����������� ������������������  

stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 56: Node.js at OKJSP

ev_loop()

file_loaded()node����������� ������������������  

execution����������� ������������������  stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 57: Node.js at OKJSP

ev_loop()node����������� ������������������  

execution����������� ������������������  stack

index.html����������� ������������������  페이지����������� ������������������  요청

Page 58: Node.js at OKJSP

CommonJS

Page 59: Node.js at OKJSP

require('모듈명')

Page 60: Node.js at OKJSP

//����������� ������������������  app.jsvar����������� ������������������  app����������� ������������������  =����������� ������������������  module.exports����������� ������������������  =����������� ������������������  {};

//����������� ������������������  another.jsvar����������� ������������������  another����������� ������������������  =����������� ������������������  require('./app')

Page 61: Node.js at OKJSP
Page 62: Node.js at OKJSP

Questions...?

Blog����������� ������������������  :����������� ������������������  http://blog.outsider.ne.krTwitter����������� ������������������  :����������� ������������������  @outsiderisemail����������� ������������������  :[email protected]