Skip to content

funkswing/event-loop-presentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS Event Loop Presentation and Demo materials

Overview

NodeJS asynchronicity allows it to easily handle many concurrent requests. This makes NodeJS a great choice to power web APIs, but asynchronicity in Node is often misunderstood. This talk goes over the basics of the event loop, how asynchronous code can block incoming requests, and how (or better when) to solve blocking asynchronous API code.

Presentation

https://event-loop.funkswing.now.sh/

Demo - Blocking API

npm install node api/index.js

Open multiple terminals to run concurrent requests to API

Mimic traffic to API: while true; do date && curl -m 1 http://localhost:3000 && echo; sleep 1; done

Choose a long-running request to see which block the event loop:

START=$(date +%s) && curl http://localhost:3000/loop && END=$(date +%s) && echo "Took: $(expr $END - $START) sec"
START=$(date +%s) && curl http://localhost:3000/loop/bmap && END=$(date +%s) && echo "Took: $(expr $END - $START) sec"
START=$(date +%s) && curl http://localhost:3000/loop/seti && END=$(date +%s) && echo "Took: $(expr $END - $START) sec"
START=$(date +%s) && curl http://localhost:3000/loop/bird && END=$(date +%s) && echo "Took: $(expr $END - $START) sec"
START=$(date +%s) && curl http://localhost:3000/loop/native && END=$(date +%s) && echo "Took: $(expr $END - $START) sec"
START=$(date +%s) && curl http://localhost:3000/loop/sett && END=$(date +%s) && echo "Took: $(expr $END - $START) sec"

About

NodeJS Event Loop Presentation and Demo materials

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published