node.js – serverside javascript

Post on 30-Dec-2015

59 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Node.js – Serverside Javascript. Maciej Jastrzębski. Czym jest Node.js Into the code Asynchroniczne I/O i Event Driven server Wydajność?! Node.js vs obecne rozwiązania. cross-platform & cross-device Client side. PaaS. SaaS. IaaS. cross-platform & cross-device Client side. - PowerPoint PPT Presentation

TRANSCRIPT

Node.js – Serverside Javascript

Maciej JastrzębskiKraków, 8 października 2011

• Czym jest Node.js• Into the code• Asynchroniczne I/O i Event Driven server• Wydajność?!• Node.js vs obecne rozwiązania

cross-platform & cross-device

Client side

PaaS

SaaS

IaaS

cross-platform & cross-device

Client side

PaaS

SaaS

IaaS

Czym jest Node.js?

Czym jest Node.js

V8

Środowisko Node.js

• V8 runtime (EcmaScript5) • Event Driven i Asynchroniczne I/O• process zamiast window!• System modułów i require (CommonJS)• Zestaw modułów natywnych• Wsparcie dla dodatków opartych o C/C++

File system

var fs = require('fs');

//synchronicznievar content = fs.readFileSync('example.txt');

//asynchroniczniefs.readFile('example.txt', function (err, data) { if (err) throw err; console.log(data);});

Server

var http = require('http');var url = require('url');

var status = "none";

http.createServer(function (req, res) { //ustawiamy nowy status var params = url.parse(req.url, true); if(params.hasOwnProperty('set_status')){ status = params['set_status']; } //zwracamy aktualny status res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(status);}).listen(80, "127.0.0.1");

setTimeout – raz jeszcze.

setTimeout(function(){ //pobierz dane z miejsca A}, 3000);

setTimeout(function(){ //pobierz dane z miejsca B}, 8000);

Nowy wymiar asynchroniczności Javascript.

Asynchroniczne I/O

Node.js

Server

GET http://example.com/index.html

Kolejka

Exec

GET http://example.com/hello.html

Asynchroniczne I/O

Node.js

Server

Kolejka

Exec

Asynchroniczne I/O

Node.js

Server

Kolejka

Exec

Asynchroniczne I/O

Node.js

Server

Kolejka

Exec

Asynchroniczne I/O

Node.js

Server

HTTP/1.1 200 OK

Kolejka

Exec

Asynchroniczne I/O

Node.js

Server

Kolejka

Exec

Asynchroniczne I/O

Node.js

Server

HTTP/1.1 200 OK

Kolejka

Exec

Nowy wymiar asynchroniczności Javascript.

Wydajność!

0

500

1000

1500

2000

2500

3000

3500

4000

4500

Req/sec

Request/second

Komercyjne zastosowanie i duże projekty.

npmjs.org

Ale…

Dziękuję za uwagę.

top related