View
162
Download
3
Category
Preview:
Citation preview
Node Event Loop
Wants to see if his team member Pam should get a raise
Alan
Wants to schedule a 2 week vacation
Bob
● Check Pam’s sales figures● Compare to company performance● Give her the raiseAla
n
● Check available vacation hours● Schedule his vacation
Bob
IIS
Alan
Bob (Empty)
JimCome into my office
IIS
Alan
Bob (Empty)
JimI need Pam’s sales figures
IIS
Alan
Bob (Empty)
JimJim logs into sales tracker and looks up info
IIS
Alan
Bob (Empty)
Jimfew min latergives answer
IIS
Alan
Bob (Empty)
JimHow much vacation do I have left?
IIS
Alan
Bob (Empty)
JimJim logs out of sales tracker and into vacay tracker
IIS
Alan
Bob (Empty)
Jimfew min latergives answer
IIS
Alan
Bob (Empty)
JimFew more rounds of Jim logging in/out. Alan and Bob wait it out
Alan
Bob
An hour later they’re back at their desks
IIS
oh no, their work has piled up! :(
Threads take up resources
Threads cause context switching
Synchronous operations must wait to continue working
IIS
Node
Intern 1
Jim
Intern 2
Door slot
Node
Intern 1
Jim
Intern 2
Sales queryfrom Alan
Node
Intern 1
Jim
Intern 2
Node
Intern 1
Jim
Intern 2
Vacay queryfrom Bob
Node
Intern 1
Jim
Intern 2
Node
Intern 1
Jim
Intern 2
Answer
Node Jim calls Alan with the answer for his query
Meanwhile, Alan has been productive with his work
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
Recommended