Date post: | 02-Jul-2015 |
Category: |
Documents |
Upload: | jeonghoon-byun |
View: | 3,735 times |
Download: | 3 times |
Introducingto node.js
2011.01.06HTML5 AG
Outsider
node.js is Server-side JavaScript
"Node looks like yet another take on the idea of server-side
JavaScript, but it's a lot more interesting
than that."
simon willison
CommonJS
started by Kevin DangoorJanuary 2009first named ServerJS renamed in August 2009http://www.commonjs.org/
JavaScript: not just for browsers any more!
"What I’m describing here is not a technical problem. It’s a matter of
people getting together and making a decision to step forward and start
building up something bigger and cooler together."
Kevin Dangoor
Specifications
ModulesSystemFilesystemUnit Testing....
Implementations
CouchDBRingoJS SproutCore node.js
node.js
history
creator : Ryan Dahl09.02.09 - V8 에 기반한 프로젝트
아이디어에 대한 글 을 올림09.02.15 - Github 에 프로젝트 시작09.11.08 - JSConf.eu 2009 발표(v0.1.16)
현재 - v0.2.6, 0.3.3
Motivation
Event Loop& non-blocking I/O
I/O 는 다르게 수행되어야 한
다 .
var result = db.query('select * from A')// use result
Why waiting?????
I/O latency
L1 : 3 cyclesL2 : 14 cyclesRAM : 250 cycles-------------------------------------------DISK : 41,000,000 cyclesNETWORK : 240,000,000 cycles
non-blocking
blocking
Apache vs NginX
Apache vs NginX
Single Thread Event loop
is better.
db.query('select * from A', function(result) { // use result});
왜 모두 event loop 를
사용하지 않는가 ???
Cultural & Infrastructual
Cultural
우리가 I/O 를 그렇게 배웠다
Cultural
puts('Enter your name : ');var neme = gets();puts('your name : ' + name);
Cultural
puts('Enter your name : ');gets(function (name) { puts('your name : ' + name);});
너무 복잡해서 사용안함 .
Infrastructual
single thread event loop 는non-blocking I/O 가 필요하다 .
Infrastructual
현재는 많은 인프라가 갖추어져 있다 .: Twisted, eventmachine
하지만 다른 라이브러리랑 섞어서 사용하 기가 어렵다 .
사용자가 event loop 와 non-blocking I/O 에 대한 전문 지식이 필요하다
Enter JavaScript
JavaScript
event loop 를 사용하도록 디자 인 되었다
익명함수와 클로져 한번의 하나의 콜백
DOM 이벤트 콜백을 통한 I/O 성능을 위한 확장경쟁이 붙었다 (Google,
Mozilla, Apple, Opera, MS)
node.jsa set of bindings to V8 JavaScript for scripting network programs
Features
evented Server-side JavaScriptbuilt on Google V8CommonJS module systemC 기반 , C AddonGreen Thread : one thread, one stackasyncounous, non-blocking 인터페이스
만 노출한다 펑션은 직접 I/O 에 접근하지 않는다 .
AdvantagesHigh-performance, FastRealtime App 에 좋다 .
다른 기술과 섞어 쓸 수 있다 .JavaScript 는 실제로 유니버셜랭귀지이다easy to Start
100 concurrent clients1 megabyte response
node 822 req/secnginx 708thin 85mongrel 4(bigger is better)
DisadvantagesMemory IssuesScale problems to Multiple CPUs or Data CenterToo Young
"Node.js Is Too Cool To Ignore"
Dustin McQuay
Usagesfrom ryannode.js v0.2.5
// 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);});
// simplehttp.jsvar http = require('http');
http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end('Hello World\n');}).listen(8000);
// 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 is ready?
"nodejs is awesome because it makes me
feel smart." Tobie Lagel