NodeJS overview

11
NodeJS

description

NodeJS flashcards

Transcript of NodeJS overview

Page 1: NodeJS overview

NodeJS

Page 2: NodeJS overview

Milestones

● Server-side Javascript based on Google V8

● Non-blocking Input/Output event model

● 100% CPU using: one process - one thread - one core

Page 3: NodeJS overview

Google V8

● V8 JavaScript VM is used in Google Chrome

● No JIT, all JavaScript is compiled to assembler

● Hidden classes optimization from Self (V8 does not dynamically lookup access properties, instead it uses hidden classes that are created behind the scene)

● Improved garbage collector

Page 4: NodeJS overview

Non-blocking I/O

The non-blocking nature makes node.js a good fit for comet and next generation realtime web-applications

nginx: non-blockingapache: threadednon-blocking can handle more requests-per-second and uses a lot less memory

Page 5: NodeJS overview

NodeJS Perks: front- and backend

● One Javascript - different approaches

● Common libs

● Unit-tests for both sides

Page 6: NodeJS overview

NodeJS Perks: Frameworks

Native example:

var http = require('http');http.createServer(function (req, res) {

res.writeHead(200, {'Content-Type': 'text/plain'

});res.end('Hello World\n');

}).listen(3000, '127.0.0.1');

ExpressJS:

var app = express.createServer();app.get('/', function(req, res){

res.send('Hello World');});app.listen(3000);

Page 7: NodeJS overview

NodeJS Perks: Comet

Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it.

● Comet servers need to have a lot of open connections● One thread-per-connection does not scale● The solution is to use event based servers● It’s only possible to create event based servers in

node.js

Page 8: NodeJS overview

NodeJS Weaknesses

● Due to Javascript flexible nature it's hard to locate mistakes

● Strict convention rules are highly recommended

● One process serve plenty requests: so, mistake in one request may "freeze" other.

● Non-trivial garbage collector (closures, long-term processes)

● Strange open-source community (no standards)

● No backward compatibility

Page 9: NodeJS overview

NodeJS Scalability

Page 10: NodeJS overview

NodeJS Scalability