Top Banner
Node Event Loop
21

Node event loop

Feb 11, 2017

Download

Documents

michaelbreyes
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Node event loop

Node Event Loop

Page 2: Node event loop

Wants to see if his team member Pam should get a raise

Alan

Wants to schedule a 2 week vacation

Bob

Page 3: Node event loop

● Check Pam’s sales figures● Compare to company performance● Give her the raiseAla

n

● Check available vacation hours● Schedule his vacation

Bob

Page 4: Node event loop

IIS

Alan

Bob (Empty)

JimCome into my office

Page 5: Node event loop

IIS

Alan

Bob (Empty)

JimI need Pam’s sales figures

Page 6: Node event loop

IIS

Alan

Bob (Empty)

JimJim logs into sales tracker and looks up info

Page 7: Node event loop

IIS

Alan

Bob (Empty)

Jimfew min latergives answer

Page 8: Node event loop

IIS

Alan

Bob (Empty)

JimHow much vacation do I have left?

Page 9: Node event loop

IIS

Alan

Bob (Empty)

JimJim logs out of sales tracker and into vacay tracker

Page 10: Node event loop

IIS

Alan

Bob (Empty)

Jimfew min latergives answer

Page 11: Node event loop

IIS

Alan

Bob (Empty)

JimFew more rounds of Jim logging in/out. Alan and Bob wait it out

Page 12: Node event loop

Alan

Bob

An hour later they’re back at their desks

IIS

oh no, their work has piled up! :(

Page 13: Node event loop

Threads take up resources

Threads cause context switching

Synchronous operations must wait to continue working

IIS

Page 14: Node event loop

Node

Intern 1

Jim

Intern 2

Door slot

Page 15: Node event loop

Node

Intern 1

Jim

Intern 2

Sales queryfrom Alan

Page 16: Node event loop

Node

Intern 1

Jim

Intern 2

Page 17: Node event loop

Node

Intern 1

Jim

Intern 2

Vacay queryfrom Bob

Page 18: Node event loop

Node

Intern 1

Jim

Intern 2

Page 19: Node event loop

Node

Intern 1

Jim

Intern 2

Answer

Page 20: Node event loop

Node Jim calls Alan with the answer for his query

Meanwhile, Alan has been productive with his work

Page 21: Node event loop

Single thread saves RAM and CPU

Queue for incoming I/O requests

Asynchronous ops, your code can keep working while you wait for a callback

Node