Download - Introduzione a node: cenni storici ecc
![Page 1: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/1.jpg)
NODE.JSUna breve introduzione
Wednesday, May 22, 13
![Page 2: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/2.jpg)
@unlucio
CIAO! :)
Wednesday, May 22, 13
![Page 3: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/3.jpg)
INDICE DEL CORSOCORE
• Introduzione su node
• Installazione
• Struttura base di un progetto
• npm
• Hands on: Esempi di funzionalita’ di base
• Hands on: Esempi di piccole applicazioni
Wednesday, May 22, 13
![Page 4: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/4.jpg)
INDICE DEL CORSOEXPRESS
• Installazione
• Generazione di un progetto
• Routes
• Views
•Middle wares
• Sessions and Error Handling
Wednesday, May 22, 13
![Page 5: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/5.jpg)
Benvenuti
Wednesday, May 22, 13
![Page 6: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/6.jpg)
INDEX
• Cos’e’ Node.js
• Come e perche’ nasce
• Async e Next Tick
• Esempi di architettura in cui usarlo
Wednesday, May 22, 13
![Page 7: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/7.jpg)
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and
efficient, perfect for data-intensive real-time applications that run across distributed devices.
Current Version: v0.8.21
Wednesday, May 22, 13
![Page 8: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/8.jpg)
RYAN DAHLnode.js creator
anno: 2009Wednesday, May 22, 13
![Page 9: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/9.jpg)
RYAN DAHL
Studente in Matematica
Si trasferisce in Sud America
Incontra un programmatore php
Inizia a sviluppare siti ed “applicazioni” web
Incontra ROR
Si accorge che il Web e’ lento!
Wednesday, May 22, 13
![Page 10: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/10.jpg)
Il Web e’ lento!
Per via di Java ;)
Wednesday, May 22, 13
![Page 11: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/11.jpg)
Il Web e’ lento!
Per via di Java ;)
Alcuni cominciano a lavorare per velocizzare ROR
Wednesday, May 22, 13
![Page 12: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/12.jpg)
Il Web e’ lento!
Per via di Java ;)
Alcuni cominciano a lavorare per velocizzare ROR
Ma il problema risiede nell’intero stack
Wednesday, May 22, 13
![Page 13: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/13.jpg)
Il Web e’ lento!
Per via di Java ;)
Alcuni cominciano a lavorare per velocizzare ROR
Ma il problema risiede nell’intero stack
Il lavoro di Zed Shaw da vita a Mongel
Wednesday, May 22, 13
![Page 14: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/14.jpg)
Mongrel
Per via di Java ;)
Wednesday, May 22, 13
![Page 15: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/15.jpg)
Mongrel
Per via di Java ;)
E’ sia una libreria http, sia un webserver!
Wednesday, May 22, 13
![Page 16: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/16.jpg)
Mongrel
Per via di Java ;)
E’ sia una libreria http, sia un webserver!
Il web server non e’ piu’ solo “una directory “
Wednesday, May 22, 13
![Page 17: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/17.jpg)
Mongrel
Per via di Java ;)
E’ sia una libreria http, sia un webserver!
Il web server non e’ piu’ solo “una directory “
Puo’ racchiudere direttamente la logica
Wednesday, May 22, 13
![Page 18: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/18.jpg)
Il Web Server
Per via di Java ;)
Wednesday, May 22, 13
![Page 19: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/19.jpg)
Il Web Server
Per via di Java ;)
Distillato, e’ fatto per gestire richieste e risposte
Wednesday, May 22, 13
![Page 20: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/20.jpg)
Il Web Server
Per via di Java ;)
Distillato, e’ fatto per gestire richieste e risposte
Servire files e’ una parte ma non e’ obbligatoria
Wednesday, May 22, 13
![Page 21: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/21.jpg)
THE FILE UPLOAD PROBLEM
Wednesday, May 22, 13
![Page 22: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/22.jpg)
THE FILE UPLOAD PROBLEMCaricare files via http non era poi cosi’ comune
Wednesday, May 22, 13
![Page 23: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/23.jpg)
THE FILE UPLOAD PROBLEMCaricare files via http non era poi cosi’ comune
Con la nascita di Ajax si cominciavano a caricare VIDEO!
Wednesday, May 22, 13
![Page 24: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/24.jpg)
THE FILE UPLOAD PROBLEMCaricare files via http non era poi cosi’ comune
Con la nascita di Ajax si cominciavano a caricare VIDEO!
Ed ecco un nuovo problema da affrontare:
Wednesday, May 22, 13
![Page 25: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/25.jpg)
LA PROGRESS BAR
Wednesday, May 22, 13
![Page 26: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/26.jpg)
LA PROGRESS BARIl DOM non dava alcuna informazione sul file
Wednesday, May 22, 13
![Page 27: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/27.jpg)
LA PROGRESS BARIl DOM non dava alcuna informazione sul file
Il trucco era controllare lo stato del file lato server in batch.
Wednesday, May 22, 13
![Page 28: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/28.jpg)
LA PROGRESS BARIl DOM non dava alcuna informazione sul file
Il trucco era controllare lo stato del file lato server in batch.
Ma l’http 1.1 ci da connessioni che possono restare aperte!
Wednesday, May 22, 13
![Page 29: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/29.jpg)
LA PROGRESS BARIl DOM non dava alcuna informazione sul file
Il trucco era controllare lo stato del file lato server in batch.
Ma l’http 1.1 ci da connessioni che possono restare aperte!
Nasce un interessante plugin per Mongrel
Wednesday, May 22, 13
![Page 30: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/30.jpg)
IL LONG POLLING
Wednesday, May 22, 13
![Page 31: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/31.jpg)
IL LONG POLLINGNon piu’ continue richieste Ajax temporizzate
Wednesday, May 22, 13
![Page 32: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/32.jpg)
IL LONG POLLINGNon piu’ continue richieste Ajax temporizzate
Il Web Server non risponde e chiude subito la connessione
Wednesday, May 22, 13
![Page 33: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/33.jpg)
IL LONG POLLINGNon piu’ continue richieste Ajax temporizzate
Il Web Server non risponde e chiude subito la connessione
La connessione resta aperta finche’ la si puo’ usare
Wednesday, May 22, 13
![Page 34: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/34.jpg)
IL LONG POLLINGNon piu’ continue richieste Ajax temporizzate
Il Web Server non risponde e chiude subito la connessione
La connessione resta aperta finche’ la si puo’ usare
Il Server continua a spedire lo stato del file fino al termine
Wednesday, May 22, 13
![Page 35: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/35.jpg)
IL WEB SERVER E’ APPENA DIVENTATO MOLTO PIU’
INTELLIGENTE! :)
Wednesday, May 22, 13
![Page 36: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/36.jpg)
MA...
Wednesday, May 22, 13
![Page 37: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/37.jpg)
IL WEB E’ ANCORA LENTO!
Wednesday, May 22, 13
![Page 38: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/38.jpg)
IL WEB E’ ANCORA LENTO!Ruby, Python, ecc sono troppo lenti by design
Wednesday, May 22, 13
![Page 39: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/39.jpg)
IL WEB E’ ANCORA LENTO!Ruby, Python, ecc sono troppo lenti by design
Gli interpreti sono singoli thread bloccanti
Wednesday, May 22, 13
![Page 40: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/40.jpg)
IL WEB E’ ANCORA LENTO!Ruby, Python, ecc sono troppo lenti by design
Gli interpreti sono singoli thread bloccanti
Il C e’ veloce ma uno sconosciuto per troppi webdev
Wednesday, May 22, 13
![Page 41: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/41.jpg)
SI SPERIMENTA CON:
Wednesday, May 22, 13
![Page 42: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/42.jpg)
SI SPERIMENTA CON:Ruby
Wednesday, May 22, 13
![Page 43: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/43.jpg)
SI SPERIMENTA CON:Ruby
Python
Wednesday, May 22, 13
![Page 44: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/44.jpg)
SI SPERIMENTA CON:Ruby
Python
Askel
Wednesday, May 22, 13
![Page 45: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/45.jpg)
L’OBIETTIVO:
Wednesday, May 22, 13
![Page 46: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/46.jpg)
L’OBIETTIVO:Costruire un sistema libero da lock!
Wednesday, May 22, 13
![Page 47: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/47.jpg)
LA RISPOSTA:
Wednesday, May 22, 13
![Page 48: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/48.jpg)
LA RISPOSTA:Tutto in un solo thread
Wednesday, May 22, 13
![Page 49: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/49.jpg)
LA RISPOSTA:Tutto in un solo thread
Migliora?
Wednesday, May 22, 13
![Page 50: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/50.jpg)
LA RISPOSTA:Tutto in un solo thread
Migliora?
SI! Si possono evitare tutti i problemi derivanti dai lock!
Wednesday, May 22, 13
![Page 51: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/51.jpg)
LA RISPOSTA:Tutto in un solo thread
Migliora?
SI! Si possono evitare tutti i problemi derivanti dai lock!
C’e’ un linguaggio che tutto cio’ lo fa di natura:
Wednesday, May 22, 13
![Page 52: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/52.jpg)
JAVASCRIPT
Wednesday, May 22, 13
![Page 53: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/53.jpg)
JAVASCRIPTNegli ultimi anni ha preso sempre piu’ piede
Wednesday, May 22, 13
![Page 54: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/54.jpg)
JAVASCRIPTNegli ultimi anni ha preso sempre piu’ piede
Tutti i maggiori browser stavano gia’ “combattendo su js”
Wednesday, May 22, 13
![Page 55: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/55.jpg)
JAVASCRIPTNegli ultimi anni ha preso sempre piu’ piede
Tutti i maggiori browser stavano gia’ “combattendo su js”Nel 2008 era stato rilasciato V8
Wednesday, May 22, 13
![Page 56: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/56.jpg)
JAVASCRIPTNegli ultimi anni ha preso sempre piu’ piede
Tutti i maggiori browser stavano gia’ “combattendo su js”Nel 2008 era stato rilasciato V8
Ha le caratteristiche adatte:
Wednesday, May 22, 13
![Page 57: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/57.jpg)
JAVASCRIPTNegli ultimi anni ha preso sempre piu’ piede
Tutti i maggiori browser stavano gia’ “combattendo su js”Nel 2008 era stato rilasciato V8
Ha le caratteristiche adatte:Closures
Wednesday, May 22, 13
![Page 58: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/58.jpg)
JAVASCRIPTNegli ultimi anni ha preso sempre piu’ piede
Tutti i maggiori browser stavano gia’ “combattendo su js”Nel 2008 era stato rilasciato V8
Ha le caratteristiche adatte:Closures
Funzioni anonime
Wednesday, May 22, 13
![Page 59: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/59.jpg)
JAVASCRIPTNegli ultimi anni ha preso sempre piu’ piede
Tutti i maggiori browser stavano gia’ “combattendo su js”Nel 2008 era stato rilasciato V8
Ha le caratteristiche adatte:Closures
Funzioni anonime
Non e’ usato al di fuori dei browser
Wednesday, May 22, 13
![Page 60: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/60.jpg)
JAVASCRIPTNegli ultimi anni ha preso sempre piu’ piede
Tutti i maggiori browser stavano gia’ “combattendo su js”Nel 2008 era stato rilasciato V8
Ha le caratteristiche adatte:Closures
Funzioni anonime
Non e’ usato al di fuori dei browserQuindi non ha preconcetti su come fare le cose.
Wednesday, May 22, 13
![Page 61: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/61.jpg)
NASCE NODE.JS
Wednesday, May 22, 13
![Page 62: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/62.jpg)
NASCE NODE.JSViene presentato alla javascript conf di Berlino
Wednesday, May 22, 13
![Page 63: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/63.jpg)
NASCE NODE.JSViene presentato alla javascript conf di Berlino
La prima app di demo: un IRC Server, 400 linee di codice!
Wednesday, May 22, 13
![Page 64: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/64.jpg)
NASCE NODE.JSViene presentato alla javascript conf di Berlino
La prima app di demo: un IRC Server, 400 linee di codice!
Ed e’ fatto per costruire network servers!
Wednesday, May 22, 13
![Page 65: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/65.jpg)
NASCE NODE.JSViene presentato alla javascript conf di Berlino
La prima app di demo: un IRC Server, 400 linee di codice!
Ed e’ fatto per costruire network servers!
Il suo nome indica che e’ fatto per essere un nodo tra molti
Wednesday, May 22, 13
![Page 66: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/66.jpg)
NASCE NODE.JSViene presentato alla javascript conf di Berlino
La prima app di demo: un IRC Server, 400 linee di codice!
Ed e’ fatto per costruire network servers!
Il suo nome indica che e’ fatto per essere un nodo tra molti
E’ adatto alla Cloud* per sua natura.
*Una volta si chiamava internetWednesday, May 22, 13
![Page 67: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/67.jpg)
FATTI: IL COSTO DELL’I/O
• cache L1: 3 cicli
• cache L2: 14 cicli
• RAM: 250 cicli
•Disco: 41x10^6 cicli
•Network: 240x10^6 cicli
Wednesday, May 22, 13
![Page 68: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/68.jpg)
ASYNC E NEXT TICK
Wednesday, May 22, 13
![Page 69: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/69.jpg)
ASYNC E NEXT TICKle applicazioni node girano in un singolo thread
Wednesday, May 22, 13
![Page 70: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/70.jpg)
ASYNC E NEXT TICKLe applicazioni node girano in un singolo thread
Questo comporta che ad ogni dato momento viene eseguito solo un task nell’event loop
Wednesday, May 22, 13
![Page 71: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/71.jpg)
ASYNC E NEXT TICKLe applicazioni node girano in un singolo thread
Questo comporta che ad ogni dato momento viene eseguito solo un task nell’event loop
Possiamo immaginare l’event loop come una coda di callback
Wednesday, May 22, 13
![Page 72: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/72.jpg)
ASYNC E NEXT TICKLe applicazioni node girano in un singolo thread
Questo comporta che ad ogni dato momento viene eseguito solo un task nell’event loop
Possiamo immaginare l’event loop come una coda di callbackAd ogni tick dell’event loop viene eseguida una delle callback
nella coda
Wednesday, May 22, 13
![Page 73: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/73.jpg)
ASYNC E NEXT TICKLe applicazioni node girano in un singolo thread
Questo comporta che ad ogni dato momento viene eseguito solo un task nell’event loop
Possiamo immaginare l’event loop come una coda di callbackAd ogni tick dell’event loop viene eseguida una delle callback
nella codaNon c’e’ concorrenza ne’ multicore
Wednesday, May 22, 13
![Page 74: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/74.jpg)
User NODE
NODE
Client Web Engine
Database
Logging facility Mass storage(big slow disk)
DB
Disk
ESEMPIO DI ARCHITETTURAIn questo modo i logs non rallentano piu’ i processi critici
Wednesday, May 22, 13
![Page 75: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/75.jpg)
backend server
Mobile client
NodeJs instances
Mobile Client
ESEMPIO: LINKEDINLinkedin usa node.js come middleware layer tra il backend e le
applicazioni mobileWednesday, May 22, 13
![Page 76: Introduzione a node: cenni storici ecc](https://reader036.vdocuments.pub/reader036/viewer/2022081401/5598fb261a28ab68718b4629/html5/thumbnails/76.jpg)
UN CASO COMPLESSOIl backend di Save The Mom e’ tutto in node.js e ne sfrutta
pesantemente il modello asincrono con l’aiuto di bus e codeWednesday, May 22, 13