what is nodejs

Post on 05-Dec-2014

18.293 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

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

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

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

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

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

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

Motivation

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

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

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

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

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

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

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

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

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

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

동시접속수

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

JavaScript

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

node.js

CouchDB

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ev_loop()

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

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

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

ev_loop()

socket_readable(1)

http_parse(1)

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

stack

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

ev_loop()

socket_readable(1)

http_parse(1)

load(“index.html”)

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

stack

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

ev_loop()

socket_readable(1)

http_parse(1)

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

stack

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

ev_loop()

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

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

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

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

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

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

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

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

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

ev_loop()

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

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

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

ev_loop()

socket_readable(2)

http_parse(2)

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

stack

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

ev_loop()

socket_readable(2)

http_parse(2)

http_respond(2)

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

stack

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

ev_loop()

socket_readable(2)

http_parse(2)

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

stack

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

ev_loop()

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

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

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

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

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

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

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

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

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

ev_loop()

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

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

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

ev_loop()

file_loaded()

http_respond(1)

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

stack

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

ev_loop()

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

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

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

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

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

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

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

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

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

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

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

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

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

node.js는

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

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

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

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

단점은?

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

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

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

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

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

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

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

sys.puts('hello');

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

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

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

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

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

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

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

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

//����������� ������������������  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);

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

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

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

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

node.js는

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

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

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

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

Questions...?

Blog����������� ������������������  :����������� ������������������  http://blog.outsider.ne.krTwitter����������� ������������������  :����������� ������������������  @outsider__email����������� ������������������  :outsideris@gmail.com

사진����������� ������������������  출처����������� ������������������  (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/

top related