224
EVENT DRIVEN NODEJS Donnerstag, 27. Juni 13

Event Driven - Node.JS

  • Upload
    mbild

  • View
    618

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Event Driven - Node.JS

EVENT DRIVENNODEJS

Donnerstag, 27. Juni 13

Page 2: Event Driven - Node.JS

ÜBER MICH

‣ JavaScript Nerd

‣ C/C++/C# Entwickler

‣ Berliner

‣ Tech Startups

@mikebild / Software Engineer

Donnerstag, 27. Juni 13

Page 3: Event Driven - Node.JS

init()

setup()

run()

cleanup()

end()

sync

Donnerstag, 27. Juni 13

Page 4: Event Driven - Node.JS

init()

setup()

run()

cleanup()

end()

sync

0

1

2

3

4

Donnerstag, 27. Juni 13

Page 5: Event Driven - Node.JS

async

init()0

setup()1

run()2

cleanup()3

end()4

Donnerstag, 27. Juni 13

Page 6: Event Driven - Node.JS

async

init()0 setup()1

run()2

cleanup()3

end()4

Donnerstag, 27. Juni 13

Page 7: Event Driven - Node.JS

async

init()0 setup()1 run()2

cleanup()3

end()4

Donnerstag, 27. Juni 13

Page 8: Event Driven - Node.JS

async

init()0 setup()1 run()2 cleanup()3

end()4

Donnerstag, 27. Juni 13

Page 9: Event Driven - Node.JS

async

init()0 setup()1 run()2 cleanup()3 end()4

Donnerstag, 27. Juni 13

Page 10: Event Driven - Node.JS

ASYNC !== POSITION

Donnerstag, 27. Juni 13

Page 11: Event Driven - Node.JS

ASYNC === ZEIT

Donnerstag, 27. Juni 13

Page 12: Event Driven - Node.JS

KONTROLLFLUSS === undefined

???

Donnerstag, 27. Juni 13

Page 13: Event Driven - Node.JS

init(setup(

run(cleanup(

end())

))

)

Donnerstag, 27. Juni 13

Page 14: Event Driven - Node.JS

???

Donnerstag, 27. Juni 13

Page 15: Event Driven - Node.JS

CONTINUATION

???

Donnerstag, 27. Juni 13

Page 16: Event Driven - Node.JS

CALLBACKSCONTINUATION

???

Donnerstag, 27. Juni 13

Page 17: Event Driven - Node.JS

FIRST-CLASS FUNCTIONS

Donnerstag, 27. Juni 13

Page 18: Event Driven - Node.JS

FIRST-CLASS FUNCTIONS‣ Funktionen sind Objekte

Donnerstag, 27. Juni 13

Page 19: Event Driven - Node.JS

FIRST-CLASS FUNCTIONS‣ Funktionen sind Objekte

‣ Variablenzuweisung

Donnerstag, 27. Juni 13

Page 20: Event Driven - Node.JS

FIRST-CLASS FUNCTIONS‣ Funktionen sind Objekte

‣ Variablenzuweisung

‣ Parameter

Donnerstag, 27. Juni 13

Page 21: Event Driven - Node.JS

FIRST-CLASS FUNCTIONS‣ Funktionen sind Objekte

‣ Variablenzuweisung

‣ Parameter

‣ Rückgabewert

Donnerstag, 27. Juni 13

Page 22: Event Driven - Node.JS

FIRST-CLASS FUNCTIONS‣ Funktionen sind Objekte

‣ Variablenzuweisung

‣ Parameter

‣ Rückgabewert

‣ Funktionen haben Eigenschaften und Methoden

Donnerstag, 27. Juni 13

Page 23: Event Driven - Node.JS

FIRST-CLASS FUNCTIONS

Donnerstag, 27. Juni 13

Page 24: Event Driven - Node.JS

non-blocking

Donnerstag, 27. Juni 13

Page 25: Event Driven - Node.JS

non-blocking

???

Donnerstag, 27. Juni 13

Page 26: Event Driven - Node.JS

non-blocking

???

Donnerstag, 27. Juni 13

Page 27: Event Driven - Node.JS

SCOPE

non-blocking

???

Donnerstag, 27. Juni 13

Page 28: Event Driven - Node.JS

SCOPE

non-blocking

IMMEDIATE FUNCTIONS

???

Donnerstag, 27. Juni 13

Page 29: Event Driven - Node.JS

SCOPE

non-blocking

IMMEDIATE FUNCTIONSCLOSURES

???

Donnerstag, 27. Juni 13

Page 30: Event Driven - Node.JS

<3 KONZEPTE

Donnerstag, 27. Juni 13

Page 31: Event Driven - Node.JS

SCOPE

‣ Gültigkeitsbereich von Variablen

‣ privat innerhalb von Funktionen

‣ das this innerhalb der Funktion

Donnerstag, 27. Juni 13

Page 32: Event Driven - Node.JS

IMMEDIATE FUNCTIONS

Donnerstag, 27. Juni 13

Page 33: Event Driven - Node.JS

IMMEDIATE FUNCTIONS

Deklaration und unmittelbare Ausführung

Donnerstag, 27. Juni 13

Page 34: Event Driven - Node.JS

CLOSURES

Donnerstag, 27. Juni 13

Page 35: Event Driven - Node.JS

CLOSURES

‣ umschließen Gültigkeitsbereich für Variablen

Donnerstag, 27. Juni 13

Page 36: Event Driven - Node.JS

CLOSURES

‣ umschließen Gültigkeitsbereich für Variablen

‣ „einfrieren“ von Werten in Variablen

Donnerstag, 27. Juni 13

Page 37: Event Driven - Node.JS

CLOSURES

‣ umschließen Gültigkeitsbereich für Variablen

‣ „einfrieren“ von Werten in Variablen

‣ private Variablen

Donnerstag, 27. Juni 13

Page 38: Event Driven - Node.JS

CLOSURES

‣ umschließen Gültigkeitsbereich für Variablen

‣ „einfrieren“ von Werten in Variablen

‣ private Variablen

‣ „konfigurierbare“ Funktionen

Donnerstag, 27. Juni 13

Page 39: Event Driven - Node.JS

CLOSURESSCOPE - private Variablen

Donnerstag, 27. Juni 13

Page 40: Event Driven - Node.JS

CLOSURES„konfigurierbare“ Funktionen

Donnerstag, 27. Juni 13

Page 41: Event Driven - Node.JS

SCOPE CLOSURE

???

Donnerstag, 27. Juni 13

Page 42: Event Driven - Node.JS

SCOPE CLOSURE

YEAH!???

Donnerstag, 27. Juni 13

Page 43: Event Driven - Node.JS

(RE)BIND SCOPE

Donnerstag, 27. Juni 13

Page 44: Event Driven - Node.JS

(RE)BIND SCOPEOUTER

Donnerstag, 27. Juni 13

Page 45: Event Driven - Node.JS

(RE)BIND SCOPEOUTER INNER

Donnerstag, 27. Juni 13

Page 46: Event Driven - Node.JS

(RE)BIND SCOPEOUTER INNER

Donnerstag, 27. Juni 13

Page 47: Event Driven - Node.JS

BLOCKINGVS.

NON-BLOCKING

Donnerstag, 27. Juni 13

Page 48: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 49: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 50: Event Driven - Node.JS

ARBEIT

Donnerstag, 27. Juni 13

Page 51: Event Driven - Node.JS

WARTEN

ARBEIT

Donnerstag, 27. Juni 13

Page 52: Event Driven - Node.JS

WARTEN

ARBEIT

Donnerstag, 27. Juni 13

Page 53: Event Driven - Node.JS

WARTEN

Donnerstag, 27. Juni 13

Page 54: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 55: Event Driven - Node.JS

FERTIG

Donnerstag, 27. Juni 13

Page 56: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 57: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 58: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 59: Event Driven - Node.JS

BLOCKING

Donnerstag, 27. Juni 13

Page 60: Event Driven - Node.JS

???GESCHWINDIGKEIT

Donnerstag, 27. Juni 13

Page 61: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 62: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 63: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 64: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 65: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 66: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 67: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 68: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 69: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 70: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 71: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 72: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 73: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 74: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 75: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 76: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 77: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 78: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 79: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 80: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 81: Event Driven - Node.JS

THREADS

Donnerstag, 27. Juni 13

Page 82: Event Driven - Node.JS

‣ Reaktionsfähig

THREADS

Donnerstag, 27. Juni 13

Page 83: Event Driven - Node.JS

‣ Reaktionsfähig

‣ Skalierbar

THREADS

Donnerstag, 27. Juni 13

Page 84: Event Driven - Node.JS

‣ Reaktionsfähig

‣ Skalierbar

‣ ABER

THREADS

Donnerstag, 27. Juni 13

Page 85: Event Driven - Node.JS

‣ Reaktionsfähig

‣ Skalierbar

‣ ABER

‣ hoher Aufwand

THREADS

Donnerstag, 27. Juni 13

Page 86: Event Driven - Node.JS

‣ Reaktionsfähig

‣ Skalierbar

‣ ABER

‣ hoher Aufwand

‣ viel Koordination

THREADS

Donnerstag, 27. Juni 13

Page 87: Event Driven - Node.JS

TEUER

Donnerstag, 27. Juni 13

Page 88: Event Driven - Node.JS

IDEEN?

Donnerstag, 27. Juni 13

Page 89: Event Driven - Node.JS

NEUER ABLAUF

Donnerstag, 27. Juni 13

Page 90: Event Driven - Node.JS

NON-BLOCKING

Donnerstag, 27. Juni 13

Page 91: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 92: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 93: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 94: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 95: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 96: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 97: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 98: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 99: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 100: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 101: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 102: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 103: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 104: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 105: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 106: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 107: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 108: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 109: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 110: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 111: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 112: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 113: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 114: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 115: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 116: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 117: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 118: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 119: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 120: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 121: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 122: Event Driven - Node.JS

Benachrichtigen Sie mich,sobald Sie fertig sind.

Donnerstag, 27. Juni 13

Page 123: Event Driven - Node.JS

EVENT DRIVEN

Donnerstag, 27. Juni 13

Page 124: Event Driven - Node.JS

‣ Reaktionsfähig

EVENT DRIVEN

Donnerstag, 27. Juni 13

Page 125: Event Driven - Node.JS

‣ Reaktionsfähig

‣ Skalierbar

EVENT DRIVEN

Donnerstag, 27. Juni 13

Page 126: Event Driven - Node.JS

‣ Reaktionsfähig

‣ Skalierbar

‣ UND

EVENT DRIVEN

Donnerstag, 27. Juni 13

Page 127: Event Driven - Node.JS

‣ Reaktionsfähig

‣ Skalierbar

‣ UND

‣ EINFACH

EVENT DRIVEN

Donnerstag, 27. Juni 13

Page 128: Event Driven - Node.JS

‣ Reaktionsfähig

‣ Skalierbar

‣ UND

‣ EINFACH

‣ GÜNSTIG

EVENT DRIVEN

Donnerstag, 27. Juni 13

Page 129: Event Driven - Node.JS

GESCHWINDIGKEIT?

Donnerstag, 27. Juni 13

Page 130: Event Driven - Node.JS

I/O GESCHWINDIGKEIT

http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait

5ns 50ns 5ms 50ms

CPU-Register0.33ns

L1-Cache1ns L2-Cache

4.7ns

RAM83ns

HDD-Seek13.7ms

NETWORK80ms

Donnerstag, 27. Juni 13

Page 131: Event Driven - Node.JS

WARTEN

Donnerstag, 27. Juni 13

Page 132: Event Driven - Node.JS

NODE.JS

Donnerstag, 27. Juni 13

Page 133: Event Driven - Node.JS

I/O MODULEfile, http, net ...

BLOCKING NON-BLOCKING

Donnerstag, 27. Juni 13

Page 134: Event Driven - Node.JS

I/O MODULEfile, http, net ...

BLOCKING NON-BLOCKING

UNTERSCHIEDE

Donnerstag, 27. Juni 13

Page 135: Event Driven - Node.JS

BLOCKING

Donnerstag, 27. Juni 13

Page 136: Event Driven - Node.JS

BLOCKING

‣ Prozess blockiert während des Aufrufes

Donnerstag, 27. Juni 13

Page 137: Event Driven - Node.JS

BLOCKING

‣ Prozess blockiert während des Aufrufes

‣ wird erst fortgesetzt, wenn Ergebnis verfügbar ist

Donnerstag, 27. Juni 13

Page 138: Event Driven - Node.JS

NON-BLOCKING

Donnerstag, 27. Juni 13

Page 139: Event Driven - Node.JS

NON-BLOCKING

‣ Prozess kann weiter arbeiten

Donnerstag, 27. Juni 13

Page 140: Event Driven - Node.JS

NON-BLOCKING

‣ Prozess kann weiter arbeiten

‣ während die Daten im Hintergrund geladen werden

Donnerstag, 27. Juni 13

Page 141: Event Driven - Node.JS

NON-BLOCKING I/O

Donnerstag, 27. Juni 13

Page 142: Event Driven - Node.JS

NON-BLOCKING I/O

‣ Funktionen ohne „direkte“ Rückgabewerte

Donnerstag, 27. Juni 13

Page 143: Event Driven - Node.JS

NON-BLOCKING I/O

‣ Funktionen ohne „direkte“ Rückgabewerte

‣ „callbacks“ sind „continuations“ zur Fortsetzung des Programmablaufs

Donnerstag, 27. Juni 13

Page 144: Event Driven - Node.JS

NON-BLOCKING I/O

‣ Funktionen ohne „direkte“ Rückgabewerte

‣ „callbacks“ sind „continuations“ zur Fortsetzung des Programmablaufs

‣ Background-Tasks machen die Arbeit

Donnerstag, 27. Juni 13

Page 145: Event Driven - Node.JS

NON-BLOCKING I/O

‣ Funktionen ohne „direkte“ Rückgabewerte

‣ „callbacks“ sind „continuations“ zur Fortsetzung des Programmablaufs

‣ Background-Tasks machen die Arbeit

‣ keine Wartezeit im Programmablauf

Donnerstag, 27. Juni 13

Page 146: Event Driven - Node.JS

EVENTS

Donnerstag, 27. Juni 13

Page 147: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 148: Event Driven - Node.JS

‣ Frontend

‣ user interaction-events: mouse*, key*

‣ timer events: setTimeout

Donnerstag, 27. Juni 13

Page 149: Event Driven - Node.JS

‣ Frontend

‣ user interaction-events: mouse*, key*

‣ timer events: setTimeout

Donnerstag, 27. Juni 13

Page 150: Event Driven - Node.JS

‣ Frontend

‣ user interaction-events: mouse*, key*

‣ timer events: setTimeout

‣ Backend

‣ I/O-events: networking, filesystem

‣ custom-events

Donnerstag, 27. Juni 13

Page 151: Event Driven - Node.JS

EVENTS

Donnerstag, 27. Juni 13

Page 152: Event Driven - Node.JS

‣ Ereignisse auf die reagiert werden

EVENTS

Donnerstag, 27. Juni 13

Page 153: Event Driven - Node.JS

‣ Ereignisse auf die reagiert werden

‣ viele Sender (üblicherweise nur einer)

EVENTS

Donnerstag, 27. Juni 13

Page 154: Event Driven - Node.JS

‣ Ereignisse auf die reagiert werden

‣ viele Sender (üblicherweise nur einer)

‣ viele Empfänger

EVENTS

Donnerstag, 27. Juni 13

Page 155: Event Driven - Node.JS

EVENT HANDLING

Donnerstag, 27. Juni 13

Page 156: Event Driven - Node.JS

callback(DATA)

Donnerstag, 27. Juni 13

Page 157: Event Driven - Node.JS

‣ vereinfachte Form der Event-Verarbeitung

‣ wird anstelle eines return-Wertes aufgerufen

‣ NODE.JS Konvention:

function callback(err, data) {}

callback(DATA)

Donnerstag, 27. Juni 13

Page 158: Event Driven - Node.JS

EVENT EMITTER

Donnerstag, 27. Juni 13

Page 159: Event Driven - Node.JS

‣ Event-Quelle und Dispatcher

‣ Empfänger werden mit on('NAME', callback) angemeldet

‣ Events werden mit emit() ausgelöst

‣ Events werden nur an die angemeldeten Empfänger im Event-Emitter gesendet

EVENT EMITTER

Donnerstag, 27. Juni 13

Page 160: Event Driven - Node.JS

EVENT EMITTER

Donnerstag, 27. Juni 13

Page 161: Event Driven - Node.JS

EVENT-LOOPARCHITEKTUR

Donnerstag, 27. Juni 13

Page 162: Event Driven - Node.JS

‣Event-Handler registrieren‣Anwendung starten

1

Bearbeitet„lang laufenden“ Aufgaben

2

WORKER THREADSWORKER THREADSWORKER THREADS

MAIN PROCESS

C++ Thread-Pool

Donnerstag, 27. Juni 13

Page 163: Event Driven - Node.JS

‣Event-Loop startet‣wartet auf Events

3

EVENT-LOOP

MAIN PROCESS

WORKER THREADSWORKER THREADSWORKER THREADS

Donnerstag, 27. Juni 13

Page 164: Event Driven - Node.JS

Meldet „Daten“-Rückgaben als Events

4

EVENT-LOOP

MAIN PROCESS

WORKER THREADSWORKER THREADSWORKER THREADS

➡ fs.data➡ fs.end➡http.request➡ ...➡ ...

EVENTQUEUE

Donnerstag, 27. Juni 13

Page 165: Event Driven - Node.JS

Dispatcher führtfür jeden EVENTden registriertenCALLBACK im

MAIN PROZESS aus

5EVENT-LOOP

MAIN PROCESS

WORKER THREADSWORKER THREADSWORKER THREADS

➡ fs.data➡ fs.end➡http.request

EVENTQUEUE

DISPATCH

Donnerstag, 27. Juni 13

Page 166: Event Driven - Node.JS

✓in nur einem Prozess

✓Single-Thread innerhalb von NODE.JS

✓keine Parallelisierung, sondern Non-Blocking

✓Event-Verarbeitung in Reihenfolge der Erzeugung

✓einfaches Modell

✓Skalierung über separate Prozesse (CPU-Intensive Tasks)

✓zwingt zum asynchronem Denken und Code

EVENT LOOP

Donnerstag, 27. Juni 13

Page 167: Event Driven - Node.JS

BEISPIEL

WEB SERVER

Donnerstag, 27. Juni 13

Page 168: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 169: Event Driven - Node.JS

NEVER BLOCK

Donnerstag, 27. Juni 13

Page 170: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 171: Event Driven - Node.JS

YEAH

Donnerstag, 27. Juni 13

Page 172: Event Driven - Node.JS

EVENT EMITTER

Donnerstag, 27. Juni 13

Page 173: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 174: Event Driven - Node.JS

STREAMS

Donnerstag, 27. Juni 13

Page 175: Event Driven - Node.JS

CHILD-PROZESS

Donnerstag, 27. Juni 13

Page 176: Event Driven - Node.JS

WENNS MAL LÄNGER DAUERT

Donnerstag, 27. Juni 13

Page 177: Event Driven - Node.JS

WENNS MAL LÄNGER DAUERT

✓„split and defer“ - setTimeout(continuation, 0);

Donnerstag, 27. Juni 13

Page 178: Event Driven - Node.JS

WENNS MAL LÄNGER DAUERT

✓„split and defer“ - setTimeout(continuation, 0);

✓EventEmitter

Donnerstag, 27. Juni 13

Page 179: Event Driven - Node.JS

WENNS MAL LÄNGER DAUERT

✓„split and defer“ - setTimeout(continuation, 0);

✓EventEmitter

✓child-process

Donnerstag, 27. Juni 13

Page 180: Event Driven - Node.JS

WENNS MAL LÄNGER DAUERT

✓„split and defer“ - setTimeout(continuation, 0);

✓EventEmitter

✓child-process

✓STREAMS

Donnerstag, 27. Juni 13

Page 181: Event Driven - Node.JS

BEISPIEL

Donnerstag, 27. Juni 13

Page 182: Event Driven - Node.JS

Donnerstag, 27. Juni 13

Page 183: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

Donnerstag, 27. Juni 13

Page 184: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

Donnerstag, 27. Juni 13

Page 185: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

Donnerstag, 27. Juni 13

Page 186: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

‣ Rezeptionist übergibt ein Zahlungsformular

Donnerstag, 27. Juni 13

Page 187: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

‣ Rezeptionist übergibt ein Zahlungsformular

‣ Rezeptionist kann weitere Gäste empfangen

Donnerstag, 27. Juni 13

Page 188: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

‣ Rezeptionist übergibt ein Zahlungsformular

‣ Rezeptionist kann weitere Gäste empfangen

Donnerstag, 27. Juni 13

Page 189: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

‣ Rezeptionist übergibt ein Zahlungsformular

‣ Rezeptionist kann weitere Gäste empfangen

‣ Der Gast füllt die Formulare aus

Donnerstag, 27. Juni 13

Page 190: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

‣ Rezeptionist übergibt ein Zahlungsformular

‣ Rezeptionist kann weitere Gäste empfangen

‣ Der Gast füllt die Formulare aus

‣ Der Gast übergibt die ausgefüllten Formulare an den Rezeptionist

Donnerstag, 27. Juni 13

Page 191: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

‣ Rezeptionist übergibt ein Zahlungsformular

‣ Rezeptionist kann weitere Gäste empfangen

‣ Der Gast füllt die Formulare aus

‣ Der Gast übergibt die ausgefüllten Formulare an den Rezeptionist

Donnerstag, 27. Juni 13

Page 192: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

‣ Rezeptionist übergibt ein Zahlungsformular

‣ Rezeptionist kann weitere Gäste empfangen

‣ Der Gast füllt die Formulare aus

‣ Der Gast übergibt die ausgefüllten Formulare an den Rezeptionist

‣ Rezeptionist überprüft die erhaltenen Formulare

Donnerstag, 27. Juni 13

Page 193: Event Driven - Node.JS

‣ Ein Gast betritt den Empfang eines Hotels

‣ Rezeptionist begrüßt den Gast

‣ Rezeptionist übergibt ein Anmeldeformular

‣ Rezeptionist übergibt ein Zahlungsformular

‣ Rezeptionist kann weitere Gäste empfangen

‣ Der Gast füllt die Formulare aus

‣ Der Gast übergibt die ausgefüllten Formulare an den Rezeptionist

‣ Rezeptionist überprüft die erhaltenen Formulare

‣ Gast bekommt seinen Zimmerschlüssel, oder muss das/die Formulare nochmals ausfüllen

Donnerstag, 27. Juni 13

Page 194: Event Driven - Node.JS

SYNC

Donnerstag, 27. Juni 13

Page 195: Event Driven - Node.JS

SYNC

Donnerstag, 27. Juni 13

Page 196: Event Driven - Node.JS

‣ nur 1 Gast je Rezeptionisten

SYNC

Donnerstag, 27. Juni 13

Page 197: Event Driven - Node.JS

‣ nur 1 Gast je Rezeptionisten

‣ X gleichzeitige Gäste brauchen X Rezeptionisten (= Threads)

SYNC

Donnerstag, 27. Juni 13

Page 198: Event Driven - Node.JS

‣ nur 1 Gast je Rezeptionisten

‣ X gleichzeitige Gäste brauchen X Rezeptionisten (= Threads)

‣ Rezeptionisten und Gast warten (= Locking)

SYNC

Donnerstag, 27. Juni 13

Page 199: Event Driven - Node.JS

‣ nur 1 Gast je Rezeptionisten

‣ X gleichzeitige Gäste brauchen X Rezeptionisten (= Threads)

‣ Rezeptionisten und Gast warten (= Locking)

‣ wenn mehr Gäste als Rezeptionisten: Warteschlange am Eingang

SYNC

Donnerstag, 27. Juni 13

Page 200: Event Driven - Node.JS

‣ nur 1 Gast je Rezeptionisten

‣ X gleichzeitige Gäste brauchen X Rezeptionisten (= Threads)

‣ Rezeptionisten und Gast warten (= Locking)

‣ wenn mehr Gäste als Rezeptionisten: Warteschlange am Eingang

‣ oder ständig "schlafende" Rezeptionisten

SYNC

Donnerstag, 27. Juni 13

Page 201: Event Driven - Node.JS

ASYNC

Donnerstag, 27. Juni 13

Page 202: Event Driven - Node.JS

ASYNC

Donnerstag, 27. Juni 13

Page 203: Event Driven - Node.JS

‣ nur 1 Rezeptionist für X Gäste

ASYNC

Donnerstag, 27. Juni 13

Page 204: Event Driven - Node.JS

‣ nur 1 Rezeptionist für X Gäste

‣ zu viele Gäste führen nur zur langsameren Ausführung nicht zur Blocking

ASYNC

Donnerstag, 27. Juni 13

Page 205: Event Driven - Node.JS

‣ nur 1 Rezeptionist für X Gäste

‣ zu viele Gäste führen nur zur langsameren Ausführung nicht zur Blocking

‣ Lange Aktionen werden von Background-Services erledigt

ASYNC

Donnerstag, 27. Juni 13

Page 206: Event Driven - Node.JS

‣ nur 1 Rezeptionist für X Gäste

‣ zu viele Gäste führen nur zur langsameren Ausführung nicht zur Blocking

‣ Lange Aktionen werden von Background-Services erledigt

‣ jegliche Aktion wird über Events ausgelöst

ASYNC

Donnerstag, 27. Juni 13

Page 207: Event Driven - Node.JS

‣ nur 1 Rezeptionist für X Gäste

‣ zu viele Gäste führen nur zur langsameren Ausführung nicht zur Blocking

‣ Lange Aktionen werden von Background-Services erledigt

‣ jegliche Aktion wird über Events ausgelöst

‣ Rezeptionisten sind nicht untätig

ASYNC

Donnerstag, 27. Juni 13

Page 208: Event Driven - Node.JS

ABER

Donnerstag, 27. Juni 13

Page 209: Event Driven - Node.JS

KOMPLIZIERT

Donnerstag, 27. Juni 13

Page 210: Event Driven - Node.JS

CALLBACK HELL

Donnerstag, 27. Juni 13

Page 211: Event Driven - Node.JS

https://npmjs.org/package/cflow

FLOW

Donnerstag, 27. Juni 13

Page 212: Event Driven - Node.JS

https://github.com/creationix/step

STEP

Donnerstag, 27. Juni 13

Page 213: Event Driven - Node.JS

https://github.com/creationix/step

STEP

Donnerstag, 27. Juni 13

Page 214: Event Driven - Node.JS

COMPLEXEVENT

PROCESSING

Donnerstag, 27. Juni 13

Page 215: Event Driven - Node.JS

REACTIVE EXTENSIONS

IN

OUT

LOGIK

Donnerstag, 27. Juni 13

Page 216: Event Driven - Node.JS

ZUSTAND

‣ Array von Events

‣ Event Store

...

{ msg: „bar“ }

{ msg: „foo“ }

{ msg: „driven“ }

{ msg: „event“ }

{ msg: „start“ }01234

Donnerstag, 27. Juni 13

Page 217: Event Driven - Node.JS

EVENTS SPEICHERN

Donnerstag, 27. Juni 13

Page 218: Event Driven - Node.JS

ABFRAGE

Donnerstag, 27. Juni 13

Page 219: Event Driven - Node.JS

ABFRAGE

pattern matching

Donnerstag, 27. Juni 13

Page 220: Event Driven - Node.JS

MATCH & FOLD

Donnerstag, 27. Juni 13

Page 221: Event Driven - Node.JS

MORGEN

Donnerstag, 27. Juni 13

Page 222: Event Driven - Node.JS

EVENT STORE

Donnerstag, 27. Juni 13

Page 223: Event Driven - Node.JS

SEDA Staged Event Driven Architecture

Donnerstag, 27. Juni 13

Page 224: Event Driven - Node.JS

DANKE

Donnerstag, 27. Juni 13