what is nodejs

82
SpringSprout Swagger 2011.01.29 Outsider What is

Upload: outsider-byun

Post on 05-Dec-2014

18.293 views

Category:

Technology


4 download

DESCRIPTION

봄싹 스웨거에서 발표한 node.js 발표자료

TRANSCRIPT

Page 1: What is nodejs

SpringSprout����������� ������������������  Swagger2011.01.29Outsider

What����������� ������������������  is

Page 2: What is nodejs
Page 3: What is nodejs
Page 4: What is nodejs
Page 5: What is nodejs

node.js����������� ������������������  is����������� ������������������  Server-side����������� ������������������  JavaScript

Page 6: What is nodejs

노드가����������� ������������������  아직은����������� ������������������  서버사이드����������� ������������������  자바스크립트의����������� ������������������  개념을����������� ������������������  취한����������� ������������������  많은����������� ������������������  것들����������� ������������������  중����������� ������������������  하나로����������� ������������������  보이지만����������� ������������������  그것들보다����������� ������������������  훨씬����������� ������������������  흥미롭다.

Simon����������� ������������������  Willison

http://simonwillison.net/2009/Nov/23/node/

Page 7: What is nodejs

Motivation

Page 8: What is nodejs

I/O는����������� ������������������  다르게����������� ������������������  수행되어야����������� ������������������  한다.

Page 9: What is nodejs

var����������� ������������������  result����������� ������������������  =����������� ������������������  db.query('select����������� ������������������  *����������� ������������������  from����������� ������������������  A')//����������� ������������������  use����������� ������������������  result

Page 10: What is nodejs

var����������� ������������������  result����������� ������������������  =����������� ������������������  db.query('select����������� ������������������  *����������� ������������������  from����������� ������������������  A')//����������� ������������������  use����������� ������������������  result

왜����������� ������������������  기다려야����������� ������������������  하는가?

Page 11: What is nodejs

L1

L2

RAM

DISK

Internet

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

80,000,000ns

13,700,000ns

83ns

4.7ns

1ns

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

Page 12: What is nodejs

싱글쓰레드를����������� ������������������  이용한����������� ������������������  

Event����������� ������������������  Loop가����������� ������������������  더����������� ������������������  낫다

Page 13: What is nodejs

db.query('select����������� ������������������  *����������� ������������������  from����������� ������������������  A',����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  function(result)����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  //����������� ������������������  use����������� ������������������  result����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  });

Page 14: What is nodejs

0

3,000

6,000

9,000

12,000

0 500 1000 1500 2000 2500 3000 3500 4000

nginx

apache

http://blog.webfaction.com/a-little-holiday-present

동시접속수에����������� ������������������  따른����������� ������������������  초당����������� ������������������  리퀘스트����������� ������������������  처리수

동시접속수

초당����������� ������������������  리퀘스트

Page 15: What is nodejs

0

10

20

30

40

0 500 1000 1500 2000 2500 3000 3500 4000

nginx

apache

http://blog.webfaction.com/a-little-holiday-present

동시접속수에����������� ������������������  따른����������� ������������������  메모리����������� ������������������  사용량

동시접속수

MB

Page 16: What is nodejs

왜����������� ������������������  모두����������� ������������������  Event����������� ������������������  Loop를����������� ������������������  사용하지����������� ������������������  않는가?

Page 17: What is nodejs
Page 18: What is nodejs

문화적인����������� ������������������  이유

Page 19: What is nodejs

우리가����������� ������������������  I/O를����������� ������������������  그렇게����������� ������������������  배웠다

Page 20: What is nodejs

puts('이름을����������� ������������������  입력하세요����������� ������������������  :����������� ������������������  ');

var����������� ������������������  neme����������� ������������������  =����������� ������������������  gets();

puts('이름����������� ������������������  :����������� ������������������  '����������� ������������������  +����������� ������������������  name);

Page 21: What is nodejs

puts('이름을����������� ������������������  입력하세요����������� ������������������  :����������� ������������������  ');

gets(function����������� ������������������  (name)����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  puts('이름����������� ������������������  :����������� ������������������  '����������� ������������������  +����������� ������������������  name);});

어렵다����������� ������������������  어려워

Page 22: What is nodejs

인프라적인����������� ������������������  이유

Page 23: What is nodejs

Single����������� ������������������  Thread����������� ������������������  Event����������� ������������������  Loop는����������� ������������������  

non-blocking����������� ������������������  I/O가����������� ������������������  필요하다.

Page 24: What is nodejs

대부분의����������� ������������������  라이브러리가

non-blocking����������� ������������������  I/O를����������� ������������������  

지원하지����������� ������������������  않았다

Page 25: What is nodejs

현재는����������� ������������������  많은����������� ������������������  인프라가����������� ������������������  갖추어져����������� ������������������  있다.

예:����������� ������������������  Twisted,����������� ������������������  eventmachine

Page 26: What is nodejs

블락킹����������� ������������������  I/O와넌블락킹����������� ������������������  I/O를섞어서����������� ������������������  

사용하는����������� ������������������  것이어렵다

Page 27: What is nodejs

Event����������� ������������������  Loop와����������� ������������������  non-blocking����������� ������������������  I/O에����������� ������������������  대한����������� ������������������  전문����������� ������������������  지식이����������� ������������������  필요하다

Page 28: What is nodejs

JavaScript

Page 29: What is nodejs

유니버셜����������� ������������������  랭귀지

Page 30: What is nodejs

Event����������� ������������������  Loop를����������� ������������������  

사용하도록����������� ������������������  

디자인����������� ������������������  되었다

Page 31: What is nodejs

성능을����������� ������������������  위한����������� ������������������  경쟁이����������� ������������������  붙었다

Page 32: What is nodejs

이제����������� ������������������  다시....

Page 33: What is nodejs

Ryan����������� ������������������  Dahl

09.02.09V8에����������� ������������������  기반한����������� ������������������  프로젝트����������� ������������������  아이디어에����������� ������������������  대한����������� ������������������  글을����������� ������������������  올림����������� ������������������  

09.02.15Github에����������� ������������������  프로젝트����������� ������������������  시작

09.11.08JSConf.eu����������� ������������������  2009����������� ������������������  발표(v0.1.16)

11.01현재����������� ������������������  -����������� ������������������  v0.2.6,����������� ������������������  0.3.7

Page 34: What is nodejs

CommonJS����������� ������������������  기반

Page 35: What is nodejs

JavaScript는����������� ������������������  더이상����������� ������������������  브라우저를����������� ������������������  위한����������� ������������������  것이����������� ������������������  아니다.

CommonJS����������� ������������������  기반

Page 36: What is nodejs

Kevin����������� ������������������  Dangoor가����������� ������������������  만든����������� ������������������  웹브라우저����������� ������������������  이외의����������� ������������������  환경에서����������� ������������������  

JavaScript를����������� ������������������  사용하기����������� ������������������  위한����������� ������������������  스펙

Modules,����������� ������������������  System,����������� ������������������  Filesystem,����������� ������������������  Unit����������� ������������������  Testing

CommonJS����������� ������������������  기반

Page 37: What is nodejs

node.js

CouchDB

RingoJS����������� ������������������  

SproutCore����������� ������������������  

CommonJS����������� ������������������  기반

Page 38: What is nodejs

V8����������� ������������������  위에서����������� ������������������  동작

Page 39: What is nodejs

C/C++����������� ������������������  애드온

Page 40: What is nodejs

직접����������� ������������������  짠����������� ������������������  코드외에는

모두����������� ������������������  비동기

Page 41: What is nodejs

모두����������� ������������������  

non-blocking����������� ������������������  I/O

Page 42: What is nodejs

단����������� ������������������  하나의����������� ������������������  쓰레드

단����������� ������������������  하나의����������� ������������������  스택

Page 43: What is nodejs

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

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

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

Page 44: What is nodejs

ev_loop()

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

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

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

Page 45: What is nodejs

ev_loop()

socket_readable(1)

http_parse(1)

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

stack

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

Page 46: What is nodejs

ev_loop()

socket_readable(1)

http_parse(1)

load(“index.html”)

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

stack

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

Page 47: What is nodejs

ev_loop()

socket_readable(1)

http_parse(1)

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

stack

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

Page 48: What is nodejs

ev_loop()

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

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

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

Page 49: What is nodejs

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

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

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

Page 50: What is nodejs

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

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

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

Page 51: What is nodejs

ev_loop()

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

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

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

Page 52: What is nodejs

ev_loop()

socket_readable(2)

http_parse(2)

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

stack

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

Page 53: What is nodejs

ev_loop()

socket_readable(2)

http_parse(2)

http_respond(2)

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

stack

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

Page 54: What is nodejs

ev_loop()

socket_readable(2)

http_parse(2)

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

stack

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

Page 55: What is nodejs

ev_loop()

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

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

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

Page 56: What is nodejs

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

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

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

Page 57: What is nodejs

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

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

index.html����������� ������������������  요청에����������� ������������������  대한����������� ������������������  응답

Page 58: What is nodejs

ev_loop()

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

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

index.html����������� ������������������  요청에����������� ������������������  대한����������� ������������������  응답

Page 59: What is nodejs

ev_loop()

file_loaded()

http_respond(1)

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

stack

index.html����������� ������������������  요청에����������� ������������������  대한����������� ������������������  응답

Page 60: What is nodejs

ev_loop()

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

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

index.html����������� ������������������  요청에����������� ������������������  대한����������� ������������������  응답

Page 61: What is nodejs

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

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

index.html����������� ������������������  요청에����������� ������������������  대한����������� ������������������  응답

Page 62: What is nodejs

����������� ������������������  무엇이����������� ������������������  좋은가

?����������� ������������������  

Page 63: What is nodejs

성능이����������� ������������������  좋고����������� ������������������  ����������� ������������������  빠르다

Page 64: What is nodejs

Realtime����������� ������������������  App에����������� ������������������  좋다

Page 65: What is nodejs

100����������� ������������������  동시접속에����������� ������������������  1MB����������� ������������������  응답

node����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  822����������� ������������������  req/secnginx����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  708����������� ������������������  req/secthin����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  85����������� ������������������  req/secmongrel����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  4����������� ������������������  req/sec

(클수록����������� ������������������  좋다)

http://chetansurpur.com/blog/2010/10/why-node-js-is-totally-awesome.html

Page 66: What is nodejs

다른����������� ������������������  기술과����������� ������������������  함께����������� ������������������  쓸����������� ������������������  수����������� ������������������  있다

Page 67: What is nodejs

시작하기가����������� ������������������  쉽

Page 68: What is nodejs

node.js는

내가����������� ������������������  똑똑한����������� ������������������  것처럼����������� ������������������  

느끼게����������� ������������������  만들어����������� ������������������  준다

Tobie����������� ������������������  Lagel

http://twitter.com/#!/tobie/status/8975802142031872

Page 69: What is nodejs

단점은?

Page 70: What is nodejs

아직����������� ������������������  어리다

Page 71: What is nodejs

멀티����������� ������������������  CPU����������� ������������������  /����������� ������������������  데이터센터간의����������� ������������������  

확장성����������� ������������������  문제

Page 72: What is nodejs

간단한����������� ������������������  예제들from����������� ������������������  ryan

node.js����������� ������������������  v0.2.6

Page 73: What is nodejs

//����������� ������������������  helloworld.jsvar����������� ������������������  sys����������� ������������������  =����������� ������������������  require('sys')

setTimeout(����������� ������������������  function()����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  sys.puts('world');},����������� ������������������  2000);

sys.puts('hello');

Page 74: What is nodejs

//����������� ������������������  forever_helloworld.jsvar����������� ������������������  puts����������� ������������������  =����������� ������������������  require('sys').puts;

setInterval(function()����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  puts('hello');},����������� ������������������  500);

process.on('SIGINT',����������� ������������������  function()����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  puts('good-bye');����������� ������������������  ����������� ������������������  ����������� ������������������  process.exit(0);});

Page 75: What is nodejs

//����������� ������������������  tcp.jsvar����������� ������������������  tcp����������� ������������������  =����������� ������������������  require('net');

var����������� ������������������  server����������� ������������������  =����������� ������������������  tcp.createServer();

server.on('connection',����������� ������������������  function(e)����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  e.write('hello!\n');����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  e.end();});server.listen(8000);

Page 76: What is nodejs

//����������� ������������������  fileio.jsvar����������� ������������������  stat����������� ������������������  =����������� ������������������  require('fs').stat,����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  puts����������� ������������������  =����������� ������������������  require('sys').puts;

stat('/etc/passwd',����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  function(err,����������� ������������������  data)����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  if����������� ������������������  (err)����������� ������������������  throw����������� ������������������  err;����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  puts('modified����������� ������������������  :'����������� ������������������  +����������� ������������������  data.mtime);����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  });

Page 77: What is nodejs

//����������� ������������������  streamhttp.jsvar����������� ������������������  http����������� ������������������  =����������� ������������������  require('http');

http.createServer(function(req,����������� ������������������  res)����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  res.writeHead(200,����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  {'Content-Type':����������� ������������������  'text/html'});����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  res.write('Hello����������� ������������������  \n');����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  setTimeout(function()����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  res.write('world!\n');����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  res.end();����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  },����������� ������������������  2000);}).listen(8000);

Page 78: What is nodejs

//����������� ������������������  watchfile.jsvar����������� ������������������  fs����������� ������������������  =����������� ������������������  require('fs'),����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  puts����������� ������������������  =����������� ������������������  require('sys').puts;

fs.watchFile('./test.txt',����������� ������������������  function()����������� ������������������  {����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  puts('파일을����������� ������������������  바꾸셨군요.');����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  process.exit(0);});

Page 79: What is nodejs

node.js는����������� ������������������  서비스할����������� ������������������  

준비가����������� ������������������  되었는가?

Page 80: What is nodejs

node.js는

무시하기에는����������� ������������������  

너무����������� ������������������  쿨하다

Dustin����������� ������������������  McQuay

http://www.synchrosinteractive.com/blog/9-nodejs/22-nodejs-has-a-bright-future

Page 81: What is nodejs

Questions...?

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

Page 82: What is nodejs

사진����������� ������������������  출처����������� ������������������  (under����������� ������������������  CCL)

http://www.flickr.com/photos/41534655@N00/220318384/

http://www.flickr.com/photos/blank22763/4089949526/

http://www.flickr.com/photos/arthurjohnpicton/4383221264/

http://www.flickr.com/photos/75898532@N00/3110092806/

http://www.flickr.com/photos/f-l-e-x/3092386087/

http://www.flickr.com/photos/chefranden/4596604619/

http://www.flickr.com/photos/tjook/5111553020/

http://www.flickr.com/photos/franksvalli/5163205409/

http://www.flickr.com/photos/rawryder/5086090931/

http://www.flickr.com/photos/elvinj/4487097018/

http://www.flickr.com/photos/ramdac/373881476/

http://www.flickr.com/photos/gregw/3592153959/